Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't continue probing for method if in suggestion and autoderef hits ambiguity #125466

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ambiguous.
if let Some(bad_ty) = &steps.opt_bad_ty {
if is_suggestion.0 {
// Ambiguity was encountered during a suggestion. Just keep going.
debug!("ProbeContext: encountered ambiguity in suggestion");
// Ambiguity was encountered during a suggestion. There's really
// not much use in suggesting methods in this case.
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: Vec::new(),
unsatisfied_predicates: Vec::new(),
out_of_scope_traits: Vec::new(),
similar_candidate: None,
mode,
}));
} else if bad_ty.reached_raw_pointer
&& !self.tcx.features().arbitrary_self_types
&& !self.tcx.sess.at_least_rust_2018()
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/methods/suggest-method-on-call-for-ambig-receiver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Fix for <https://github.com/rust-lang/rust/issues/125432>.

fn separate_arms() {
let mut x = None;
match x {
None => {
x = Some(0);
}
Some(right) => {
consume(right);
//~^ ERROR cannot find function `consume` in this scope
}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find function `consume` in this scope
--> $DIR/suggest-method-on-call-for-ambig-receiver.rs:10:13
|
LL | consume(right);
| ^^^^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
Loading