@@ -2981,13 +2981,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
29812981 // Make the base error.
29822982 let expected = source. descr_expected ( ) ;
29832983 let path_str = names_to_string ( path) ;
2984+ let item_str = path[ path. len ( ) - 1 ] ;
29842985 let code = source. error_code ( def. is_some ( ) ) ;
29852986 let ( base_msg, fallback_label, base_span) = if let Some ( def) = def {
29862987 ( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
29872988 format ! ( "not a {}" , expected) ,
29882989 span)
29892990 } else {
2990- let item_str = path[ path. len ( ) - 1 ] ;
29912991 let item_span = path[ path. len ( ) - 1 ] . span ;
29922992 let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
29932993 ( String :: new ( ) , "this scope" . to_string ( ) )
@@ -3010,6 +3010,20 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
30103010 let code = DiagnosticId :: Error ( code. into ( ) ) ;
30113011 let mut err = this. session . struct_span_err_with_code ( base_span, & base_msg, code) ;
30123012
3013+ // Emit help message for fake-self from other languages like `this`(javascript)
3014+ let fake_self: Vec < Ident > = [ "this" , "my" ] . iter ( ) . map (
3015+ |s| Ident :: from_str ( * s)
3016+ ) . collect ( ) ;
3017+ if fake_self. contains ( & item_str)
3018+ && this. self_value_is_available ( path[ 0 ] . span , span) {
3019+ err. span_suggestion_with_applicability (
3020+ span,
3021+ "did you mean" ,
3022+ "self" . to_string ( ) ,
3023+ Applicability :: MachineApplicable ,
3024+ ) ;
3025+ }
3026+
30133027 // Emit special messages for unresolved `Self` and `self`.
30143028 if is_self_type ( path, ns) {
30153029 __diagnostic_used ! ( E0411 ) ;
0 commit comments