-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
fix: prevent infinity evaluate predicate for auto-trait #111985
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
struct A<T>(B<T>); | ||
//~^ ERROR: recursive types `A` and `B` have infinite size | ||
struct B<T>(A<A<T>>); | ||
trait Foo {} | ||
impl<T> Foo for T where T: Send {} | ||
impl Foo for B<u8> {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0072]: recursive types `A` and `B` have infinite size | ||
--> $DIR/issue-105231.rs:1:1 | ||
| | ||
LL | struct A<T>(B<T>); | ||
| ^^^^^^^^^^^ ---- recursive without indirection | ||
LL | | ||
LL | struct B<T>(A<A<T>>); | ||
| ^^^^^^^^^^^ ------- recursive without indirection | ||
| | ||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | ||
| | ||
LL ~ struct A<T>(Box<B<T>>); | ||
LL | | ||
LL ~ struct B<T>(Box<A<A<T>>>); | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0072`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still breaks if you changed the definitions from:
to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it and there seems to be no panic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I've misinterpreted why you're using
sized_constraint
here.Checking that
sized_constraint
matches[ty::Error]
doesn't seem like the right way to check that the struct is cyclical, and after that, not registering anAutoImplCandidate
if a type is cyclical also seems like the wrong way to avoid an overflow in the solver.The correct solution is probably to not ICE on the overflow at all, and instead treat it as ambiguity, but that is (as I said above) a bit delicate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, this is a method I never thought of, because when I look at this part of the code, it seems to be all set up for throwing an error after an overflow.
can we write it like this:
It should eventually throw the following error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's okay to be emitting an overflow error there. Typically we avoid emitting errors from within the trait solver itself (except for pretty specific cases).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make the following changes:
it will not cause a panic because the code has been checked for cycles in the
check_evaluation_cycle
function (see here).Therefore, could we add a similar function called
check_evaluation_overflow
to check if the current stack has an infinite evaluation process?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that that's right either. I think we should probably just make
predicate_may_hold_fatal
not actually ICE. But then there's only one callsite forpredicate_may_hold_fatal
anyways, so it's probably best to just inline it and delay a bug if we have overflow.