Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80157a5

Browse files
committedMar 8, 2025
bless tests
yay, I fixed the bug/missing feature :')
1 parent b62d58f commit 80157a5

7 files changed

+66
-235
lines changed
 

‎tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ struct X<T: ?Sized>(T);
1010

1111
fn unwrap(a: *const W<dyn A>) -> *const (dyn A + Send) {
1212
a as _
13-
//~^ error
14-
//~| error
15-
//~| error
13+
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast
1614
}
1715

1816
fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A + Send> {
1917
a as _
20-
//~^ error
21-
//~| error
22-
//~| error
18+
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast
2319
}
2420

2521
fn rewrap(a: *const W<dyn A>) -> *const X<dyn A + Send> {
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,23 @@
1-
error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
2-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12: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-add-auto.rs:6:1
9-
|
10-
LL | trait A {}
11-
| ^^^^^^^
12-
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A + Send`
13-
14-
error[E0277]: `(dyn A + 'static)` cannot be sent between threads safely
15-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5
16-
|
17-
LL | a as _
18-
| ^ `(dyn A + 'static)` cannot be sent between threads safely
19-
|
20-
= help: within `W<(dyn A + 'static)>`, the trait `Send` 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-add-auto.rs:8: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 + Send`
27-
28-
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
1+
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
292
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5
303
|
314
LL | a as _
32-
| ^ doesn't have a size known at compile-time
33-
|
34-
= help: within `W<(dyn A + 'static)>`, the trait `Sized` is not implemented for `(dyn A + 'static)`
35-
note: required because it appears within the type `W<(dyn A + 'static)>`
36-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
37-
|
38-
LL | struct W<T: ?Sized>(T);
39-
| ^
40-
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A + Send`
41-
42-
error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
43-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:19:5
44-
|
45-
LL | a as _
46-
| ^ the trait `A` is not implemented for `W<(dyn A + 'static)>`
47-
|
48-
help: this trait has no implementations, consider adding one
49-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:6:1
50-
|
51-
LL | trait A {}
52-
| ^^^^^^^
53-
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A + Send>`
54-
55-
error[E0277]: `(dyn A + 'static)` cannot be sent between threads safely
56-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:19:5
57-
|
58-
LL | a as _
59-
| ^ `(dyn A + 'static)` cannot be sent between threads safely
60-
|
61-
= help: within `W<(dyn A + 'static)>`, the trait `Send` is not implemented for `(dyn A + 'static)`
62-
note: required because it appears within the type `W<(dyn A + 'static)>`
63-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
5+
| ^^^^^^ unsupported cast
646
|
65-
LL | struct W<T: ?Sized>(T);
66-
| ^
67-
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A + Send>`
7+
= note: this could allow UB elsewhere
8+
= help: use `transmute` if you're sure this is sound
689

69-
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
70-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:19:5
10+
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
11+
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:17:5
7112
|
7213
LL | a as _
73-
| ^ doesn't have a size known at compile-time
74-
|
75-
= help: within `W<(dyn A + 'static)>`, the trait `Sized` is not implemented for `(dyn A + 'static)`
76-
note: required because it appears within the type `W<(dyn A + 'static)>`
77-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
14+
| ^^^^^^ unsupported cast
7815
|
79-
LL | struct W<T: ?Sized>(T);
80-
| ^
81-
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A + Send>`
16+
= note: this could allow UB elsewhere
17+
= help: use `transmute` if you're sure this is sound
8218

8319
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
84-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:26:5
20+
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:22:5
8521
|
8622
LL | a as _
8723
| ^^^^^^ unsupported cast
@@ -90,7 +26,7 @@ LL | a as _
9026
= help: use `transmute` if you're sure this is sound
9127

9228
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
93-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:31:5
29+
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:27:5
9430
|
9531
LL | a as _
9632
| ^^^^^^ unsupported cast
@@ -99,15 +35,14 @@ LL | a as _
9935
= help: use `transmute` if you're sure this is sound
10036

10137
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
102-
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:36:5
38+
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:32:5
10339
|
10440
LL | a as _
10541
| ^^^^^^ unsupported cast
10642
|
10743
= note: this could allow UB elsewhere
10844
= help: use `transmute` if you're sure this is sound
10945

110-
error: aborting due to 9 previous errors
46+
error: aborting due to 5 previous errors
11147

112-
Some errors have detailed explanations: E0277, E0804.
113-
For more information about an error, try `rustc --explain E0277`.
48+
For more information about this error, try `rustc --explain E0804`.

‎tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ struct X<T: ?Sized>(T);
1010

1111
fn unwrap<F, G>(a: *const W<dyn A<F>>) -> *const dyn A<G> {
1212
a as _
13-
//~^ error
14-
//~| error
13+
//~^ error casting `*const W<(dyn A<F> + 'static)>` as `*const dyn A<G>` is invalid
1514
}
1615

1716
fn unwrap_nested<F, G>(a: *const W<W<dyn A<F>>>) -> *const W<dyn A<G>> {
1817
a as _
19-
//~^ error
20-
//~| error
18+
//~^ error casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<dyn A<G>>` is invalid
2119
}
2220

2321
fn rewrap<F, G>(a: *const W<dyn A<F>>) -> *const X<dyn A<G>> {
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,43 @@
1-
error[E0277]: the trait bound `W<(dyn A<F> + 'static)>: A<G>` is not satisfied
1+
error[E0606]: casting `*const W<(dyn A<F> + 'static)>` as `*const dyn A<G>` is invalid
22
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:12:5
33
|
44
LL | a as _
5-
| ^ the trait `A<G>` is not implemented for `W<(dyn A<F> + 'static)>`
6-
|
7-
help: this trait has no implementations, consider adding one
8-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:6:1
9-
|
10-
LL | trait A<T> {}
11-
| ^^^^^^^^^^
12-
= note: required for the cast from `*const W<(dyn A<F> + 'static)>` to `*const dyn A<G>`
13-
14-
error[E0277]: the size for values of type `(dyn A<F> + 'static)` cannot be known at compilation time
15-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:12:5
16-
|
17-
LL | a as _
18-
| ^ doesn't have a size known at compile-time
19-
|
20-
= help: within `W<(dyn A<F> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<F> + 'static)`
21-
note: required because it appears within the type `W<(dyn A<F> + 'static)>`
22-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:8:8
23-
|
24-
LL | struct W<T: ?Sized>(T);
25-
| ^
26-
= note: required for the cast from `*const W<(dyn A<F> + 'static)>` to `*const dyn A<G>`
27-
28-
error[E0277]: the trait bound `W<(dyn A<F> + 'static)>: A<G>` is not satisfied
29-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18:5
30-
|
31-
LL | a as _
32-
| ^ the trait `A<G>` is not implemented for `W<(dyn A<F> + 'static)>`
33-
|
34-
help: this trait has no implementations, consider adding one
35-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:6:1
5+
| ^^^^^^
366
|
37-
LL | trait A<T> {}
38-
| ^^^^^^^^^^
39-
= note: required for the cast from `*const W<W<(dyn A<F> + 'static)>>` to `*const W<dyn A<G>>`
7+
= note: the trait objects may have different vtables
408

41-
error[E0277]: the size for values of type `(dyn A<F> + 'static)` cannot be known at compilation time
42-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18:5
9+
error[E0606]: casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<dyn A<G>>` is invalid
10+
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:17:5
4311
|
4412
LL | a as _
45-
| ^ doesn't have a size known at compile-time
46-
|
47-
= help: within `W<(dyn A<F> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<F> + 'static)`
48-
note: required because it appears within the type `W<(dyn A<F> + 'static)>`
49-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:8:8
13+
| ^^^^^^
5014
|
51-
LL | struct W<T: ?Sized>(T);
52-
| ^
53-
= note: required for the cast from `*const W<W<(dyn A<F> + 'static)>>` to `*const W<dyn A<G>>`
15+
= note: the trait objects may have different vtables
5416

5517
error[E0606]: casting `*const W<(dyn A<F> + 'static)>` as `*const X<dyn A<G>>` is invalid
56-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:24:5
18+
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:22:5
5719
|
5820
LL | a as _
5921
| ^^^^^^
6022
|
6123
= note: the trait objects may have different vtables
6224

6325
error[E0606]: casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<X<dyn A<G>>>` is invalid
64-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:29:5
26+
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:27:5
6527
|
6628
LL | a as _
6729
| ^^^^^^
6830
|
6931
= note: the trait objects may have different vtables
7032

7133
error[E0606]: casting `*const (dyn A<F> + 'static)` as `*const W<dyn A<G>>` is invalid
72-
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:34:5
34+
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:32:5
7335
|
7436
LL | a as _
7537
| ^^^^^^
7638
|
7739
= note: the trait objects may have different vtables
7840

79-
error: aborting due to 7 previous errors
41+
error: aborting due to 5 previous errors
8042

81-
Some errors have detailed explanations: E0277, E0606.
82-
For more information about an error, try `rustc --explain E0277`.
43+
For more information about this error, try `rustc --explain E0606`.

‎tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
error[E0277]: the trait bound `W<(dyn A<'a> + 'static)>: A<'b>` is not satisfied
1+
error: lifetime may not live long enough
22
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:12:5
33
|
4+
LL | fn unwrap<'a, 'b>(a: *const W<dyn A<'a>>) -> *const dyn A<'b> {
5+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
48
LL | a as _
5-
| ^ the trait `A<'b>` is not implemented for `W<(dyn A<'a> + 'static)>`
6-
|
7-
help: this trait has no implementations, consider adding one
8-
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:6:1
9+
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
910
|
10-
LL | trait A<'a> {}
11-
| ^^^^^^^^^^^
12-
= note: required for the cast from `*const W<(dyn A<'a> + 'static)>` to `*const dyn A<'b>`
11+
= help: consider adding the following bound: `'b: 'a`
1312

14-
error[E0277]: the size for values of type `(dyn A<'a> + 'static)` cannot be known at compilation time
13+
error: lifetime may not live long enough
1514
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:12:5
1615
|
16+
LL | fn unwrap<'a, 'b>(a: *const W<dyn A<'a>>) -> *const dyn A<'b> {
17+
| -- -- lifetime `'b` defined here
18+
| |
19+
| lifetime `'a` defined here
1720
LL | a as _
18-
| ^ doesn't have a size known at compile-time
19-
|
20-
= help: within `W<(dyn A<'a> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<'a> + 'static)`
21-
note: required because it appears within the type `W<(dyn A<'a> + 'static)>`
22-
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:8:8
21+
| ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
2322
|
24-
LL | struct W<T: ?Sized>(T);
25-
| ^
26-
= note: required for the cast from `*const W<(dyn A<'a> + 'static)>` to `*const dyn A<'b>`
23+
= help: consider adding the following bound: `'a: 'b`
24+
25+
help: `'b` and `'a` must be the same: replace one with the other
2726

28-
error[E0277]: the trait bound `W<(dyn A<'a> + 'static)>: A<'b>` is not satisfied
27+
error: lifetime may not live long enough
2928
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:18:5
3029
|
30+
LL | fn unwrap_nested<'a, 'b>(a: *const W<W<dyn A<'a>>>) -> *const W<dyn A<'b>> {
31+
| -- -- lifetime `'b` defined here
32+
| |
33+
| lifetime `'a` defined here
3134
LL | a as _
32-
| ^ the trait `A<'b>` is not implemented for `W<(dyn A<'a> + 'static)>`
33-
|
34-
help: this trait has no implementations, consider adding one
35-
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:6:1
35+
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
3636
|
37-
LL | trait A<'a> {}
38-
| ^^^^^^^^^^^
39-
= note: required for the cast from `*const W<W<(dyn A<'a> + 'static)>>` to `*const W<dyn A<'b>>`
37+
= help: consider adding the following bound: `'b: 'a`
4038

41-
error[E0277]: the size for values of type `(dyn A<'a> + 'static)` cannot be known at compilation time
39+
error: lifetime may not live long enough
4240
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:18:5
4341
|
42+
LL | fn unwrap_nested<'a, 'b>(a: *const W<W<dyn A<'a>>>) -> *const W<dyn A<'b>> {
43+
| -- -- lifetime `'b` defined here
44+
| |
45+
| lifetime `'a` defined here
4446
LL | a as _
45-
| ^ doesn't have a size known at compile-time
47+
| ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
4648
|
47-
= help: within `W<(dyn A<'a> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<'a> + 'static)`
48-
note: required because it appears within the type `W<(dyn A<'a> + 'static)>`
49-
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:8:8
49+
= help: consider adding the following bound: `'a: 'b`
50+
51+
help: `'b` and `'a` must be the same: replace one with the other
5052
|
51-
LL | struct W<T: ?Sized>(T);
52-
| ^
53-
= note: required for the cast from `*const W<W<(dyn A<'a> + 'static)>>` to `*const W<dyn A<'b>>`
53+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5454

5555
error: lifetime may not live long enough
5656
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:24:5
@@ -77,6 +77,8 @@ LL | a as _
7777
= help: consider adding the following bound: `'a: 'b`
7878

7979
help: `'b` and `'a` must be the same: replace one with the other
80+
|
81+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8082

8183
error: lifetime may not live long enough
8284
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:30:5
@@ -136,4 +138,3 @@ help: `'b` and `'a` must be the same: replace one with the other
136138

137139
error: aborting due to 10 previous errors
138140

139-
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/cast/ptr-to-trait-obj-wrap.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// structure, so these casts *are* fine.
44
//
55
// `unwrap` and `unwrap_nested` currently don't work due to a compiler limitation.
6+
//@ check-pass
67

78
trait A {}
89

@@ -11,14 +12,10 @@ struct X<T: ?Sized>(T);
1112

1213
fn unwrap(a: *const W<dyn A>) -> *const dyn A {
1314
a as _
14-
//~^ error
15-
//~| error
1615
}
1716

1817
fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A> {
1918
a as _
20-
//~^ error
21-
//~| error
2219
}
2320

2421
fn rewrap(a: *const W<dyn A>) -> *const X<dyn A> {
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.