-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow transmuting ZSTs in dispatch_from_dyn impl
- Loading branch information
1 parent
ad211ce
commit 3c31861
Showing
5 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |