1
Fork 0
rust/tests/ui/cast/ptr-to-trait-obj-wrap.rs
Waffle Lapkin 5712d2e956
add a test for pointer casts involving un/re/wrapping trait objects
the errors should not be there, this is a bug/missing feature.
2025-03-08 14:49:47 +01:00

36 lines
756 B
Rust

// Checks that various casts of pointers to trait objects wrapped in structures
// work. Note that the metadata doesn't change when a DST is wrapped in a
// structure, so these casts *are* fine.
//
// `unwrap` and `unwrap_nested` currently don't work due to a compiler limitation.
trait A {}
struct W<T: ?Sized>(T);
struct X<T: ?Sized>(T);
fn unwrap(a: *const W<dyn A>) -> *const dyn A {
a as _
//~^ error
//~| error
}
fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A> {
a as _
//~^ error
//~| error
}
fn rewrap(a: *const W<dyn A>) -> *const X<dyn A> {
a as _
}
fn rewrap_nested(a: *const W<W<dyn A>>) -> *const W<X<dyn A>> {
a as _
}
fn wrap(a: *const dyn A) -> *const W<dyn A> {
a as _
}
fn main() {}