-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect trait upcasting through struct tail unsizing
- Loading branch information
1 parent
b6dd153
commit 752e6e1
Showing
4 changed files
with
60 additions
and
5 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
13 changes: 13 additions & 0 deletions
13
tests/ui/traits/trait-upcasting/upcast-through-struct-tail.current.stderr
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,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`. |
13 changes: 13 additions & 0 deletions
13
tests/ui/traits/trait-upcasting/upcast-through-struct-tail.next.stderr
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,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`. |
14 changes: 14 additions & 0 deletions
14
tests/ui/traits/trait-upcasting/upcast-through-struct-tail.rs
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,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() {} |