Skip to content

Commit b7e6200

Browse files
Fix glob import ICE in rustdoc JSON format
1 parent bd2e51a commit b7e6200

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/librustdoc/clean/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,8 +2161,12 @@ impl Path {
21612161
self.res.def_id()
21622162
}
21632163

2164+
pub(crate) fn last_opt(&self) -> Option<Symbol> {
2165+
self.segments.last().map(|s| s.name)
2166+
}
2167+
21642168
pub(crate) fn last(&self) -> Symbol {
2165-
self.segments.last().expect("segments were empty").name
2169+
self.last_opt().expect("segments were empty")
21662170
}
21672171

21682172
pub(crate) fn whole_name(&self) -> String {

src/librustdoc/json/conversions.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,12 @@ impl FromWithTcx<clean::Import> for Import {
663663
},
664664
Glob => Import {
665665
source: import.source.path.whole_name(),
666-
name: import.source.path.last().to_string(),
666+
name: import
667+
.source
668+
.path
669+
.last_opt()
670+
.unwrap_or_else(|| Symbol::intern("*"))
671+
.to_string(),
667672
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
668673
glob: true,
669674
},

0 commit comments

Comments
 (0)