File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments