diff options
| author | Michael Goulet <michael@errs.io> | 2023-07-29 01:04:04 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-07-29 06:40:36 +0000 |
| commit | 752e6e13adacd499049985ad9c5f7f4d08b78261 (patch) | |
| tree | 3fa11bbc7ed69ddc509cf117b453f7ceba3d0a3d /tests | |
| parent | b6dd153fbcc06b3bc936aca800af4b8376c229e4 (diff) | |
| download | rust-752e6e13adacd499049985ad9c5f7f4d08b78261.tar.gz rust-752e6e13adacd499049985ad9c5f7f4d08b78261.zip | |
Detect trait upcasting through struct tail unsizing
Diffstat (limited to 'tests')
3 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.current.stderr b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.current.stderr new file mode 100644 index 00000000000..9f0993d65a7 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.current.stderr @@ -0,0 +1,13 @@ +error[E0658]: cannot cast `dyn A` to `dyn B`, trait upcasting coercion is experimental + --> $DIR/upcast-through-struct-tail.rs:10:5 + | +LL | x + | ^ + | + = note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information + = help: add `#![feature(trait_upcasting)]` to the crate attributes to enable + = note: required when coercing `Box<Wrapper<(dyn A + 'a)>>` into `Box<Wrapper<(dyn B + 'a)>>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.next.stderr b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.next.stderr new file mode 100644 index 00000000000..9f0993d65a7 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.next.stderr @@ -0,0 +1,13 @@ +error[E0658]: cannot cast `dyn A` to `dyn B`, trait upcasting coercion is experimental + --> $DIR/upcast-through-struct-tail.rs:10:5 + | +LL | x + | ^ + | + = note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information + = help: add `#![feature(trait_upcasting)]` to the crate attributes to enable + = note: required when coercing `Box<Wrapper<(dyn A + 'a)>>` into `Box<Wrapper<(dyn B + 'a)>>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.rs b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.rs new file mode 100644 index 00000000000..42495f45f8a --- /dev/null +++ b/tests/ui/traits/trait-upcasting/upcast-through-struct-tail.rs @@ -0,0 +1,14 @@ +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +struct Wrapper<T: ?Sized>(T); + +trait A: B {} +trait B {} + +fn test<'a>(x: Box<Wrapper<dyn A + 'a>>) -> Box<Wrapper<dyn B + 'a>> { + x + //~^ ERROR cannot cast `dyn A` to `dyn B`, trait upcasting coercion is experimental +} + +fn main() {} |
