Skip to content

Commit

Permalink
Rollup merge of #98611 - GuillaumeGomez:rustdoc-json-glob-ice, r=notr…
Browse files Browse the repository at this point in the history
…iddle

Fix glob import ICE in rustdoc JSON format

Fixes #98003.

r? `@notriddle`
  • Loading branch information
matthiaskrgr committed Jun 28, 2022
2 parents a1b0638 + c2221ef commit 956a9f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,12 @@ impl Path {
self.res.def_id()
}

pub(crate) fn last_opt(&self) -> Option<Symbol> {
self.segments.last().map(|s| s.name)
}

pub(crate) fn last(&self) -> Symbol {
self.segments.last().expect("segments were empty").name
self.last_opt().expect("segments were empty")
}

pub(crate) fn whole_name(&self) -> String {
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,12 @@ impl FromWithTcx<clean::Import> for Import {
},
Glob => Import {
source: import.source.path.whole_name(),
name: import.source.path.last().to_string(),
name: import
.source
.path
.last_opt()
.unwrap_or_else(|| Symbol::intern("*"))
.to_string(),
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
glob: true,
},
Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc-json/glob_import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This is a regression test for <https://github.com/rust-lang/rust/issues/98003>.

#![feature(no_core)]
#![no_std]
#![no_core]

// @has glob_import.json
// @has - "$.index[*][?(@.name=='glob')]"
// @has - "$.index[*][?(@.kind=='import')].inner.name" \"*\"


mod m1 {
pub fn f() {}
}
mod m2 {
pub fn f(_: u8) {}
}

pub use m1::*;
pub use m2::*;

pub mod glob {
pub use *;
}

0 comments on commit 956a9f5

Please sign in to comment.