-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 erroreven 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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.