@@ -1186,12 +1186,17 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11861186 let is_assoc_fn = self . self_type_is_available ( ) ;
11871187 let self_from_macro = "a `self` parameter, but a macro invocation can only \
11881188 access identifiers it receives from parameters";
1189- if let Some ( ( fn_kind, span ) ) = & self . diag_metadata . current_function {
1189+ if let Some ( ( fn_kind, fn_span ) ) = & self . diag_metadata . current_function {
11901190 // The current function has a `self` parameter, but we were unable to resolve
11911191 // a reference to `self`. This can only happen if the `self` identifier we
1192- // are resolving came from a different hygiene context.
1192+ // are resolving came from a different hygiene context or a variable binding .
11931193 if fn_kind. decl ( ) . inputs . get ( 0 ) . is_some_and ( |p| p. is_self ( ) ) {
1194- err. span_label ( * span, format ! ( "this function has {self_from_macro}" ) ) ;
1194+ // When the `self` is from a macro, we should add a label
1195+ // If the `self` resolved failed, and it is not from a macro,
1196+ // it's a variable binding, e.g. `let self = 1;`, we do nothing, see issue #143134
1197+ if span. from_expansion ( ) {
1198+ err. span_label ( * fn_span, format ! ( "this function has {self_from_macro}" ) ) ;
1199+ }
11951200 } else {
11961201 let doesnt = if is_assoc_fn {
11971202 let ( span, sugg) = fn_kind
@@ -1204,7 +1209,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12041209 // This avoids placing the suggestion into the visibility specifier.
12051210 let span = fn_kind
12061211 . ident ( )
1207- . map_or ( * span , |ident| span . with_lo ( ident. span . hi ( ) ) ) ;
1212+ . map_or ( * fn_span , |ident| fn_span . with_lo ( ident. span . hi ( ) ) ) ;
12081213 (
12091214 self . r
12101215 . tcx
0 commit comments