Skip to content

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Nov 7, 2025

If an obligation's nested obligations expands to itself, do not add it to the working queue.

Fix #148653.

… invalid recursive struct definition

If an obligation's nested obligations expands to itself, do not add it to the working queue.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@estebank estebank mentioned this pull request Nov 7, 2025
@estebank
Copy link
Contributor Author

estebank commented Nov 7, 2025

There might be a better approach.

CC @lcnr

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 10, 2025

r? lcnr

i don't have the capacity to properly investigate the custom unsizing solver logic rn

@rustbot rustbot assigned lcnr and unassigned BoxyUwU Nov 10, 2025
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.
Copy link
Contributor

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

Copy link
Contributor

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 😅

Copy link
Contributor Author

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.

@lcnr lcnr added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hang in custom Vec

4 participants