Description
I was playing around with defining higher ranked types using trait objects and tried the following pattern.
trait A<T>: B<T = T> {}
trait B {
type T;
}
To my surprise trait objects of the form dyn for<'a> A<&'a T>
were allowed. After some experimentation I found that this leads to UB in safe rust.
trait A<T>: B<T = T> {}
trait B {
type T;
}
struct Erase<T: ?Sized + B>(T::T);
fn main() {
let x = {
let x = String::from("hello");
Erase::<dyn for<'a> A<&'a _>>(x.as_str())
};
dbg!(x.0);
}
[src/main.rs:16:5] x.0 = "\0\0\0\0\0"
This is likely related to 25860 somehow, but I haven't seen this flavor before.
Meta
This effects all versions from latest nightly to 1.33.0 (on 1.32.0 it causes a ICE, and before it wasn't allowed).
Metadata
Metadata
Assignees
Labels
Area: trait objects, vtable layoutCategory: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh priorityRelevant to the types team, which will review and decide on the PR/issue.
Type
Projects
Status
Completed