From ac354cf5ced544e7e7c74f67ea5fd82d5b501aed Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sun, 13 Jun 2021 18:42:11 +0800 Subject: [PATCH] Add feature gate tests. --- compiler/rustc_feature/src/active.rs | 2 +- .../feature-gates/feature-gate-trait_upcasting.rs | 13 +++++++++++++ .../feature-gate-trait_upcasting.stderr | 12 ++++++++++++ src/test/ui/issues/issue-11515.rs | 2 +- src/test/ui/issues/issue-11515.stderr | 10 +++++----- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-trait_upcasting.rs create mode 100644 src/test/ui/feature-gates/feature-gate-trait_upcasting.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 138770647479..638330c904d7 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -685,7 +685,7 @@ declare_features! ( /// Allows upcasting trait objects via supertraits. /// Trait upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`. - (active, trait_upcasting, "1.56.0", Some(65991), None), + (incomplete, trait_upcasting, "1.56.0", Some(65991), None), // ------------------------------------------------------------------------- // feature-group-end: actual feature gates diff --git a/src/test/ui/feature-gates/feature-gate-trait_upcasting.rs b/src/test/ui/feature-gates/feature-gate-trait_upcasting.rs new file mode 100644 index 000000000000..0b702ab99fdc --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-trait_upcasting.rs @@ -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 is experimental [E0658] +} diff --git a/src/test/ui/feature-gates/feature-gate-trait_upcasting.stderr b/src/test/ui/feature-gates/feature-gate-trait_upcasting.stderr new file mode 100644 index 000000000000..fa273926fbdf --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-trait_upcasting.stderr @@ -0,0 +1,12 @@ +error[E0658]: trait upcasting is experimental + --> $DIR/feature-gate-trait_upcasting.rs:11:25 + | +LL | let foo: &dyn Foo = bar; + | ^^^ + | + = note: see issue #65991 for more information + = help: add `#![feature(trait_upcasting)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/issues/issue-11515.rs b/src/test/ui/issues/issue-11515.rs index a7671b9282a9..46a11002e516 100644 --- a/src/test/ui/issues/issue-11515.rs +++ b/src/test/ui/issues/issue-11515.rs @@ -6,5 +6,5 @@ struct Test { fn main() { let closure: Box = Box::new(|| ()); - let test = box Test { func: closure }; //~ ERROR mismatched types + let test = box Test { func: closure }; //~ ERROR trait upcasting is experimental [E0658] } diff --git a/src/test/ui/issues/issue-11515.stderr b/src/test/ui/issues/issue-11515.stderr index 7935615ad7e5..708e31641177 100644 --- a/src/test/ui/issues/issue-11515.stderr +++ b/src/test/ui/issues/issue-11515.stderr @@ -1,12 +1,12 @@ -error[E0308]: mismatched types +error[E0658]: trait upcasting is experimental --> $DIR/issue-11515.rs:9:33 | LL | let test = box Test { func: closure }; - | ^^^^^^^ expected trait `FnMut`, found trait `Fn` + | ^^^^^^^ | - = note: expected struct `Box<(dyn FnMut() + 'static)>` - found struct `Box<(dyn Fn() + 'static)>` + = note: see issue #65991 for more information + = help: add `#![feature(trait_upcasting)]` to the crate attributes to enable error: aborting due to previous error -For more information about this error, try `rustc --explain E0308`. +For more information about this error, try `rustc --explain E0658`.