Closed
Description
While re-discovering #57893 (in #80783) and in particular while poking around in the world of all the wonderful ICEs that you can get once you’ve convinced the compiler that a trait object is actually Sized
, I noticed that calling size_of
does actually still compile without any error. It returns 0
, e.g. see this example:
trait IsEqual {
type To: ?Sized;
}
impl<A: ?Sized> IsEqual for A {
type To = A;
}
fn main() {
argument_equal_to_sized_type::<dyn IsEqual<To = u64>>();
}
fn argument_equal_to_sized_type<T: ?Sized>()
where
<T as IsEqual>::To: Sized,
{
argument_sized::<T>();
}
fn argument_sized<T>() {
println!("{}", std::any::type_name::<T>());
println!("{}", std::mem::size_of::<T>());
}
dyn playground::IsEqual+To = u64
0
I wonder what that value of 0
is good for! Couldn’t it raise an ICE instead?
@rustbot modify labels: T-compiler, C-enhancement, A-dst