@@ -2981,13 +2981,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2981
2981
// Make the base error.
2982
2982
let expected = source. descr_expected ( ) ;
2983
2983
let path_str = names_to_string ( path) ;
2984
+ let item_str = path[ path. len ( ) - 1 ] ;
2984
2985
let code = source. error_code ( def. is_some ( ) ) ;
2985
2986
let ( base_msg, fallback_label, base_span) = if let Some ( def) = def {
2986
2987
( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2987
2988
format ! ( "not a {}" , expected) ,
2988
2989
span)
2989
2990
} else {
2990
- let item_str = path[ path. len ( ) - 1 ] ;
2991
2991
let item_span = path[ path. len ( ) - 1 ] . span ;
2992
2992
let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
2993
2993
( String :: new ( ) , "this scope" . to_string ( ) )
@@ -3010,6 +3010,20 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3010
3010
let code = DiagnosticId :: Error ( code. into ( ) ) ;
3011
3011
let mut err = this. session . struct_span_err_with_code ( base_span, & base_msg, code) ;
3012
3012
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
+
3013
3027
// Emit special messages for unresolved `Self` and `self`.
3014
3028
if is_self_type ( path, ns) {
3015
3029
__diagnostic_used ! ( E0411 ) ;
0 commit comments