Skip to content

Commit 2cba0b6

Browse files
Merge pull request #21074 from Aditya-PS-05/fix/param-macro-names-21070
fix: show no error when parameters match macro names
2 parents 9e833ab + d2ce37a commit 2cba0b6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

crates/ide-assists/src/handlers/add_missing_impl_members.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,4 +2470,37 @@ impl b::Checker for MyChecker {
24702470
}"#,
24712471
);
24722472
}
2473+
2474+
#[test]
2475+
fn test_parameter_names_matching_macros_not_qualified() {
2476+
// Parameter names that match macro names should not be qualified
2477+
check_assist(
2478+
add_missing_impl_members,
2479+
r#"
2480+
//- /lib.rs crate:dep
2481+
#[macro_export]
2482+
macro_rules! my_macro {
2483+
() => {}
2484+
}
2485+
2486+
pub trait Foo {
2487+
fn foo(&self, my_macro: usize);
2488+
}
2489+
2490+
//- /main.rs crate:main deps:dep
2491+
struct Bar;
2492+
2493+
impl dep::Foo for Bar {$0}
2494+
"#,
2495+
r#"
2496+
struct Bar;
2497+
2498+
impl dep::Foo for Bar {
2499+
fn foo(&self, my_macro: usize) {
2500+
${0:todo!()}
2501+
}
2502+
}
2503+
"#,
2504+
);
2505+
}
24732506
}

crates/ide-db/src/path_transform.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,13 @@ impl Ctx<'_> {
546546

547547
match resolution {
548548
hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
549+
// Macros cannot be used in pattern position, and identifiers that happen
550+
// to have the same name as macros (like parameter names `vec`, `format`, etc.)
551+
// are bindings, not references. Don't qualify them.
552+
if matches!(def, hir::ModuleDef::Macro(_)) {
553+
return None;
554+
}
555+
549556
let cfg = FindPathConfig {
550557
prefer_no_std: false,
551558
prefer_prelude: true,

0 commit comments

Comments
 (0)