Skip to content

Commit 4bcb45b

Browse files
committed
Remove mutation check
1 parent 1e6ae64 commit 4bcb45b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
470470
);
471471
}
472472

473-
let mut internal_mutation_in_method = false;
474473
if let SelfSource::MethodCall(rcvr_expr) = source {
475474
self.suggest_fn_call(&mut err, rcvr_expr, rcvr_ty, |output_ty| {
476475
let call_expr =
@@ -484,7 +483,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
484483
);
485484
probe.is_ok()
486485
});
487-
internal_mutation_in_method = true;
488486
self.note_internal_mutation_in_method(
489487
&mut err,
490488
rcvr_expr,
@@ -1242,13 +1240,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12421240
}
12431241
}
12441242
// Only if an appropriate error source is not found, check method chain for possible candiates
1245-
let error_source_not_found =
1246-
unsatisfied_predicates.is_empty() && !internal_mutation_in_method;
1243+
let error_source_not_found = unsatisfied_predicates.is_empty();
12471244
if error_source_not_found && let Mode::MethodCall = mode && let SelfSource::MethodCall(mut rcvr_expr) = source {
12481245
while let hir::ExprKind::MethodCall(_path_segment, parent_expr, _args, method_span) =
12491246
rcvr_expr.kind
12501247
{
1251-
print!("rcvr_expr {:?}", rcvr_expr);
12521248
let prev_ty = self.resolve_vars_if_possible(
12531249
self.typeck_results
12541250
.borrow()
@@ -1262,13 +1258,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12621258
IsSuggestion(true),
12631259
prev_ty,
12641260
rcvr_expr.hir_id,
1265-
ProbeScope::AllTraits,) {
1261+
ProbeScope::TraitsInScope,) {
12661262
err.span_label(method_span, format!("{item_kind} `{item_name}` is available on `{prev_ty}`"));
12671263
}
12681264
rcvr_expr = parent_expr;
12691265

12701266
}
12711267
}
1268+
12721269
self.note_derefed_ty_has_method(&mut err, source, rcvr_ty, item_name, expected);
12731270
return Some(err);
12741271
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +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`
8+
| --- ^^^ method not found in `D`
9+
| |
10+
| method `foo` is available on `&B`
911

1012
error: aborting due to previous error
1113

tests/ui/suggestions/chain-method-call-mutation-in-place.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ error[E0599]: no method named `sort` found for unit type `()` in the current sco
1818
--> $DIR/chain-method-call-mutation-in-place.rs:3:72
1919
|
2020
LL | vec![1, 2, 3].into_iter().collect::<Vec<i32>>().sort_by_key(|i| i).sort();
21-
| ^^^^ method not found in `()`
21+
| ----------- ------------------ ^^^^ method not found in `()`
22+
| | |
23+
| | method `sort` is available on `&mut [i32]`
24+
| method `sort` is available on `Vec<i32>`
2225
|
2326
note: method `sort_by_key` modifies its receiver in-place, it is not meant to be used in method chains.
2427
--> $DIR/chain-method-call-mutation-in-place.rs:3:53

0 commit comments

Comments
 (0)