From 231b8ab6478e953bafcf2c3a164eabcc5ea51403 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Thu, 20 Nov 2025 14:50:56 +0530 Subject: [PATCH] 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/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs index 7e03eb30304b..d0ad2fa4f189 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -2470,4 +2470,39 @@ fn check(&self) -> b::State { }"#, ); } + + #[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/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs index 4a27035afd09..096a65d9af20 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs @@ -538,6 +538,14 @@ fn transform_ident_pat( 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 @@ fn transform_ident_pat( 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,