about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-21 18:53:18 +0000
committerGitHub <noreply@github.com>2025-04-21 18:53:18 +0000
commit96ac7d8b5e141ac7ccac7e7c2160dcacf7e24fc0 (patch)
tree651ee9917a640f321213d7762cd9ee8007f04fbb /src
parentb3a0104ddbb617a101f6f047f4166a442378c585 (diff)
parent88a5e1ef683673c7e1b16b399d745d01ad540a19 (diff)
Rollup merge of #140052 - GuillaumeGomez:fix-140026, r=nnethercote
Fix error when an intra doc link is trying to resolve an empty associated item

Fixes https://github.com/rust-lang/rust/issues/140026.

Assigning ```@nnethercote``` since they're the one who wrote the initial change.

I updated rustdoc code instead of compiler's because I think it makes more sense that the caller ensures on their side that the name they're looking for isn't empty.

r? ```@nnethercote```
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 297597b3dea..36f5889dcf4 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -59,7 +59,12 @@ fn filter_assoc_items_by_name_and_namespace(
     ident: Ident,
     ns: Namespace,
 ) -> impl Iterator<Item = &ty::AssocItem> {
-    tcx.associated_items(assoc_items_of).filter_by_name_unhygienic(ident.name).filter(move |item| {
+    let iter: Box<dyn Iterator<Item = &ty::AssocItem>> = if !ident.name.is_empty() {
+        Box::new(tcx.associated_items(assoc_items_of).filter_by_name_unhygienic(ident.name))
+    } else {
+        Box::new([].iter())
+    };
+    iter.filter(move |item| {
         item.namespace() == ns && tcx.hygienic_eq(ident, item.ident(tcx), assoc_items_of)
     })
 }