diff options
| author | Michael Goulet <michael@errs.io> | 2025-01-08 00:28:47 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-01-08 00:28:47 +0000 |
| commit | 3c3186148e4a66a507e606f191c35ed49d873b08 (patch) | |
| tree | 9ffe97bddbaed9c6bc1b684c75dfdda1f00b0e3c /tests/ui/self | |
| parent | ad211ced81509462cdfe4c29ed10f97279a0acae (diff) | |
| download | rust-3c3186148e4a66a507e606f191c35ed49d873b08.tar.gz rust-3c3186148e4a66a507e606f191c35ed49d873b08.zip | |
Don't allow transmuting ZSTs in dispatch_from_dyn impl
Diffstat (limited to 'tests/ui/self')
| -rw-r--r-- | tests/ui/self/dispatch-from-dyn-zst-transmute.rs | 34 | ||||
| -rw-r--r-- | tests/ui/self/dispatch-from-dyn-zst-transmute.stderr | 16 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/self/dispatch-from-dyn-zst-transmute.rs b/tests/ui/self/dispatch-from-dyn-zst-transmute.rs new file mode 100644 index 00000000000..57c255b4d7b --- /dev/null +++ b/tests/ui/self/dispatch-from-dyn-zst-transmute.rs @@ -0,0 +1,34 @@ +#![feature(arbitrary_self_types)] +#![feature(unsize)] +#![feature(dispatch_from_dyn)] + +use std::marker::PhantomData; +use std::marker::Unsize; +use std::ops::DispatchFromDyn; +use std::ops::Deref; + +struct IsSendToken<T: ?Sized>(PhantomData<fn(T) -> T>); + +struct Foo<'a, U: ?Sized> { + token: IsSendToken<U>, + ptr: &'a U, +} + +impl<'a, T, U> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> +//~^ ERROR implementing the `DispatchFromDyn` trait requires multiple coercions +where + T: Unsize<U> + ?Sized, + U: ?Sized {} + +trait Bar { + fn f(self: Foo<'_, Self>); +} + +impl<U: ?Sized> Deref for Foo<'_, U> { + type Target = U; + fn deref(&self) -> &U { + self.ptr + } +} + +fn main() {} diff --git a/tests/ui/self/dispatch-from-dyn-zst-transmute.stderr b/tests/ui/self/dispatch-from-dyn-zst-transmute.stderr new file mode 100644 index 00000000000..5a8ae88b5f1 --- /dev/null +++ b/tests/ui/self/dispatch-from-dyn-zst-transmute.stderr @@ -0,0 +1,16 @@ +error[E0378]: implementing the `DispatchFromDyn` trait requires multiple coercions + --> $DIR/dispatch-from-dyn-zst-transmute.rs:17:1 + | +LL | / impl<'a, T, U> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> +LL | | +LL | | where +LL | | T: Unsize<U> + ?Sized, +LL | | U: ?Sized {} + | |_____________^ + | + = note: the trait `DispatchFromDyn` may only be implemented for a coercion between structures with a single field being coerced + = note: currently, 2 fields need coercions: `token` (`IsSendToken<T>` to `IsSendToken<U>`), `ptr` (`&'a T` to `&'a U`) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0378`. |
