about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-06-28 11:46:03 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2022-06-28 11:46:03 +0200
commitb7e62000ddced5d8bd4b7e21d9e247bbc1912723 (patch)
tree11d80be1a3eacc52772888e5c0fa6d38efbda4d2 /src
parentbd2e51a338e36372b200a22f3e0e22189a1063e6 (diff)
downloadrust-b7e62000ddced5d8bd4b7e21d9e247bbc1912723.tar.gz
rust-b7e62000ddced5d8bd4b7e21d9e247bbc1912723.zip
Fix glob import ICE in rustdoc JSON format
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/types.rs6
-rw-r--r--src/librustdoc/json/conversions.rs7
2 files changed, 11 insertions, 2 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 2762d5e8502..352803855a4 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -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 {
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index c627dcc30d6..84b3d7431cf 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -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,
             },