Skip to content

Commit

Permalink
Rollup merge of rust-lang#122360 - veera-sivarajan:bugfix-121941, r=c…
Browse files Browse the repository at this point in the history
…ompiler-errors

 Don't Create `ParamCandidate` When Obligation Contains Errors

Fixes rust-lang#121941

I'm not sure if I understand this correctly but this bug was caused by an error type incorrectly matching against `ParamCandidate`. This was introduced by the changes made in rust-lang#72621 (figured using cargo-bisect-rustc).

This PR fixes it by skipping `ParamCandidate` generation when an error type is involved. Also, this is similar to rust-lang#73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
  • Loading branch information
matthiaskrgr authored Mar 13, 2024
2 parents d93772d + 96b8225 commit 0dd4ffe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn function<T: PartialEq>() {
foo == 2; //~ ERROR cannot find value `foo` in this scope [E0425]
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 0dd4ffe

Please sign in to comment.