Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21074 from Aditya-PS-05/fix/param-macro-names-21070
fix: show no error when parameters match macro names
Chayim Refael Friedman 5 months ago
parent 9e833ab · parent d2ce37a · commit 2cba0b6
-rw-r--r--crates/ide-assists/src/handlers/add_missing_impl_members.rs33
-rw-r--r--crates/ide-db/src/path_transform.rs7
2 files changed, 40 insertions, 0 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 7e03eb3030..636cbfe913 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 4a27035afd..bc5958ec58 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,