-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Avoid infinite cycle in coerce_unsized_old_solver when encountering invalid recursive struct definition
#148677
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
base: main
Are you sure you want to change the base?
Conversation
… invalid recursive struct definition If an obligation's nested obligations expands to itself, do not add it to the working queue.
|
There might be a better approach. CC @lcnr |
|
r? lcnr i don't have the capacity to properly investigate the custom unsizing solver logic rn |
| if nested.len() == 1 && &obligation == &nested[0] { | ||
| // Avoid hang when expanding the current obligation to the same obligation. | ||
| // This doesn't occur under normal circumstances, only on incorrect | ||
| // recursive type definitions. Issue #148653. |
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 feels really brittle
I don't fully understand what's necessary for this to diverge, but would expect it to be possible to have non-trivial recursion here as well, e.g. why does the following not have issues
struct Vec<T> { //~ ERROR recursive type `Vec` has infinite size
data: Vec<Vec<T>>, //~ ERROR type parameter `T` is only used recursively
}
impl<T> Vec<T> {
pub fn push(&mut self) -> &mut Self {
self
}
}I feel like we probably should properly increment the recursion_depth of the obligations and have a recursion limit check here instead
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.
alternatively this might cause issues if they reference different regions (or we just don't resolve them to be equal at that point). relying on structural equality for diversion checks is just really brittle 😅
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 disagree, I just tried to make the minimal possible patch (that I could find in a limited amount of time) that could avoid the hang on the current solver.
If an obligation's nested obligations expands to itself, do not add it to the working queue.
Fix #148653.