Skip to content

Commit 4bc41b9

Browse files
Don't continue probing for method if in suggestion and autoderef hits ambiguity
1 parent 5baee04 commit 4bc41b9

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
395395
// ambiguous.
396396
if let Some(bad_ty) = &steps.opt_bad_ty {
397397
if is_suggestion.0 {
398-
// Ambiguity was encountered during a suggestion. Just keep going.
399-
debug!("ProbeContext: encountered ambiguity in suggestion");
398+
// Ambiguity was encountered during a suggestion. There's really
399+
// not much use in suggesting methods in this case.
400+
return Err(MethodError::NoMatch(NoMatchData {
401+
static_candidates: Vec::new(),
402+
unsatisfied_predicates: Vec::new(),
403+
out_of_scope_traits: Vec::new(),
404+
similar_candidate: None,
405+
mode,
406+
}));
400407
} else if bad_ty.reached_raw_pointer
401408
&& !self.tcx.features().arbitrary_self_types
402409
&& !self.tcx.sess.at_least_rust_2018()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Fix for <https://github.com/rust-lang/rust/issues/125432>.
2+
3+
fn separate_arms() {
4+
let mut x = None;
5+
match x {
6+
None => {
7+
x = Some(0);
8+
}
9+
Some(right) => {
10+
consume(right);
11+
//~^ ERROR cannot find function `consume` in this scope
12+
}
13+
}
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `consume` in this scope
2+
--> $DIR/suggest-method-on-call-for-ambig-receiver.rs:10:13
3+
|
4+
LL | consume(right);
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)