@@ -1186,12 +1186,17 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
1186
1186
let is_assoc_fn = self . self_type_is_available ( ) ;
1187
1187
let self_from_macro = "a `self` parameter, but a macro invocation can only \
1188
1188
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 {
1190
1190
// The current function has a `self` parameter, but we were unable to resolve
1191
1191
// 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 .
1193
1193
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
+ }
1195
1200
} else {
1196
1201
let doesnt = if is_assoc_fn {
1197
1202
let ( span, sugg) = fn_kind
@@ -1204,7 +1209,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
1204
1209
// This avoids placing the suggestion into the visibility specifier.
1205
1210
let span = fn_kind
1206
1211
. 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 ( ) ) ) ;
1208
1213
(
1209
1214
self . r
1210
1215
. tcx
0 commit comments