-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't create impl candidates when obligation contains errors #73005
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1104,6 +1104,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |
// who might care about this case, like coherence, should use | ||
// that function). | ||
if candidates.is_empty() { | ||
// If there's an error type, 'downgrade' our result from | ||
// `Err(Unimplemented)` to `Ok(None)`. This helps us avoid | ||
// emitting additional spurious errors, since we're guaranteed | ||
// to have emitted at least one. | ||
if stack.obligation.references_error() { | ||
debug!("no results for error type, treating as ambiguous"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With #70551, seeing an error type guarantees that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. r=me when CI is green then :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you want to wait for #70551, or can I r+ this now? |
||
return Ok(None); | ||
} | ||
return Err(Unimplemented); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Regression test for issue #72839 | ||
// Tests that we do not overflow during trait selection after | ||
// a type error occurs | ||
use std::ops::Rem; | ||
trait Foo {} | ||
struct MyStruct<T>(T); | ||
|
||
impl<T, U> Rem<MyStruct<T>> for MyStruct<U> where MyStruct<U>: Rem<MyStruct<T>> { | ||
type Output = u8; | ||
fn rem(self, _: MyStruct<T>) -> Self::Output { | ||
panic!() | ||
} | ||
} | ||
|
||
fn main() {} | ||
|
||
fn foo() { | ||
if missing_var % 8 == 0 {} //~ ERROR cannot find | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0425]: cannot find value `missing_var` in this scope | ||
--> $DIR/issue-72839-error-overflow.rs:18:8 | ||
| | ||
LL | if missing_var % 8 == 0 {} | ||
| ^^^^^^^^^^^ not found in this scope | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
Uh oh!
There was an error while loading. Please reload this page.