-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
fix: Guard SizeSkeleton::compute against stack overflow #156235
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
Open
rajgandhi1
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
rajgandhi1:compiler_stack_overflow_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−7
Open
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 hidden or 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 hidden or 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,24 @@ | ||
| // Regression test for issue #156137. | ||
| // Computing the `SizeSkeleton` of a type whose layout depends on itself | ||
| // through a normalizing type alias used to recurse without bound and | ||
| // blow the stack. We now bail out via the recursion limit and emit a | ||
| // regular error instead of ICE-ing. | ||
|
|
||
| use std::mem::transmute; | ||
|
|
||
| trait Trait { | ||
| type Assoc; | ||
| } | ||
| impl<T> Trait for T { | ||
| type Assoc = T; | ||
| } | ||
| type Alias<T> = <T as Trait>::Assoc; | ||
|
|
||
| pub struct Thing<T: ?Sized>(*const T, Alias<Thing<T>>); | ||
|
|
||
| pub fn weird<T: ?Sized>(value: Thing<T>) { | ||
| let _: i32 = unsafe { transmute(value) }; | ||
| //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or 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,12 @@ | ||
| error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
| --> $DIR/recursive-size-skeleton.rs:20:27 | ||
| | | ||
| LL | let _: i32 = unsafe { transmute(value) }; | ||
| | ^^^^^^^^^ | ||
| | | ||
| = note: source type: `Thing<T>` (the type `*const T` has an unknown layout) | ||
| = note: target type: `i32` (32 bits) | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0512`. |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We should just raise a recursion limit error here. There's a function for doing that, several other recursion limit checks should be doing that, too.
View changes since the review