From 5712d2e956e592bc4184e9c28cda9cfb5975a3db Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Thu, 16 Jan 2025 16:12:27 +0100 Subject: [PATCH 1/3] add a test for pointer casts involving un/re/wrapping trait objects the errors should not be there, this is a bug/missing feature. --- .../ui/cast/ptr-to-trait-obj-wrap-add-auto.rs | 40 +++++ .../ptr-to-trait-obj-wrap-add-auto.stderr | 113 ++++++++++++++ .../ptr-to-trait-obj-wrap-different-args.rs | 38 +++++ ...tr-to-trait-obj-wrap-different-args.stderr | 82 +++++++++++ ...ptr-to-trait-obj-wrap-different-regions.rs | 41 ++++++ ...to-trait-obj-wrap-different-regions.stderr | 139 ++++++++++++++++++ tests/ui/cast/ptr-to-trait-obj-wrap.rs | 36 +++++ tests/ui/cast/ptr-to-trait-obj-wrap.stderr | 57 +++++++ 8 files changed, 546 insertions(+) create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.rs create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap.rs create mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap.stderr diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs new file mode 100644 index 0000000000000..2e5a9d0d3b584 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs @@ -0,0 +1,40 @@ +// Combination of `ptr-to-trait-obj-wrap.rs` and `ptr-to-trait-obj-add-auto.rs`. +// +// Checks that you *can't* add auto traits to trait object in pointer casts involving wrapping said +// traits structures. + +trait A {} + +struct W(T); +struct X(T); + +fn unwrap(a: *const W) -> *const (dyn A + Send) { + a as _ + //~^ error + //~| error + //~| error +} + +fn unwrap_nested(a: *const W>) -> *const W { + a as _ + //~^ error + //~| error + //~| error +} + +fn rewrap(a: *const W) -> *const X { + a as _ + //~^ error: cannot add auto trait `Send` to dyn bound via pointer cast +} + +fn rewrap_nested(a: *const W>) -> *const W> { + a as _ + //~^ error: cannot add auto trait `Send` to dyn bound via pointer cast +} + +fn wrap(a: *const dyn A) -> *const W { + a as _ + //~^ error: cannot add auto trait `Send` to dyn bound via pointer cast +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr new file mode 100644 index 0000000000000..00a27156f0773 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr @@ -0,0 +1,113 @@ +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); + | ^ + = 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 + --> $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); + | ^ + = 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>` to `*const W` + +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 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W>` to `*const W` + +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 + | +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); + | ^ + = note: required for the cast from `*const W>` to `*const W` + +error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast + --> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:26:5 + | +LL | a as _ + | ^^^^^^ unsupported cast + | + = 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:31:5 + | +LL | a as _ + | ^^^^^^ unsupported cast + | + = 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:36: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 + +Some errors have detailed explanations: E0277, E0804. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs new file mode 100644 index 0000000000000..55dc0aa184da1 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs @@ -0,0 +1,38 @@ +// Combination of `ptr-to-trait-obj-different-args.rs` and `ptr-to-trait-obj-wrap.rs`. +// +// Checks that you *can't* change type arguments of trait objects in pointer casts involving +// wrapping said traits structures. + +trait A {} + +struct W(T); +struct X(T); + +fn unwrap(a: *const W>) -> *const dyn A { + a as _ + //~^ error + //~| error +} + +fn unwrap_nested(a: *const W>>) -> *const W> { + a as _ + //~^ error + //~| error +} + +fn rewrap(a: *const W>) -> *const X> { + a as _ + //~^ error: casting `*const W<(dyn A + 'static)>` as `*const X>` is invalid +} + +fn rewrap_nested(a: *const W>>) -> *const W>> { + a as _ + //~^ error: casting `*const W + 'static)>>` as `*const W>>` is invalid +} + +fn wrap(a: *const dyn A) -> *const W> { + a as _ + //~^ error: casting `*const (dyn A + 'static)` as `*const W>` is invalid +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr new file mode 100644 index 0000000000000..59543229de7f3 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr @@ -0,0 +1,82 @@ +error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap-different-args.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-different-args.rs:6:1 + | +LL | trait A {} + | ^^^^^^^^^^ + = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` + +error[E0277]: the size for values of type `(dyn A + '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 + '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-different-args.rs:8:8 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` + +error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18: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-different-args.rs:6:1 + | +LL | trait A {} + | ^^^^^^^^^^ + = note: required for the cast from `*const W + 'static)>>` to `*const W>` + +error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time + --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18: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-different-args.rs:8:8 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W + 'static)>>` to `*const W>` + +error[E0606]: casting `*const W<(dyn A + 'static)>` as `*const X>` is invalid + --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:24:5 + | +LL | a as _ + | ^^^^^^ + | + = note: the trait objects may have different vtables + +error[E0606]: casting `*const W + 'static)>>` as `*const W>>` is invalid + --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:29:5 + | +LL | a as _ + | ^^^^^^ + | + = note: the trait objects may have different vtables + +error[E0606]: casting `*const (dyn A + 'static)` as `*const W>` is invalid + --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:34:5 + | +LL | a as _ + | ^^^^^^ + | + = note: the trait objects may have different vtables + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0277, E0606. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.rs new file mode 100644 index 0000000000000..b0941277d01d3 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.rs @@ -0,0 +1,41 @@ +// Combination of `ptr-to-trait-obj-different-regions-misc.rs` and `ptr-to-trait-obj-wrap.rs`. +// +// Checks that you *can't* change lifetime arguments of trait objects in pointer casts involving +// wrapping said traits structures. + +trait A<'a> {} + +struct W(T); +struct X(T); + +fn unwrap<'a, 'b>(a: *const W>) -> *const dyn A<'b> { + a as _ + //~^ error + //~| error +} + +fn unwrap_nested<'a, 'b>(a: *const W>>) -> *const W> { + a as _ + //~^ error + //~| error +} + +fn rewrap<'a, 'b>(a: *const W>) -> *const X> { + a as _ + //~^ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + +fn rewrap_nested<'a, 'b>(a: *const W>>) -> *const W>> { + a as _ + //~^ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + +fn wrap<'a, 'b>(a: *const dyn A<'a>) -> *const W> { + a as _ + //~^ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr new file mode 100644 index 0000000000000..3d5fafea2eefe --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr @@ -0,0 +1,139 @@ +error[E0277]: the trait bound `W<(dyn A<'a> + 'static)>: A<'b>` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:12:5 + | +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 + | +LL | trait A<'a> {} + | ^^^^^^^^^^^ + = note: required for the cast from `*const W<(dyn A<'a> + 'static)>` to `*const dyn A<'b>` + +error[E0277]: the size for values of type `(dyn A<'a> + 'static)` cannot be known at compilation time + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:12:5 + | +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 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W<(dyn A<'a> + 'static)>` to `*const dyn A<'b>` + +error[E0277]: the trait bound `W<(dyn A<'a> + 'static)>: A<'b>` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:18:5 + | +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 + | +LL | trait A<'a> {} + | ^^^^^^^^^^^ + = note: required for the cast from `*const W + 'static)>>` to `*const W>` + +error[E0277]: the size for values of type `(dyn A<'a> + 'static)` cannot be known at compilation time + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:18:5 + | +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 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W + 'static)>>` to `*const W>` + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:24:5 + | +LL | fn rewrap<'a, 'b>(a: *const W>) -> *const X> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:24:5 + | +LL | fn rewrap<'a, 'b>(a: *const W>) -> *const X> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + +help: `'b` and `'a` must be the same: replace one with the other + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:30:5 + | +LL | fn rewrap_nested<'a, 'b>(a: *const W>>) -> *const W>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:30:5 + | +LL | fn rewrap_nested<'a, 'b>(a: *const W>>) -> *const W>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = 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:36:5 + | +LL | fn wrap<'a, 'b>(a: *const dyn A<'a>) -> *const W> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-wrap-different-regions.rs:36:5 + | +LL | fn wrap<'a, 'b>(a: *const dyn A<'a>) -> *const W> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | a as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = 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: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap.rs b/tests/ui/cast/ptr-to-trait-obj-wrap.rs new file mode 100644 index 0000000000000..f45cedcab7285 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap.rs @@ -0,0 +1,36 @@ +// Checks that various casts of pointers to trait objects wrapped in structures +// work. Note that the metadata doesn't change when a DST is wrapped in a +// structure, so these casts *are* fine. +// +// `unwrap` and `unwrap_nested` currently don't work due to a compiler limitation. + +trait A {} + +struct W(T); +struct X(T); + +fn unwrap(a: *const W) -> *const dyn A { + a as _ + //~^ error + //~| error +} + +fn unwrap_nested(a: *const W>) -> *const W { + a as _ + //~^ error + //~| error +} + +fn rewrap(a: *const W) -> *const X { + a as _ +} + +fn rewrap_nested(a: *const W>) -> *const W> { + a as _ +} + +fn wrap(a: *const dyn A) -> *const W { + a as _ +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap.stderr new file mode 100644 index 0000000000000..3003363c04aba --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap.stderr @@ -0,0 +1,57 @@ +error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap.rs:13: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.rs:7:1 + | +LL | trait A {} + | ^^^^^^^ + = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` + +error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time + --> $DIR/ptr-to-trait-obj-wrap.rs:13: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.rs:9:8 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` + +error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied + --> $DIR/ptr-to-trait-obj-wrap.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.rs:7:1 + | +LL | trait A {} + | ^^^^^^^ + = note: required for the cast from `*const W>` to `*const W` + +error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time + --> $DIR/ptr-to-trait-obj-wrap.rs:19: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.rs:9:8 + | +LL | struct W(T); + | ^ + = note: required for the cast from `*const W>` to `*const W` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. From b62d58f5415032291863d6b20654e86fcb7c4aea Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Thu, 16 Jan 2025 14:24:35 +0100 Subject: [PATCH 2/3] check that `UnsizeCoerce` may hold before trying unsizing coercion this prevents us from trying unsizing coercion in cases like `*const W` -> `*const dyn T`, where it would later cause a compilation error since `W: Sized` and `W: T` do not hold. --- compiler/rustc_hir_typeck/src/coercion.rs | 68 ++++++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 67419fdf1c3e5..d7b5c1ed5e15b 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -41,8 +41,8 @@ use rustc_abi::ExternAbi; use rustc_attr_parsing::InlineAttr; use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, struct_span_code_err}; -use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::{self as hir, LangItem}; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer::relate::RelateResult; use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult}; @@ -56,7 +56,7 @@ use rustc_middle::ty::adjustment::{ }; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::visit::TypeVisitableExt; -use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt}; +use rustc_middle::ty::{self, AliasTy, GenericArgsRef, Ty, TyCtxt}; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span}; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; @@ -593,6 +593,63 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // Create an obligation for `Source: CoerceUnsized`. let cause = self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target }); + let root_obligation = Obligation::new( + self.tcx, + cause.clone(), + self.fcx.param_env, + ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]), + ); + + // If the root `Source: CoerceUnsized` obligation can't possibly hold, + // we don't have to assume that this is unsizing coercion (it will always lead to an error) + // + // However, we don't want to bail early all the time, since the unholdable obligations + // may be interesting for diagnostics (such as trying to coerce `&T` to `&dyn Id`), + // so we only bail if there (likely) is another way to convert the types. + if !self.infcx.predicate_may_hold(&root_obligation) { + if let Some(dyn_metadata_adt_def_id) = self.tcx.lang_items().get(LangItem::DynMetadata) + && let Some(metadata_type_def_id) = self.tcx.lang_items().get(LangItem::Metadata) + { + self.probe(|_| { + let ocx = ObligationCtxt::new(&self.infcx); + + // returns `true` if `::Metadata` is `DynMetadata<_>` + let has_dyn_trait_metadata = |ty| { + let metadata_ty: Result<_, _> = ocx.structurally_normalize_ty( + &ObligationCause::dummy(), + self.fcx.param_env, + Ty::new_alias( + self.tcx, + ty::AliasTyKind::Projection, + AliasTy::new(self.tcx, metadata_type_def_id, [ty]), + ), + ); + + metadata_ty.is_ok_and(|metadata_ty| { + metadata_ty + .ty_adt_def() + .is_some_and(|d| d.did() == dyn_metadata_adt_def_id) + }) + }; + + // If both types are raw pointers to a (wrapper over a) trait object, + // this might be a cast like `*const W -> *const dyn Trait`. + // So it's better to bail and try that. (even if the cast is not possible, for + // example due to vtables not matching, cast diagnostic will likely still be better) + // + // N.B. use `target`, not `coerce_target` (the latter is a var) + if let &ty::RawPtr(source_pointee, _) = coerce_source.kind() + && let &ty::RawPtr(target_pointee, _) = target.kind() + && has_dyn_trait_metadata(source_pointee) + && has_dyn_trait_metadata(target_pointee) + { + return Err(TypeError::Mismatch); + } + + Ok(()) + })?; + } + } // Use a FIFO queue for this custom fulfillment procedure. // @@ -601,12 +658,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // and almost never more than 3. By using a SmallVec we avoid an // allocation, at the (very small) cost of (occasionally) having to // shift subsequent elements down when removing the front element. - let mut queue: SmallVec<[PredicateObligation<'tcx>; 4]> = smallvec![Obligation::new( - self.tcx, - cause, - self.fcx.param_env, - ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]) - )]; + let mut queue: SmallVec<[PredicateObligation<'tcx>; 4]> = smallvec![root_obligation]; // Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid // emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where From 80157a560f3b139e0209d358ef275a84bccd99ed Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Fri, 17 Jan 2025 14:57:22 +0100 Subject: [PATCH 3/3] bless tests yay, I fixed the bug/missing feature :') --- .../ui/cast/ptr-to-trait-obj-wrap-add-auto.rs | 8 +- .../ptr-to-trait-obj-wrap-add-auto.stderr | 93 +++---------------- .../ptr-to-trait-obj-wrap-different-args.rs | 6 +- ...tr-to-trait-obj-wrap-different-args.stderr | 63 +++---------- ...to-trait-obj-wrap-different-regions.stderr | 69 +++++++------- tests/ui/cast/ptr-to-trait-obj-wrap.rs | 5 +- tests/ui/cast/ptr-to-trait-obj-wrap.stderr | 57 ------------ 7 files changed, 66 insertions(+), 235 deletions(-) delete mode 100644 tests/ui/cast/ptr-to-trait-obj-wrap.stderr diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs index 2e5a9d0d3b584..cfc0a97989dc1 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.rs @@ -10,16 +10,12 @@ struct X(T); fn unwrap(a: *const W) -> *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>) -> *const W { a as _ - //~^ error - //~| error - //~| error + //~^ error: cannot add auto trait `Send` to dyn bound via pointer cast } fn rewrap(a: *const W) -> *const X { diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr index 00a27156f0773..42cdbc34ee827 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-add-auto.stderr @@ -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); - | ^ - = 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); - | ^ - = 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>` to `*const W` - -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); - | ^ - = note: required for the cast from `*const W>` to `*const W` + = 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); - | ^ - = note: required for the cast from `*const W>` to `*const W` + = 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 @@ -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 @@ -99,7 +35,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:36:5 + --> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:32:5 | LL | a as _ | ^^^^^^ unsupported cast @@ -107,7 +43,6 @@ LL | a as _ = 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`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs index 55dc0aa184da1..ebe7a06a7a158 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.rs @@ -10,14 +10,12 @@ struct X(T); fn unwrap(a: *const W>) -> *const dyn A { a as _ - //~^ error - //~| error + //~^ error casting `*const W<(dyn A + 'static)>` as `*const dyn A` is invalid } fn unwrap_nested(a: *const W>>) -> *const W> { a as _ - //~^ error - //~| error + //~^ error casting `*const W + 'static)>>` as `*const W>` is invalid } fn rewrap(a: *const W>) -> *const X> { diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr index 59543229de7f3..4f85b208d05ac 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-args.stderr @@ -1,59 +1,21 @@ -error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied +error[E0606]: casting `*const W<(dyn A + 'static)>` as `*const dyn A` is invalid --> $DIR/ptr-to-trait-obj-wrap-different-args.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-different-args.rs:6:1 - | -LL | trait A {} - | ^^^^^^^^^^ - = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` - -error[E0277]: the size for values of type `(dyn A + '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 + '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-different-args.rs:8:8 - | -LL | struct W(T); - | ^ - = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` - -error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied - --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18: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-different-args.rs:6:1 + | ^^^^^^ | -LL | trait A {} - | ^^^^^^^^^^ - = note: required for the cast from `*const W + 'static)>>` to `*const W>` + = note: the trait objects may have different vtables -error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/ptr-to-trait-obj-wrap-different-args.rs:18:5 +error[E0606]: casting `*const W + 'static)>>` as `*const W>` 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 + '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-different-args.rs:8:8 + | ^^^^^^ | -LL | struct W(T); - | ^ - = note: required for the cast from `*const W + 'static)>>` to `*const W>` + = note: the trait objects may have different vtables error[E0606]: casting `*const W<(dyn A + 'static)>` as `*const X>` 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 _ | ^^^^^^ @@ -61,7 +23,7 @@ LL | a as _ = note: the trait objects may have different vtables error[E0606]: casting `*const W + 'static)>>` as `*const W>>` 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 _ | ^^^^^^ @@ -69,14 +31,13 @@ LL | a as _ = note: the trait objects may have different vtables error[E0606]: casting `*const (dyn A + 'static)` as `*const W>` 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`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr index 3d5fafea2eefe..17a0ca3c34fc8 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-different-regions.stderr @@ -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>) -> *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>) -> *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); - | ^ - = 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>>) -> *const W> { + | -- -- 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 + 'static)>>` to `*const W>` + = 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>>) -> *const W> { + | -- -- 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); - | ^ - = note: required for the cast from `*const W + 'static)>>` to `*const W>` + = 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 @@ -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 @@ -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`. diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap.rs b/tests/ui/cast/ptr-to-trait-obj-wrap.rs index f45cedcab7285..6f9f6bddb996b 100644 --- a/tests/ui/cast/ptr-to-trait-obj-wrap.rs +++ b/tests/ui/cast/ptr-to-trait-obj-wrap.rs @@ -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 {} @@ -11,14 +12,10 @@ struct X(T); fn unwrap(a: *const W) -> *const dyn A { a as _ - //~^ error - //~| error } fn unwrap_nested(a: *const W>) -> *const W { a as _ - //~^ error - //~| error } fn rewrap(a: *const W) -> *const X { diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap.stderr deleted file mode 100644 index 3003363c04aba..0000000000000 --- a/tests/ui/cast/ptr-to-trait-obj-wrap.stderr +++ /dev/null @@ -1,57 +0,0 @@ -error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied - --> $DIR/ptr-to-trait-obj-wrap.rs:13: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.rs:7:1 - | -LL | trait A {} - | ^^^^^^^ - = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` - -error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/ptr-to-trait-obj-wrap.rs:13: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.rs:9:8 - | -LL | struct W(T); - | ^ - = note: required for the cast from `*const W<(dyn A + 'static)>` to `*const dyn A` - -error[E0277]: the trait bound `W<(dyn A + 'static)>: A` is not satisfied - --> $DIR/ptr-to-trait-obj-wrap.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.rs:7:1 - | -LL | trait A {} - | ^^^^^^^ - = note: required for the cast from `*const W>` to `*const W` - -error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/ptr-to-trait-obj-wrap.rs:19: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.rs:9:8 - | -LL | struct W(T); - | ^ - = note: required for the cast from `*const W>` to `*const W` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0277`.