Don't Create ParamCandidate When Obligation Contains Errors

Fixes #121941
This commit is contained in:
Veera 2024-03-11 23:05:43 -04:00
parent 4a0cc881dc
commit 96b8225d8d
3 changed files with 21 additions and 0 deletions

View file

@ -219,6 +219,13 @@ fn assemble_candidates_from_caller_bounds<'o>(
) -> Result<(), SelectionError<'tcx>> {
debug!(?stack.obligation);
// An error type will unify with anything. So, avoid
// matching an error type with `ParamCandidate`.
// This helps us avoid spurious errors like issue #121941.
if stack.obligation.predicate.references_error() {
return Ok(());
}
let all_bounds = stack
.obligation
.param_env

View file

@ -0,0 +1,5 @@
fn function<T: PartialEq>() {
foo == 2; //~ ERROR cannot find value `foo` in this scope [E0425]
}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0425]: cannot find value `foo` in this scope
--> $DIR/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.rs:2:5
|
LL | foo == 2;
| ^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.