Skip to content

Commit 96b8225

Browse files
Don't Create ParamCandidate When Obligation Contains Errors
Fixes #121941
1 parent 4a0cc88 commit 96b8225

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+7
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
219219
) -> Result<(), SelectionError<'tcx>> {
220220
debug!(?stack.obligation);
221221

222+
// An error type will unify with anything. So, avoid
223+
// matching an error type with `ParamCandidate`.
224+
// This helps us avoid spurious errors like issue #121941.
225+
if stack.obligation.predicate.references_error() {
226+
return Ok(());
227+
}
228+
222229
let all_bounds = stack
223230
.obligation
224231
.param_env
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn function<T: PartialEq>() {
2+
foo == 2; //~ ERROR cannot find value `foo` in this scope [E0425]
3+
}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `foo` in this scope
2+
--> $DIR/dont-match-error-ty-with-calller-supplied-obligation-issue-121941.rs:2:5
3+
|
4+
LL | foo == 2;
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)