Skip to content

Commit 956a9f5

Browse files
authored
Rollup merge of #98611 - GuillaumeGomez:rustdoc-json-glob-ice, r=notriddle
Fix glob import ICE in rustdoc JSON format Fixes #98003. r? `@notriddle`
2 parents a1b0638 + c2221ef commit 956a9f5

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Diff for: src/librustdoc/clean/types.rs

+5-1
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 {

Diff for: src/librustdoc/json/conversions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,12 @@ impl FromWithTcx<clean::Import> for Import {
666666
},
667667
Glob => Import {
668668
source: import.source.path.whole_name(),
669-
name: import.source.path.last().to_string(),
669+
name: import
670+
.source
671+
.path
672+
.last_opt()
673+
.unwrap_or_else(|| Symbol::intern("*"))
674+
.to_string(),
670675
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
671676
glob: true,
672677
},

Diff for: src/test/rustdoc-json/glob_import.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/98003>.
2+
3+
#![feature(no_core)]
4+
#![no_std]
5+
#![no_core]
6+
7+
// @has glob_import.json
8+
// @has - "$.index[*][?(@.name=='glob')]"
9+
// @has - "$.index[*][?(@.kind=='import')].inner.name" \"*\"
10+
11+
12+
mod m1 {
13+
pub fn f() {}
14+
}
15+
mod m2 {
16+
pub fn f(_: u8) {}
17+
}
18+
19+
pub use m1::*;
20+
pub use m2::*;
21+
22+
pub mod glob {
23+
pub use *;
24+
}

0 commit comments

Comments
 (0)