File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -2470,4 +2470,39 @@ impl b::Checker for MyChecker {
24702470}"# ,
24712471 ) ;
24722472 }
2473+
2474+ #[ test]
2475+ fn test_parameter_names_matching_macros_not_qualified ( ) {
2476+ check_assist (
2477+ add_missing_impl_members,
2478+ r#"
2479+ trait Foo {
2480+ fn foo(&self, vec: usize);
2481+ fn bar(&self, format: String, panic: bool);
2482+ }
2483+
2484+ struct Bar;
2485+
2486+ impl Foo for Bar {$0}
2487+ "# ,
2488+ r#"
2489+ trait Foo {
2490+ fn foo(&self, vec: usize);
2491+ fn bar(&self, format: String, panic: bool);
2492+ }
2493+
2494+ struct Bar;
2495+
2496+ impl Foo for Bar {
2497+ fn foo(&self, vec: usize) {
2498+ ${0:todo!()}
2499+ }
2500+
2501+ fn bar(&self, format: String, panic: bool) {
2502+ todo!()
2503+ }
2504+ }
2505+ "# ,
2506+ ) ;
2507+ }
24732508}
Original file line number Diff line number Diff line change @@ -538,6 +538,14 @@ impl Ctx<'_> {
538538 editor : & mut SyntaxEditor ,
539539 ident_pat : & ast:: IdentPat ,
540540 ) -> Option < ( ) > {
541+ // Check if IdentPat is inside a function parameter.
542+ // Parameter names are bindings, not references, thus should not be qualified.
543+ for ancestor in ident_pat. syntax ( ) . ancestors ( ) {
544+ if ast:: Param :: can_cast ( ancestor. kind ( ) ) {
545+ return None ;
546+ }
547+ }
548+
541549 let name = ident_pat. name ( ) ?;
542550
543551 let temp_path = make:: path_from_text ( & name. text ( ) ) ;
@@ -546,6 +554,11 @@ impl Ctx<'_> {
546554
547555 match resolution {
548556 hir:: PathResolution :: Def ( def) if def. as_assoc_item ( self . source_scope . db ) . is_none ( ) => {
557+ // Don't qualify macros - they can't be used in pattern position
558+ if matches ! ( def, hir:: ModuleDef :: Macro ( _) ) {
559+ return None ;
560+ }
561+
549562 let cfg = FindPathConfig {
550563 prefer_no_std : false ,
551564 prefer_prelude : true ,
You can’t perform that action at this time.
0 commit comments