Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/ide-assists/src/handlers/add_missing_impl_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()}
}
}
"#,
);
}
}
7 changes: 7 additions & 0 deletions crates/ide-db/src/path_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down