diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-13 06:41:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-13 06:41:23 +0100 |
| commit | 5d131407daea78c0490e6958d84dd69447fae8a6 (patch) | |
| tree | 752a44c87f7f88457e96aebb1099cab080231814 | |
| parent | e42a7024305417e516a1dd9cf58eff3d5af62c69 (diff) | |
| parent | 96b8225d8dd971bc2ecc7aa12068adcda9a9f20f (diff) | |
| download | rust-5d131407daea78c0490e6958d84dd69447fae8a6.tar.gz rust-5d131407daea78c0490e6958d84dd69447fae8a6.zip | |
Rollup merge of #122360 - veera-sivarajan:bugfix-121941, r=compiler-errors
Don't Create `ParamCandidate` When Obligation Contains Errors Fixes #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 #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 #73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
3 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 66f740b761d..89654ed61ae 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -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 diff --git a/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.rs b/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.rs new file mode 100644 index 00000000000..a08407683d8 --- /dev/null +++ b/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.rs @@ -0,0 +1,5 @@ +fn function<T: PartialEq>() { + foo == 2; //~ ERROR cannot find value `foo` in this scope [E0425] +} + +fn main() {} diff --git a/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.stderr b/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.stderr new file mode 100644 index 00000000000..2da731dcc4b --- /dev/null +++ b/tests/ui/traits/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.stderr @@ -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`. |
