@@ -7,6 +7,7 @@ use crate::{PathResult, PathSource, Segment};
77
88use rustc_ast:: ast:: { self , Expr , ExprKind , Item , ItemKind , NodeId , Path , Ty , TyKind } ;
99use rustc_ast:: util:: lev_distance:: find_best_match_for_name;
10+ use rustc_ast:: visit:: FnKind ;
1011use rustc_data_structures:: fx:: FxHashSet ;
1112use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticBuilder } ;
1213use rustc_hir as hir;
@@ -175,15 +176,38 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
175176 let mut err = self . r . session . struct_span_err_with_code ( base_span, & base_msg, code) ;
176177
177178 // Emit help message for fake-self from other languages (e.g., `this` in Javascript).
178- if [ "this" , "my" ] . contains ( & & * item_str. as_str ( ) )
179- && self . self_value_is_available ( path[ 0 ] . ident . span , span)
180- {
179+ if [ "this" , "my" ] . contains ( & & * item_str. as_str ( ) ) && self . self_type_is_available ( span) {
181180 err. span_suggestion_short (
182181 span,
183182 "you might have meant to use `self` here instead" ,
184183 "self" . to_string ( ) ,
185184 Applicability :: MaybeIncorrect ,
186185 ) ;
186+ if !self . self_value_is_available ( path[ 0 ] . ident . span , span) {
187+ if let Some ( ( FnKind :: Fn ( _, _, sig, ..) , fn_span) ) =
188+ & self . diagnostic_metadata . current_function
189+ {
190+ if let Some ( param) = sig. decl . inputs . get ( 0 ) {
191+ err. span_suggestion_verbose (
192+ param. span . shrink_to_lo ( ) ,
193+ "you are also missing a `self` receiver argument" ,
194+ "&self, " . to_string ( ) ,
195+ Applicability :: MaybeIncorrect ,
196+ ) ;
197+ } else {
198+ err. span_suggestion_verbose (
199+ self . r
200+ . session
201+ . source_map ( )
202+ . span_through_char ( * fn_span, '(' )
203+ . shrink_to_hi ( ) ,
204+ "you are also missing a `self` receiver argument" ,
205+ "&self" . to_string ( ) ,
206+ Applicability :: MaybeIncorrect ,
207+ ) ;
208+ }
209+ }
210+ }
187211 }
188212
189213 // Emit special messages for unresolved `Self` and `self`.
0 commit comments