From f9c4f2b7ad431c6658682724a057b4a36920fdb4 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 19 May 2022 14:48:39 +0000 Subject: [PATCH] Fix up tests --- .../staged-api-user-crate.rs | 16 +++++++++++ .../staged-api-user-crate.stderr | 11 ++++++++ .../rfc-2632-const-trait-impl/staged-api.rs | 18 +++++++++++- .../staged-api.stable.stderr | 14 +++++++++- .../staged-api.unstable.stderr | 28 +++++++++++++++++-- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.stderr diff --git a/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.rs b/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.rs new file mode 100644 index 0000000000000..fc0d82727b553 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.rs @@ -0,0 +1,16 @@ +// aux-build: staged-api.rs +extern crate staged_api; + +use staged_api::*; + +// Const stability has no impact on usage in non-const contexts. +fn non_const_context() { + Unstable::func(); +} + +const fn stable_const_context() { + Unstable::func(); + //~^ ERROR cannot call non-const fn `::func` in constant functions +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.stderr b/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.stderr new file mode 100644 index 0000000000000..61f9840e0d0a0 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.stderr @@ -0,0 +1,11 @@ +error[E0015]: cannot call non-const fn `::func` in constant functions + --> $DIR/staged-api-user-crate.rs:12:5 + | +LL | Unstable::func(); + | ^^^^^^^^^^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`. 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 a521e986babf0..1d79f5adf93f3 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 @@ -33,15 +33,31 @@ const fn const_context() { // ^ 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 + //[unstable]~^ ERROR not yet stable as a const fn + // ^ fails, because the `foo` feature is not active } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(unstable, rustc_const_unstable(feature = "foo", issue = "none"))] +pub const fn const_context_not_const_stable() { + //[stable]~^ ERROR function has missing const stability attribute + Unstable::func(); + // ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is + // not const-stable. + Foo::func(); + //[unstable]~^ ERROR not yet stable as a const fn + // ^ fails, because the `foo` feature is not active +} + +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "cheese", 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 + const_context_not_const_stable() + //[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 6c9c660ab234c..a1aca762ef479 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 @@ -9,5 +9,17 @@ LL | | } | = note: see issue #67792 for more information -error: aborting due to previous error +error: function has missing const stability attribute + --> $DIR/staged-api.rs:42:1 + | +LL | / pub const fn const_context_not_const_stable() { +LL | | +LL | | Unstable::func(); +LL | | // ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is +... | +LL | | // ^ fails, because the `foo` feature is not active +LL | | } + | |_^ + +error: aborting due to 2 previous errors 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 0401ba478fd11..c38d1a81ae77b 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 @@ -7,12 +7,36 @@ LL | Foo::func(); = help: add `#![feature(foo)]` to the crate attributes to enable error: `::func` is not yet stable as a const fn - --> $DIR/staged-api.rs:43:5 + --> $DIR/staged-api.rs:47:5 | LL | Foo::func(); | ^^^^^^^^^^^ | = help: add `#![feature(foo)]` to the crate attributes to enable -error: aborting due to 2 previous errors +error: `::func` is not yet stable as a const fn + --> $DIR/staged-api.rs:55:5 + | +LL | Unstable::func(); + | ^^^^^^^^^^^^^^^^ + | + = help: const-stable functions can only call other const-stable functions + +error: `::func` is not yet stable as a const fn + --> $DIR/staged-api.rs:57:5 + | +LL | Foo::func(); + | ^^^^^^^^^^^ + | + = help: const-stable functions can only call other const-stable functions + +error: `const_context_not_const_stable` is not yet stable as a const fn + --> $DIR/staged-api.rs:59:5 + | +LL | const_context_not_const_stable() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: const-stable functions can only call other const-stable functions + +error: aborting due to 5 previous errors