https://github.com/rust-lang/rust/blob/672388edbee9e93c35e5fdf7dac818a6612a5103/tests/ui/layout/normalization-failure.rs
use std::marker::PhantomData;
trait Project1 {
type Assoc1;
}
impl<T> Project1 for T {
type Assoc1 = ();
}
trait Project2 {
type Assoc2;
fn get(self) -> Self::Assoc2;
}
impl<T: Project1<Assoc1 = ()>> Project2 for PhantomData<T> {
type Assoc2 = ();
fn get(self) -> Self::Assoc2 {}
}
fn opaque<T>() -> impl Project2 {
PhantomData::<T>
}
fn check<T: Project1>() {
unsafe {
std::mem::transmute::<_, ()>(opaque::<T>().get());
//~^ ERROR: cannot transmute
//~| NOTE: source type: `{type error}` (the type has an unknown layout)
//~| NOTE: target type: `()` (0 bits)
}
}
results in
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> src/lib.rs:28:9
|
28 | std::mem::transmute::<_, ()>(opaque::<T>().get());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `{type error}` (the type has an unknown layout)
= note: target type: `()` (0 bits)
For more information about this error, try `rustc --explain E0512`.
This error message is weird:
- it references
type error even though no other error has been emitted
- we don't explain why the source error is a type error
We should have some LayoutError::NormalizationFailure here which should also be emitted and then don't emit the transmute error as one of the types is a type error
https://github.com/rust-lang/rust/blob/672388edbee9e93c35e5fdf7dac818a6612a5103/tests/ui/layout/normalization-failure.rs
results in
This error message is weird:
type erroreven though no other error has been emittedWe should have some
LayoutError::NormalizationFailurehere which should also be emitted and then don't emit the transmute error as one of the types is atype error