Skip to content

Commit 4e73d90

Browse files
committed
rustdoc-json: De-duplicate FromWithTcx<clean::Import>
1 parent 96c2df8 commit 4e73d90

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -679,24 +679,18 @@ impl FromWithTcx<clean::Variant> for Variant {
679679
impl FromWithTcx<clean::Import> for Import {
680680
fn from_tcx(import: clean::Import, tcx: TyCtxt<'_>) -> Self {
681681
use clean::ImportKind::*;
682-
match import.kind {
683-
Simple(s) => Import {
684-
source: import.source.path.whole_name(),
685-
name: s.to_string(),
686-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
687-
glob: false,
688-
},
689-
Glob => Import {
690-
source: import.source.path.whole_name(),
691-
name: import
692-
.source
693-
.path
694-
.last_opt()
695-
.unwrap_or_else(|| Symbol::intern("*"))
696-
.to_string(),
697-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
698-
glob: true,
699-
},
682+
let (name, glob) = match import.kind {
683+
Simple(s) => (s.to_string(), false),
684+
Glob => (
685+
import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
686+
true,
687+
),
688+
};
689+
Import {
690+
source: import.source.path.whole_name(),
691+
name,
692+
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
693+
glob,
700694
}
701695
}
702696
}

0 commit comments

Comments
 (0)