-
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 ICE in mir when evaluating SizeOf on unsized type #81185
Merged
Merged
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,33 @@ | ||
// check-fail | ||
|
||
// This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(const_evaluatable_checked)] | ||
#![feature(const_generics)] | ||
|
||
use std::fmt::Debug; | ||
use std::marker::PhantomData; | ||
use std::mem::size_of; | ||
|
||
struct Inline<T> | ||
where | ||
[u8; size_of::<T>() + 1]: , | ||
{ | ||
_phantom: PhantomData<T>, | ||
buf: [u8; size_of::<T>() + 1], | ||
} | ||
|
||
impl<T> Inline<T> | ||
where | ||
[u8; size_of::<T>() + 1]: , | ||
{ | ||
pub fn new(val: T) -> Inline<T> { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() { | ||
let dst = Inline::<dyn Debug>::new(0); //~ ERROR | ||
//~^ ERROR | ||
} |
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,42 @@ | ||
error[E0599]: no function or associated item named `new` found for struct `Inline<dyn Debug>` in the current scope | ||
--> $DIR/issue-80742.rs:31:36 | ||
| | ||
LL | / struct Inline<T> | ||
LL | | where | ||
LL | | [u8; size_of::<T>() + 1]: , | ||
LL | | { | ||
LL | | _phantom: PhantomData<T>, | ||
LL | | buf: [u8; size_of::<T>() + 1], | ||
LL | | } | ||
| |_- function or associated item `new` not found for this | ||
... | ||
LL | let dst = Inline::<dyn Debug>::new(0); | ||
| ^^^ function or associated item not found in `Inline<dyn Debug>` | ||
| | ||
::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL | ||
| | ||
LL | pub trait Debug { | ||
| --------------- doesn't satisfy `dyn Debug: Sized` | ||
| | ||
= note: the method `new` exists but the following trait bounds were not satisfied: | ||
`dyn Debug: Sized` | ||
|
||
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time | ||
--> $DIR/issue-80742.rs:31:15 | ||
| | ||
LL | struct Inline<T> | ||
| - required by this bound in `Inline` | ||
... | ||
LL | let dst = Inline::<dyn Debug>::new(0); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `dyn Debug` | ||
help: consider relaxing the implicit `Sized` restriction | ||
| | ||
LL | struct Inline<T: ?Sized> | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0599. | ||
For more information about an error, try `rustc --explain E0277`. | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
I think we should still abort execution. The result that we return here is wrong. So there should be a new error variant, similar to
TransmuteSizeDiff
, and that should be raised here.