Skip to content

Commit

Permalink
Fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 19, 2022
1 parent aa9eae5 commit f9c4f2b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.rs
Original file line number Diff line number Diff line change
@@ -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 `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api-user-crate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0015]: cannot call non-const fn `<staged_api::Unstable as staged_api::MyTrait>::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`.
18 changes: 17 additions & 1 deletion src/test/ui/rfc-2632-const-trait-impl/staged-api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
14 changes: 13 additions & 1 deletion src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ LL | | }
|
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/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

28 changes: 26 additions & 2 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,36 @@ 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: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: `<staged_api::Unstable as staged_api::MyTrait>::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: `<Foo as staged_api::MyTrait>::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

0 comments on commit f9c4f2b

Please sign in to comment.