diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2022-02-22 14:54:47 -0500 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-19 12:21:45 +0000 |
| commit | 5ff331142e03bede7f9c8264b8625caf6b65989c (patch) | |
| tree | 91b68c412532abe12f3cbd4e0a47f915db4b887f /src/test | |
| parent | f0620c95038c1e586f5165d5d3be7cf009aaf387 (diff) | |
| download | rust-5ff331142e03bede7f9c8264b8625caf6b65989c.tar.gz rust-5ff331142e03bede7f9c8264b8625caf6b65989c.zip | |
Move check to existing pass
This alters the diagnostics a bit, as the trait method is still stable. The only thing this check does is ensure that compilation fails if a trait implementation is declared const-stable.
Diffstat (limited to 'src/test')
5 files changed, 36 insertions, 98 deletions
diff --git a/src/test/ui/rfc-2632-const-trait-impl/stability.rs b/src/test/ui/rfc-2632-const-trait-impl/stability.rs deleted file mode 100644 index 15f1db18f89..00000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/stability.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![feature(const_trait_impl)] -#![feature(staged_api)] -#![stable(feature = "rust1", since = "1.0.0")] - -#[stable(feature = "rust1", since = "1.0.0")] -pub struct Int(i32); - -#[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_stable(feature = "rust1", since = "1.0.0")] -impl const std::ops::Sub for Int { - //~^ ERROR trait implementations cannot be const stable yet - type Output = Self; - - fn sub(self, rhs: Self) -> Self { - Int(self.0 - rhs.0) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_add", issue = "none")] -impl const std::ops::Add for Int { - type Output = Self; - - fn add(self, rhs: Self) -> Self { - Int(self.0 + rhs.0) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_stable(feature = "rust1", since = "1.0.0")] -pub const fn const_err() { - Int(0) + Int(0); - //~^ ERROR not yet stable as a const fn - Int(0) - Int(0); -} - -#[stable(feature = "rust1", since = "1.0.0")] -pub fn non_const_success() { - Int(0) + Int(0); - Int(0) - Int(0); -} - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/stability.stderr b/src/test/ui/rfc-2632-const-trait-impl/stability.stderr deleted file mode 100644 index fa3d85a3e6a..00000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/stability.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: `<Int as Add>::add` is not yet stable as a const fn - --> $DIR/stability.rs:32:5 - | -LL | Int(0) + Int(0); - | ^^^^^^^^^^^^^^^ - | - = help: const-stable functions can only call other const-stable functions - -error: trait implementations cannot be const stable yet - --> $DIR/stability.rs:10:1 - | -LL | / impl const std::ops::Sub for Int { -LL | | -LL | | type Output = Self; -LL | | -... | -LL | | } -LL | | } - | |_^ - | - = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/rfc-2632-const-trait-impl/staged-api.rs b/src/test/ui/rfc-2632-const-trait-impl/staged-api.rs index 903ced42698..f8a55a0a4a0 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/staged-api.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/staged-api.rs @@ -11,26 +11,36 @@ extern crate staged_api; use staged_api::*; #[stable(feature = "rust1", since = "1.0.0")] -pub struct Stable; +pub struct Foo; #[stable(feature = "rust1", since = "1.0.0")] -#[cfg_attr(stable, rustc_const_stable(feature = "rust1", since = "1.0.0"))] -impl const MyTrait for Stable { +#[cfg_attr(unstable, rustc_const_unstable(feature = "foo", issue = "none"))] +impl const MyTrait for Foo { //[stable]~^ ERROR trait implementations cannot be const stable yet - //[unstable]~^^ ERROR implementation has missing const stability attribute fn func() {} } +// Const stability has no impact on usage in non-const contexts. fn non_const_context() { Unstable::func(); - Stable::func(); + Foo::func(); } #[unstable(feature = "none", issue = "none")] const fn const_context() { Unstable::func(); - //[stable]~^ ERROR `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn - Stable::func(); + // ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is + // not const-stable. + Foo::func(); + //[unstable]~^ not yet stable as a const fn +} + +#[stable(feature = "rust1", since = "1.0.0")] +const fn stable_const_context() { + Unstable::func(); + //[unstable]~^ ERROR not yet stable as a const fn + Foo::func(); + //[unstable]~^ ERROR not yet stable as a const fn } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr b/src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr index 2fde51217f5..25407a0b43c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr @@ -1,22 +1,11 @@ -error: `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn - --> $DIR/staged-api.rs:31:5 - | -LL | Unstable::func(); - | ^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(unstable)]` to the crate attributes to enable - -error: trait implementations cannot be const stable yet +error: implementation has missing const stability attribute --> $DIR/staged-api.rs:18:1 | -LL | / impl const MyTrait for Stable { -LL | | +LL | / impl const MyTrait for Foo { LL | | LL | | fn func() {} LL | | } | |_^ - | - = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr b/src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr index 4ea1be69b3b..30fe97bb884 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr @@ -1,12 +1,18 @@ -error: implementation has missing const stability attribute - --> $DIR/staged-api.rs:18:1 - | -LL | / impl const MyTrait for Stable { -LL | | -LL | | -LL | | fn func() {} -LL | | } - | |_^ +error: `<Foo as staged_api::MyTrait>::func` is not yet stable as a const fn + --> $DIR/staged-api.rs:34:5 + | +LL | Foo::func(); + | ^^^^^^^^^^^ + | + = help: add `#![feature(foo)]` to the crate attributes to enable + +error: `<Foo as staged_api::MyTrait>::func` is not yet stable as a const fn + --> $DIR/staged-api.rs:42:5 + | +LL | Foo::func(); + | ^^^^^^^^^^^ + | + = help: add `#![feature(foo)]` to the crate attributes to enable -error: aborting due to previous error +error: aborting due to 2 previous errors |
