5645e8e285
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows: - If `B` has a principal - `A` must have exactly the same principal (including generics) - Auto traits of `B` must be a subset of autotraits in `A` Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type. The lifetime of the trait object itself (`dyn ... + 'a`) is not checked. This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting. Namely, these checks make sure that vtable is always valid for the pointee.
11 lines
370 B
Plaintext
11 lines
370 B
Plaintext
error: lifetime may not live long enough
|
|
--> $DIR/ptr-to-trait-obj-different-regions-lt-ext.rs:12:5
|
|
|
|
|
LL | fn bad_cast<'a>(x: *const dyn Static<'static>) -> *const dyn Static<'a> {
|
|
| -- lifetime `'a` defined here
|
|
LL | x as _
|
|
| ^^^^^^ returning this value requires that `'a` must outlive `'static`
|
|
|
|
error: aborting due to 1 previous error
|
|
|