Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glob import ICE in rustdoc JSON format #98611

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -663,7 +663,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 *;
}