From b6c3409ded78124cf45e9e850b899913a4549f0e Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Thu, 20 Nov 2025 14:50:56 +0530 Subject: [PATCH 1/3] fix: show no error when parameters match macro names --- .../src/handlers/add_missing_impl_members.rs | 35 +++++++++++++++++++ crates/ide-db/src/path_transform.rs | 13 +++++++ 2 files changed, 48 insertions(+) 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..d0ad2fa4f189 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,39 @@ impl b::Checker for MyChecker { }"#, ); } + + #[test] + fn test_parameter_names_matching_macros_not_qualified() { + check_assist( + add_missing_impl_members, + r#" +trait Foo { + fn foo(&self, vec: usize); + fn bar(&self, format: String, panic: bool); +} + +struct Bar; + +impl Foo for Bar {$0} +"#, + r#" +trait Foo { + fn foo(&self, vec: usize); + fn bar(&self, format: String, panic: bool); +} + +struct Bar; + +impl Foo for Bar { + fn foo(&self, vec: usize) { + ${0:todo!()} + } + + fn bar(&self, format: String, panic: bool) { + todo!() + } +} +"#, + ); + } } diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs index 4a27035afd09..096a65d9af20 100644 --- a/crates/ide-db/src/path_transform.rs +++ b/crates/ide-db/src/path_transform.rs @@ -538,6 +538,14 @@ impl Ctx<'_> { editor: &mut SyntaxEditor, ident_pat: &ast::IdentPat, ) -> Option<()> { + // Check if IdentPat is inside a function parameter. + // Parameter names are bindings, not references, thus should not be qualified. + for ancestor in ident_pat.syntax().ancestors() { + if ast::Param::can_cast(ancestor.kind()) { + return None; + } + } + let name = ident_pat.name()?; let temp_path = make::path_from_text(&name.text()); @@ -546,6 +554,11 @@ impl Ctx<'_> { match resolution { hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => { + // Don't qualify macros - they can't be used in pattern position + if matches!(def, hir::ModuleDef::Macro(_)) { + return None; + } + let cfg = FindPathConfig { prefer_no_std: false, prefer_prelude: true, From 53be2d17d1fe24ca190d87a50ab0156cf41c51f4 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Fri, 21 Nov 2025 00:13:51 +0530 Subject: [PATCH 2/3] update test --- .../src/handlers/add_missing_impl_members.rs | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) 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 d0ad2fa4f189..636cbfe9132f 100644 --- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -2473,34 +2473,32 @@ 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#" -trait Foo { - fn foo(&self, vec: usize); - fn bar(&self, format: String, panic: bool); +//- /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 Foo for Bar {$0} +impl dep::Foo for Bar {$0} "#, r#" -trait Foo { - fn foo(&self, vec: usize); - fn bar(&self, format: String, panic: bool); -} - struct Bar; -impl Foo for Bar { - fn foo(&self, vec: usize) { +impl dep::Foo for Bar { + fn foo(&self, my_macro: usize) { ${0:todo!()} } - - fn bar(&self, format: String, panic: bool) { - todo!() - } } "#, ); From d2ce37aef495ea90b2d60e1d1423050c4abf29fd Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Sat, 22 Nov 2025 23:13:02 +0530 Subject: [PATCH 3/3] fix: don't qualify macro names in pattern bindings --- crates/ide-db/src/path_transform.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs index 096a65d9af20..bc5958ec5854 100644 --- a/crates/ide-db/src/path_transform.rs +++ b/crates/ide-db/src/path_transform.rs @@ -538,14 +538,6 @@ impl Ctx<'_> { editor: &mut SyntaxEditor, ident_pat: &ast::IdentPat, ) -> Option<()> { - // Check if IdentPat is inside a function parameter. - // Parameter names are bindings, not references, thus should not be qualified. - for ancestor in ident_pat.syntax().ancestors() { - if ast::Param::can_cast(ancestor.kind()) { - return None; - } - } - let name = ident_pat.name()?; let temp_path = make::path_from_text(&name.text()); @@ -554,7 +546,9 @@ impl Ctx<'_> { match resolution { hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => { - // Don't qualify macros - they can't be used in pattern position + // 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; }