Skip to content

Commit b060c18

Browse files
committed
Make the span more relevant to possible match
1 parent 39c4312 commit b060c18

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1241,27 +1241,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12411241
}
12421242
// Only if an appropriate error source is not found, check method chain for possible candiates
12431243
let error_source_not_found = unsatisfied_predicates.is_empty();
1244-
if error_source_not_found && let Mode::MethodCall = mode && let SelfSource::MethodCall(mut rcvr_expr) = source {
1245-
while let hir::ExprKind::MethodCall(_path_segment, parent_expr, _args, method_span) =
1246-
rcvr_expr.kind
1244+
if error_source_not_found && let Mode::MethodCall = mode && let SelfSource::MethodCall(mut source_expr) = source {
1245+
while let hir::ExprKind::MethodCall(_path_segment, rcvr_expr, _args, _span) =
1246+
source_expr.kind
12471247
{
1248-
let prev_ty = self.resolve_vars_if_possible(
1248+
let rcvr_ty = self.resolve_vars_if_possible(
12491249
self.typeck_results
12501250
.borrow()
1251-
.expr_ty_adjusted_opt(parent_expr)
1251+
.expr_ty_adjusted_opt(rcvr_expr)
12521252
.unwrap_or(Ty::new_misc_error(self.tcx)),);
12531253

12541254
for _matched_method in self.probe_for_name_many(
12551255
Mode::MethodCall,
12561256
item_name,
12571257
None,
12581258
IsSuggestion(true),
1259-
prev_ty,
1260-
rcvr_expr.hir_id,
1259+
rcvr_ty,
1260+
source_expr.hir_id,
12611261
ProbeScope::TraitsInScope,) {
1262-
err.span_label(method_span, format!("{item_kind} `{item_name}` is available on `{prev_ty}`"));
1262+
err.span_label(rcvr_expr.span, format!("{item_kind} `{item_name}` is available on `{rcvr_ty}`"));
12631263
}
1264-
rcvr_expr = parent_expr;
1264+
source_expr = rcvr_expr;
12651265

12661266
}
12671267
}

tests/ui/structs/method-chain-expression-failure.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ LL | struct D;
55
| -------- method `foo` not found for this struct
66
...
77
LL | A.b().c().d().foo();
8-
| --- ^^^ method not found in `D`
9-
| |
10-
| method `foo` is available on `&B`
8+
| ----- ^^^ method not found in `D`
9+
| |
10+
| method `foo` is available on `&B`
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)