forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arbitrary self types v2: avoid dyn, generic ICE
Bug rust-lang#57276 (and several duplicates) is an ICE which occurs when a generic type is used as a receiver which implements both Receiver and DispatchFromDyn. This change proposes to detect this error condition and turn it into a regular error rather than an ICE. Future changes could liberalise things here. As this same code path currently produces an ICE, this seems to be strictly better, and it seems defensible to inform the user that their excessively generic type is not dyn-safe. This is somewhat related to the stabilization of arbitrary self types in PR rust-lang#135881, tracked in rust-lang#44874.
- Loading branch information
Showing
6 changed files
with
61 additions
and
26 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
#![feature(arbitrary_self_types, dispatch_from_dyn)] | ||
|
||
use std::ops::{Deref, DispatchFromDyn}; | ||
|
||
trait Trait<T: Deref<Target=Self> + DispatchFromDyn<T>> { | ||
fn foo(self: T) -> dyn Trait<T>; | ||
//~^ ERROR: associated item referring to unboxed trait object for its own trait | ||
//~| ERROR: the trait `Trait` is not dyn compatible | ||
} | ||
|
||
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,26 @@ | ||
error: associated item referring to unboxed trait object for its own trait | ||
--> $DIR/dispatch-from-dyn-layout.rs:6:24 | ||
| | ||
LL | trait Trait<T: Deref<Target=Self> + DispatchFromDyn<T>> { | ||
| ----- in this trait | ||
LL | fn foo(self: T) -> dyn Trait<T>; | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: you might have meant to use `Self` to refer to the implementing type | ||
| | ||
LL | fn foo(self: T) -> Self; | ||
| ~~~~ | ||
|
||
error[E0038]: the trait `Trait` is not dyn compatible | ||
--> $DIR/dispatch-from-dyn-layout.rs:6:24 | ||
| | ||
LL | fn foo(self: T) -> dyn Trait<T>; | ||
| ^^^^^^^^^^^^ `Trait` is not dyn compatible | ||
| | ||
= note: the trait is not dyn compatible because it is too generic to determine type layout | ||
= note: for a trait to be dyn compatible it needs to allow building a vtable | ||
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |