about summary refs log tree commit diff
path: root/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.rs
blob: ff2c4cacfb1f7d4b6ca506fe503d53d01a3f1bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
trait Super {}
trait Sub: Super {}

struct Wrapper<T: ?Sized>(T);

// This cast should not compile.
// Upcasting can't work here, because we are also changing the type (`Wrapper`),
// and reinterpreting would be confusing/surprising.
// See <https://github.com/rust-lang/rust/pull/120248#discussion_r1487739518>
fn cast(ptr: *const dyn Sub) -> *const Wrapper<dyn Super> {
    ptr as _ //~ error: casting `*const (dyn Sub + 'static)` as `*const Wrapper<dyn Super>` is invalid
}

fn main() {}