-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 stack overflow when checking for structural recursion #85012
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,11 @@ | ||
struct A<T> { | ||
//~^ ERROR recursive type `A` has infinite size | ||
x: T, | ||
y: A<A<T>>, | ||
} | ||
|
||
struct B { | ||
z: A<usize> | ||
} | ||
|
||
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,17 @@ | ||
error[E0072]: recursive type `A` has infinite size | ||
--> $DIR/issue-74224.rs:1:1 | ||
| | ||
LL | struct A<T> { | ||
| ^^^^^^^^^^^ recursive type has infinite size | ||
... | ||
LL | y: A<A<T>>, | ||
| ------- recursive without indirection | ||
| | ||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable | ||
| | ||
LL | y: Box<A<A<T>>>, | ||
| ^^^^ ^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0072`. |
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,11 @@ | ||
struct Foo<T> { | ||
//~^ ERROR recursive type `Foo` has infinite size | ||
x: Foo<[T; 1]>, | ||
y: T, | ||
} | ||
|
||
struct Bar { | ||
x: Foo<Bar>, | ||
} | ||
|
||
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,17 @@ | ||
error[E0072]: recursive type `Foo` has infinite size | ||
--> $DIR/issue-84611.rs:1:1 | ||
| | ||
LL | struct Foo<T> { | ||
| ^^^^^^^^^^^^^ recursive type has infinite size | ||
LL | | ||
LL | x: Foo<[T; 1]>, | ||
| ----------- recursive without indirection | ||
| | ||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | ||
| | ||
LL | x: Box<Foo<[T; 1]>>, | ||
| ^^^^ ^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0072`. |
23 changes: 23 additions & 0 deletions
23
src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs
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,23 @@ | ||
struct A<T> { | ||
//~^ ERROR recursive type `A` has infinite size | ||
x: T, | ||
y: B<T>, | ||
} | ||
|
||
struct B<T> { | ||
//~^ ERROR recursive type `B` has infinite size | ||
z: A<T> | ||
} | ||
|
||
struct C<T> { | ||
//~^ ERROR recursive type `C` has infinite size | ||
x: T, | ||
y: Option<Option<D<T>>>, | ||
} | ||
|
||
struct D<T> { | ||
//~^ ERROR recursive type `D` has infinite size | ||
z: Option<Option<C<T>>>, | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
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 independent check for structural recursion belongs somewhere outside this fold, since it not specific to a field. Outside this function most likely, since the check is not strictly about the inner types like the name
are_inner_types_recursive
would suggest. Maybe inis_type_structurally_recursive_inner
? The same is the case forshadow_seen.first() == Some(def)
a few lines earlier.