-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
TransmuteFrom: Gracefully handle unnormalized types and normalization errors #131112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![crate_type = "lib"] | ||
#![feature(transmutability)] | ||
|
||
trait A { | ||
type AssocA; | ||
} | ||
|
||
trait B { | ||
type AssocB: std::mem::TransmuteFrom<()>; | ||
} | ||
|
||
impl<T> B for (T, u8) | ||
where | ||
T: A, | ||
{ | ||
type AssocB = T::AssocA; //~ERROR: the trait bound `<T as A>::AssocA: TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not satisfied [E0277] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm personally fine to punt on making this error message prettier — my top priority is making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's fine. But yeah, it could be customized to say something like "cannot transmute types with ty/ct params in it". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But happy to do that later. |
||
} | ||
|
||
|
||
impl<T> B for (T, u16) | ||
where | ||
for<'a> &'a i32: A, | ||
{ | ||
type AssocB = <&'static i32 as A>::AssocA; //~ERROR: `()` cannot be safely transmuted into `<&i32 as A>::AssocA` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0277]: the trait bound `<T as A>::AssocA: TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not satisfied | ||
--> $DIR/assoc-bound.rs:16:19 | ||
| | ||
LL | type AssocB = T::AssocA; | ||
| ^^^^^^^^^ the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `<T as A>::AssocA` | ||
| | ||
note: required by a bound in `B::AssocB` | ||
--> $DIR/assoc-bound.rs:9:18 | ||
| | ||
LL | type AssocB: std::mem::TransmuteFrom<()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `B::AssocB` | ||
help: consider further restricting the associated type | ||
| | ||
LL | T: A, <T as A>::AssocA: TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }> | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error[E0277]: `()` cannot be safely transmuted into `<&i32 as A>::AssocA` | ||
--> $DIR/assoc-bound.rs:24:19 | ||
| | ||
LL | type AssocB = <&'static i32 as A>::AssocA; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<&i32 as A>::AssocA` has an unknown layout | ||
| | ||
note: required by a bound in `B::AssocB` | ||
--> $DIR/assoc-bound.rs:9:18 | ||
| | ||
LL | type AssocB: std::mem::TransmuteFrom<()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `B::AssocB` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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.
Could use a comment