Skip to content

Commit 8ff1f80

Browse files
Merge pull request rust-lang#22822 from RealRTTV/master
Fix: panic with a function item and a proc macro item having a duplicate name
2 parents 51cb2bc + 7cd274c commit 8ff1f80

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

crates/hir-def/src/item_scope.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,11 @@ impl ItemScope {
483483
}
484484

485485
pub(crate) fn remove_from_value_ns(&mut self, name: &Name, def: ModuleDefId) {
486-
let entry = self.values.shift_remove(name);
487-
assert!(entry.is_some_and(|entry| entry.def == def))
486+
// predicate needed since a different item with the same name may be registered instead,
487+
// leading to `shift_remove` removing the wrong item.
488+
if self.values.get(name).is_some_and(|entry| entry.def == def) {
489+
let _ = self.values.shift_remove(name);
490+
}
488491
}
489492

490493
pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<&[MacroId]> {

crates/hir-def/src/nameres/tests/macros.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,3 +1755,18 @@ enum MyEnum {}
17551755
"#]],
17561756
);
17571757
}
1758+
1759+
#[test]
1760+
fn regression_22806() {
1761+
compute_crate_def_map(
1762+
r#"
1763+
#![crate_type = "proc-macro"]
1764+
1765+
fn foo() {}
1766+
1767+
#[proc_macro]
1768+
fn foo() {}
1769+
"#,
1770+
|_| (),
1771+
)
1772+
}

0 commit comments

Comments
 (0)