diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs index 7e03eb30304b..636cbfe9132f 100644 --- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -2470,4 +2470,37 @@ impl b::Checker for MyChecker { }"#, ); } + + #[test] + fn test_parameter_names_matching_macros_not_qualified() { + // Parameter names that match macro names should not be qualified + check_assist( + add_missing_impl_members, + r#" +//- /lib.rs crate:dep +#[macro_export] +macro_rules! my_macro { + () => {} +} + +pub trait Foo { + fn foo(&self, my_macro: usize); +} + +//- /main.rs crate:main deps:dep +struct Bar; + +impl dep::Foo for Bar {$0} +"#, + r#" +struct Bar; + +impl dep::Foo for Bar { + fn foo(&self, my_macro: usize) { + ${0:todo!()} + } +} +"#, + ); + } } diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs index 4a27035afd09..bc5958ec5854 100644 --- a/crates/ide-db/src/path_transform.rs +++ b/crates/ide-db/src/path_transform.rs @@ -546,6 +546,13 @@ impl Ctx<'_> { match resolution { hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => { + // Macros cannot be used in pattern position, and identifiers that happen + // to have the same name as macros (like parameter names `vec`, `format`, etc.) + // are bindings, not references. Don't qualify them. + if matches!(def, hir::ModuleDef::Macro(_)) { + return None; + } + let cfg = FindPathConfig { prefer_no_std: false, prefer_prelude: true,