Skip to content

Commit

Permalink
bless tests
Browse files Browse the repository at this point in the history
yay, I fixed the bug/missing feature :')
  • Loading branch information
WaffleLapkin committed Mar 8, 2025
1 parent b62d58f commit 80157a5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 235 deletions.
8 changes: 2 additions & 6 deletions tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ struct X<T: ?Sized>(T);

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

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

fn rewrap(a: *const W<dyn A>) -> *const X<dyn A + Send> {
Expand Down
93 changes: 14 additions & 79 deletions tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr
Original file line number Diff line number Diff line change
@@ -1,87 +1,23 @@
error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5
|
LL | a as _
| ^ the trait `A` is not implemented for `W<(dyn A + 'static)>`
|
help: this trait has no implementations, consider adding one
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:6:1
|
LL | trait A {}
| ^^^^^^^
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A + Send`

error[E0277]: `(dyn A + 'static)` cannot be sent between threads safely
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5
|
LL | a as _
| ^ `(dyn A + 'static)` cannot be sent between threads safely
|
= help: within `W<(dyn A + 'static)>`, the trait `Send` is not implemented for `(dyn A + 'static)`
note: required because it appears within the type `W<(dyn A + 'static)>`
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
|
LL | struct W<T: ?Sized>(T);
| ^
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A + Send`

error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5
|
LL | a as _
| ^ doesn't have a size known at compile-time
|
= help: within `W<(dyn A + 'static)>`, the trait `Sized` is not implemented for `(dyn A + 'static)`
note: required because it appears within the type `W<(dyn A + 'static)>`
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
|
LL | struct W<T: ?Sized>(T);
| ^
= note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A + Send`

error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:19:5
|
LL | a as _
| ^ the trait `A` is not implemented for `W<(dyn A + 'static)>`
|
help: this trait has no implementations, consider adding one
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:6:1
|
LL | trait A {}
| ^^^^^^^
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A + Send>`

error[E0277]: `(dyn A + 'static)` cannot be sent between threads safely
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:19:5
|
LL | a as _
| ^ `(dyn A + 'static)` cannot be sent between threads safely
|
= help: within `W<(dyn A + 'static)>`, the trait `Send` is not implemented for `(dyn A + 'static)`
note: required because it appears within the type `W<(dyn A + 'static)>`
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:8:8
| ^^^^^^ unsupported cast
|
LL | struct W<T: ?Sized>(T);
| ^
= note: required for the cast from `*const W<W<(dyn A + 'static)>>` to `*const W<dyn A + Send>`
= note: this could allow UB elsewhere
= help: use `transmute` if you're sure this is sound

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

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

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

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

error: aborting due to 9 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0277, E0804.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0804`.
6 changes: 2 additions & 4 deletions tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ struct X<T: ?Sized>(T);

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

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

fn rewrap<F, G>(a: *const W<dyn A<F>>) -> *const X<dyn A<G>> {
Expand Down
63 changes: 12 additions & 51 deletions tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr
Original file line number Diff line number Diff line change
@@ -1,82 +1,43 @@
error[E0277]: the trait bound `W<(dyn A<F> + 'static)>: A<G>` is not satisfied
error[E0606]: casting `*const W<(dyn A<F> + 'static)>` as `*const dyn A<G>` is invalid
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:12:5
|
LL | a as _
| ^ the trait `A<G>` is not implemented for `W<(dyn A<F> + 'static)>`
|
help: this trait has no implementations, consider adding one
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:6:1
|
LL | trait A<T> {}
| ^^^^^^^^^^
= note: required for the cast from `*const W<(dyn A<F> + 'static)>` to `*const dyn A<G>`

error[E0277]: the size for values of type `(dyn A<F> + 'static)` cannot be known at compilation time
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:12:5
|
LL | a as _
| ^ doesn't have a size known at compile-time
|
= help: within `W<(dyn A<F> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<F> + 'static)`
note: required because it appears within the type `W<(dyn A<F> + 'static)>`
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:8:8
|
LL | struct W<T: ?Sized>(T);
| ^
= note: required for the cast from `*const W<(dyn A<F> + 'static)>` to `*const dyn A<G>`

error[E0277]: the trait bound `W<(dyn A<F> + 'static)>: A<G>` is not satisfied
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18:5
|
LL | a as _
| ^ the trait `A<G>` is not implemented for `W<(dyn A<F> + 'static)>`
|
help: this trait has no implementations, consider adding one
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:6:1
| ^^^^^^
|
LL | trait A<T> {}
| ^^^^^^^^^^
= note: required for the cast from `*const W<W<(dyn A<F> + 'static)>>` to `*const W<dyn A<G>>`
= note: the trait objects may have different vtables

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

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

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

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

error: aborting due to 7 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0277, E0606.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0606`.
69 changes: 35 additions & 34 deletions tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
error[E0277]: the trait bound `W<(dyn A<'a> + 'static)>: A<'b>` is not satisfied
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:12:5
|
LL | fn unwrap<'a, 'b>(a: *const W<dyn A<'a>>) -> *const dyn A<'b> {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | a as _
| ^ the trait `A<'b>` is not implemented for `W<(dyn A<'a> + 'static)>`
|
help: this trait has no implementations, consider adding one
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:6:1
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
|
LL | trait A<'a> {}
| ^^^^^^^^^^^
= note: required for the cast from `*const W<(dyn A<'a> + 'static)>` to `*const dyn A<'b>`
= help: consider adding the following bound: `'b: 'a`

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

help: `'b` and `'a` must be the same: replace one with the other

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

error[E0277]: the size for values of type `(dyn A<'a> + 'static)` cannot be known at compilation time
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:18:5
|
LL | fn unwrap_nested<'a, 'b>(a: *const W<W<dyn A<'a>>>) -> *const W<dyn A<'b>> {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | a as _
| ^ doesn't have a size known at compile-time
| ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
|
= help: within `W<(dyn A<'a> + 'static)>`, the trait `Sized` is not implemented for `(dyn A<'a> + 'static)`
note: required because it appears within the type `W<(dyn A<'a> + 'static)>`
--> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:8:8
= help: consider adding the following bound: `'a: 'b`

help: `'b` and `'a` must be the same: replace one with the other
|
LL | struct W<T: ?Sized>(T);
| ^
= note: required for the cast from `*const W<W<(dyn A<'a> + 'static)>>` to `*const W<dyn A<'b>>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

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

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

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

error: aborting due to 10 previous errors

For more information about this error, try `rustc --explain E0277`.
5 changes: 1 addition & 4 deletions tests/ui/cast/ptr-to-trait-obj-wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// structure, so these casts *are* fine.
//
// `unwrap` and `unwrap_nested` currently don't work due to a compiler limitation.
//@ check-pass

trait A {}

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

fn unwrap(a: *const W<dyn A>) -> *const dyn A {
a as _
//~^ error
//~| error
}

fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A> {
a as _
//~^ error
//~| error
}

fn rewrap(a: *const W<dyn A>) -> *const X<dyn A> {
Expand Down
Loading

0 comments on commit 80157a5

Please sign in to comment.