forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#120269 - oli-obk:revert_trait_obj_upcast_stab…
…ilization, r=jackh726 [beta] Revert trait obj upcast stabilization backport of rust-lang#120233 note that this is not yet approved for beta backport
- Loading branch information
Showing
72 changed files
with
422 additions
and
105 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
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
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
27 changes: 27 additions & 0 deletions
27
src/doc/unstable-book/src/language-features/trait-upcasting.md
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,27 @@ | ||
# `trait_upcasting` | ||
|
||
The tracking issue for this feature is: [#65991] | ||
|
||
[#65991]: https://github.com/rust-lang/rust/issues/65991 | ||
|
||
------------------------ | ||
|
||
The `trait_upcasting` feature adds support for trait upcasting coercion. This allows a | ||
trait object of type `dyn Bar` to be cast to a trait object of type `dyn Foo` | ||
so long as `Bar: Foo`. | ||
|
||
```rust,edition2018 | ||
#![feature(trait_upcasting)] | ||
#![allow(incomplete_features)] | ||
trait Foo {} | ||
trait Bar: Foo {} | ||
impl Foo for i32 {} | ||
impl<T: Foo + ?Sized> Bar for T {} | ||
let bar: &dyn Bar = &123; | ||
let foo: &dyn Foo = bar; | ||
``` |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#![feature(trait_upcasting)] | ||
#![allow(incomplete_features)] | ||
|
||
fn main() { | ||
basic(); | ||
diamond(); | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// build-pass | ||
#![feature(trait_upcasting)] | ||
|
||
pub trait A {} | ||
pub trait B {} | ||
|
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
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 @@ | ||
trait Foo {} | ||
|
||
trait Bar: Foo {} | ||
|
||
impl Foo for () {} | ||
|
||
impl Bar for () {} | ||
|
||
fn main() { | ||
let bar: &dyn Bar = &(); | ||
let foo: &dyn Foo = bar; | ||
//~^ ERROR trait upcasting coercion is experimental [E0658] | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/feature-gates/feature-gate-trait_upcasting.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 Bar` to `dyn Foo`, trait upcasting coercion is experimental | ||
--> $DIR/feature-gate-trait_upcasting.rs:11:25 | ||
| | ||
LL | let foo: &dyn Foo = bar; | ||
| ^^^ | ||
| | ||
= 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 `&dyn Bar` into `&dyn Foo` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// compile-flags: -Znext-solver | ||
// check-pass | ||
#![feature(trait_upcasting)] | ||
|
||
trait A {} | ||
trait B: A {} | ||
|
1 change: 1 addition & 0 deletions
1
tests/ui/traits/next-solver/trait-upcast-lhs-needs-normalization.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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// check-pass | ||
// compile-flags: -Znext-solver | ||
#![feature(trait_upcasting)] | ||
|
||
pub trait A {} | ||
pub trait B: A {} | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// compile-flags: -Znext-solver | ||
// check-pass | ||
#![feature(trait_upcasting)] | ||
|
||
trait Foo: Bar<i32> + Bar<u32> {} | ||
|
||
|
1 change: 1 addition & 0 deletions
1
tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.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
2 changes: 1 addition & 1 deletion
2
tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.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
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
1 change: 1 addition & 0 deletions
1
tests/ui/traits/trait-upcasting/correct-supertrait-substitution.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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.