You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
error[E0277]: the trait bound `dyn Trait<'_>: Unsize<dyn Trait<'_> + Send>` is not satisfied
2
+
--> $DIR/ptr-to-trait-obj-add-auto.rs:6:5
3
+
|
4
+
LL | x as _
5
+
| ^^^^^^ the trait `Unsize<dyn Trait<'_> + Send>` is not implemented for `dyn Trait<'_>`
6
+
|
7
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
8
+
9
+
error: aborting due to 1 previous error
10
+
11
+
For more information about this error, try `rustc --explain E0277`.
error[E0606]: casting `*const dyn A` as `*const dyn B` is invalid
1
+
error[E0277]: the trait bound `dyn A: Unsize<dyn B>` is not satisfied
2
2
--> $DIR/ptr-to-trait-obj-different-args.rs:19:27
3
3
|
4
4
LL | let b: *const dyn B = a as _;
5
-
| ^^^^^^
5
+
| ^^^^^^ the trait `Unsize<dyn B>` is not implemented for `dyn A`
6
6
|
7
-
= note: vtable kinds may not match
7
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
8
8
9
-
error[E0606]: casting `*const dyn Trait<X>` as `*const dyn Trait<Y>` is invalid
9
+
error[E0277]: the trait bound `dyn Trait<X>: Unsize<dyn Trait<Y>>` is not satisfied
10
10
--> $DIR/ptr-to-trait-obj-different-args.rs:22:34
11
11
|
12
12
LL | let y: *const dyn Trait<Y> = x as _;
13
-
| ^^^^^^
13
+
| ^^^^^^ the trait `Unsize<dyn Trait<Y>>` is not implemented for `dyn Trait<X>`
14
14
|
15
-
= note: vtable kinds may not match
15
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
16
16
17
-
error[E0606]: casting `*const (dyn Trait<X> + 'static)` as `*const dyn Trait<T>` is invalid
17
+
error[E0277]: the trait bound `dyn Trait<X>: Unsize<dyn Trait<T>>` is not satisfied
18
18
--> $DIR/ptr-to-trait-obj-different-args.rs:28:34
19
19
|
20
20
LL | let _: *const dyn Trait<T> = x as _;
21
-
| ^^^^^^
21
+
| ^^^^^^ the trait `Unsize<dyn Trait<T>>` is not implemented for `dyn Trait<X>`
22
22
|
23
-
= note: vtable kinds may not match
23
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
24
+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
error[E0606]: casting `*const (dyn Trait<T> + 'static)` as `*const dyn Trait<X>` is invalid
29
+
error[E0277]: the trait bound `dyn Trait<T>: Unsize<dyn Trait<X>>` is not satisfied
26
30
--> $DIR/ptr-to-trait-obj-different-args.rs:29:34
27
31
|
28
32
LL | let _: *const dyn Trait<X> = t as _;
29
-
| ^^^^^^
33
+
| ^^^^^^ the trait `Unsize<dyn Trait<X>>` is not implemented for `dyn Trait<T>`
34
+
|
35
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
36
+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
error[E0277]: the trait bound `dyn Assocked<Assoc = u8>: Unsize<dyn Assocked<Assoc = u32>>` is not satisfied
42
+
--> $DIR/ptr-to-trait-obj-different-args.rs:37:5
43
+
|
44
+
LL | x as _
45
+
| ^^^^^^ the trait `Unsize<dyn Assocked<Assoc = u32>>` is not implemented for `dyn Assocked<Assoc = u8>`
30
46
|
31
-
= note: vtable kinds may not match
47
+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
32
48
33
-
error: aborting due to 4 previous errors
49
+
error: aborting due to 5 previous errors
34
50
35
-
For more information about this error, try `rustc --explain E0606`.
51
+
For more information about this error, try `rustc --explain E0277`.
0 commit comments