@@ -38,8 +38,8 @@ type Res = def::Res<ast::NodeId>;
3838/// A field or associated item from self type suggested in case of resolution failure.
3939enum AssocSuggestion {
4040 Field ,
41- MethodWithSelf ,
42- AssocFn ,
41+ MethodWithSelf { called : bool } ,
42+ AssocFn { called : bool } ,
4343 AssocType ,
4444 AssocConst ,
4545}
@@ -48,8 +48,14 @@ impl AssocSuggestion {
4848 fn action ( & self ) -> & ' static str {
4949 match self {
5050 AssocSuggestion :: Field => "use the available field" ,
51- AssocSuggestion :: MethodWithSelf => "call the method with the fully-qualified path" ,
52- AssocSuggestion :: AssocFn => "call the associated function" ,
51+ AssocSuggestion :: MethodWithSelf { called : true } => {
52+ "call the method with the fully-qualified path"
53+ }
54+ AssocSuggestion :: MethodWithSelf { called : false } => {
55+ "refer to the method with the fully-qualified path"
56+ }
57+ AssocSuggestion :: AssocFn { called : true } => "call the associated function" ,
58+ AssocSuggestion :: AssocFn { called : false } => "refer to the associated function" ,
5359 AssocSuggestion :: AssocConst => "use the associated `const`" ,
5460 AssocSuggestion :: AssocType => "use the associated type" ,
5561 }
@@ -516,7 +522,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
516522 let typo_sugg =
517523 self . lookup_typo_candidate ( path, source. namespace ( ) , is_expected) . to_opt_suggestion ( ) ;
518524 if path. len ( ) == 1 && self . self_type_is_available ( ) {
519- if let Some ( candidate) = self . lookup_assoc_candidate ( ident, ns, is_expected) {
525+ if let Some ( candidate) =
526+ self . lookup_assoc_candidate ( ident, ns, is_expected, source. is_call ( ) )
527+ {
520528 let self_is_available = self . self_value_is_available ( path[ 0 ] . ident . span ) ;
521529 match candidate {
522530 AssocSuggestion :: Field => {
@@ -531,16 +539,21 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
531539 err. span_label ( span, "a field by this name exists in `Self`" ) ;
532540 }
533541 }
534- AssocSuggestion :: MethodWithSelf if self_is_available => {
542+ AssocSuggestion :: MethodWithSelf { called } if self_is_available => {
543+ let msg = if called {
544+ "you might have meant to call the method"
545+ } else {
546+ "you might have meant to refer to the method"
547+ } ;
535548 err. span_suggestion (
536549 span,
537- "you might have meant to call the method" ,
550+ msg ,
538551 format ! ( "self.{path_str}" ) ,
539552 Applicability :: MachineApplicable ,
540553 ) ;
541554 }
542- AssocSuggestion :: MethodWithSelf
543- | AssocSuggestion :: AssocFn
555+ AssocSuggestion :: MethodWithSelf { .. }
556+ | AssocSuggestion :: AssocFn { .. }
544557 | AssocSuggestion :: AssocConst
545558 | AssocSuggestion :: AssocType => {
546559 err. span_suggestion (
@@ -1498,6 +1511,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
14981511 ident : Ident ,
14991512 ns : Namespace ,
15001513 filter_fn : FilterFn ,
1514+ called : bool ,
15011515 ) -> Option < AssocSuggestion >
15021516 where
15031517 FilterFn : Fn ( Res ) -> bool ,
@@ -1539,9 +1553,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
15391553 return Some ( match & assoc_item. kind {
15401554 ast:: AssocItemKind :: Const ( ..) => AssocSuggestion :: AssocConst ,
15411555 ast:: AssocItemKind :: Fn ( box ast:: Fn { sig, .. } ) if sig. decl . has_self ( ) => {
1542- AssocSuggestion :: MethodWithSelf
1556+ AssocSuggestion :: MethodWithSelf { called }
15431557 }
1544- ast:: AssocItemKind :: Fn ( ..) => AssocSuggestion :: AssocFn ,
1558+ ast:: AssocItemKind :: Fn ( ..) => AssocSuggestion :: AssocFn { called } ,
15451559 ast:: AssocItemKind :: Type ( ..) => AssocSuggestion :: AssocType ,
15461560 ast:: AssocItemKind :: MacCall ( _) => continue ,
15471561 } ) ;
@@ -1560,10 +1574,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
15601574 let res = binding. res ( ) ;
15611575 if filter_fn ( res) {
15621576 if self . r . has_self . contains ( & res. def_id ( ) ) {
1563- return Some ( AssocSuggestion :: MethodWithSelf ) ;
1577+ return Some ( AssocSuggestion :: MethodWithSelf { called } ) ;
15641578 } else {
15651579 match res {
1566- Res :: Def ( DefKind :: AssocFn , _) => return Some ( AssocSuggestion :: AssocFn ) ,
1580+ Res :: Def ( DefKind :: AssocFn , _) => {
1581+ return Some ( AssocSuggestion :: AssocFn { called } ) ;
1582+ }
15671583 Res :: Def ( DefKind :: AssocConst , _) => {
15681584 return Some ( AssocSuggestion :: AssocConst ) ;
15691585 }
0 commit comments