Skip to content

Commit bda4b30

Browse files
committed
add a test for pointer casts involving un/re/wrapping trait objects
the errors should not be there, this is a bug/missing feature.
1 parent 419b3e2 commit bda4b30

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![allow(unused)]
2+
3+
trait A {}
4+
5+
struct W<T: ?Sized>(T);
6+
struct X<T: ?Sized>(T);
7+
8+
fn unwrap(a: *const W<dyn A>) -> *const dyn A {
9+
a as _
10+
//~^ error
11+
//~| error
12+
}
13+
14+
fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A> {
15+
a as _
16+
//~^ error
17+
//~| error
18+
}
19+
20+
fn rewrap(a: *const W<dyn A>) -> *const X<dyn A> {
21+
a as _
22+
}
23+
24+
fn rewrap_nested(a: *const W<W<dyn A>>) -> *const W<X<dyn A>> {
25+
a as _
26+
}
27+
28+
fn wrap(a: *const dyn A) -> *const W<dyn A> {
29+
a as _
30+
}
31+
32+
fn main() {}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
2+
--> $DIR/ptr-to-trait-obj-wrap.rs:9:5
3+
|
4+
LL | a as _
5+
| ^ the trait `A` is not implemented for `W<(dyn A + 'static)>`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/ptr-to-trait-obj-wrap.rs:3:1
9+
|
10+
LL | trait A {}
11+
| ^^^^^^^
12+
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A`
13+
14+
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
15+
--> $DIR/ptr-to-trait-obj-wrap.rs:9:5
16+
|
17+
LL | a as _
18+
| ^ doesn't have a size known at compile-time
19+
|
20+
= help: within `W<(dyn A + 'static)>`, the trait `Sized` is not implemented for `(dyn A + 'static)`
21+
note: required because it appears within the type `W<(dyn A + 'static)>`
22+
--> $DIR/ptr-to-trait-obj-wrap.rs:5:8
23+
|
24+
LL | struct W<T: ?Sized>(T);
25+
| ^
26+
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A`
27+
28+
error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
29+
--> $DIR/ptr-to-trait-obj-wrap.rs:15:5
30+
|
31+
LL | a as _
32+
| ^ the trait `A` is not implemented for `W<(dyn A + 'static)>`
33+
|
34+
help: this trait has no implementations, consider adding one
35+
--> $DIR/ptr-to-trait-obj-wrap.rs:3:1
36+
|
37+
LL | trait A {}
38+
| ^^^^^^^
39+
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A>`
40+
41+
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
42+
--> $DIR/ptr-to-trait-obj-wrap.rs:15:5
43+
|
44+
LL | a as _
45+
| ^ doesn't have a size known at compile-time
46+
|
47+
= help: within `W<(dyn A + 'static)>`, the trait `Sized` is not implemented for `(dyn A + 'static)`
48+
note: required because it appears within the type `W<(dyn A + 'static)>`
49+
--> $DIR/ptr-to-trait-obj-wrap.rs:5:8
50+
|
51+
LL | struct W<T: ?Sized>(T);
52+
| ^
53+
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A>`
54+
55+
error: aborting due to 4 previous errors
56+
57+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)