-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Rust doesn't know type is sized #50824
Comments
(The definition above of Seems like a bug re. the trait bounds. Reducing a bit (tested on nightly and stable): #![crate_type = "lib"]
use std::mem::{size_of, transmute};
fn bug<T>() -> (usize, T) {
(
size_of::<T>(),
transmute(
[0u8; size_of::<T>()]
)
)
} |
Lol yes sorry for the blatantly unsafe code. I was playing around with getting type inference to work in a macro. That code was never intended to actually be run. |
The error seems to appear when Rust is forced to compute with values inside types. Further minimised example: (play)
|
The error message given for this is:
There is no error about |
As a workaround, you can do this instead: use std::mem;
unsafe fn example<T>() -> (usize, T) {
(mem::size_of::<T>(), mem::zeroed())
} This is unsafe, because not every type has 0 as a valid value. Still a bug, don't get me wrong. |
This is just another symptom of #43408 I believe |
rustc
is telling me thatT
needs to beSized
when it is clearly alreadySized
. This code:(playground link)
Produces this error:
Obviously
T: Sized
andwhere T: Sized
are redundant, but I did it to demonstrate that neither is sufficient. The same error appears if only one of the bounds is used, or if neither are used.The text was updated successfully, but these errors were encountered: