Skip to content

Commit f9c4f2b

Browse files
committed
Fix up tests
1 parent aa9eae5 commit f9c4f2b

File tree

5 files changed

+83
-4
lines changed

5 files changed

+83
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build: staged-api.rs
2+
extern crate staged_api;
3+
4+
use staged_api::*;
5+
6+
// Const stability has no impact on usage in non-const contexts.
7+
fn non_const_context() {
8+
Unstable::func();
9+
}
10+
11+
const fn stable_const_context() {
12+
Unstable::func();
13+
//~^ ERROR cannot call non-const fn `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0015]: cannot call non-const fn `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
2+
--> $DIR/staged-api-user-crate.rs:12:5
3+
|
4+
LL | Unstable::func();
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0015`.

src/test/ui/rfc-2632-const-trait-impl/staged-api.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,31 @@ const fn const_context() {
3333
// ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is
3434
// not const-stable.
3535
Foo::func();
36-
//[unstable]~^ not yet stable as a const fn
36+
//[unstable]~^ ERROR not yet stable as a const fn
37+
// ^ fails, because the `foo` feature is not active
3738
}
3839

3940
#[stable(feature = "rust1", since = "1.0.0")]
41+
#[cfg_attr(unstable, rustc_const_unstable(feature = "foo", issue = "none"))]
42+
pub const fn const_context_not_const_stable() {
43+
//[stable]~^ ERROR function has missing const stability attribute
44+
Unstable::func();
45+
// ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is
46+
// not const-stable.
47+
Foo::func();
48+
//[unstable]~^ ERROR not yet stable as a const fn
49+
// ^ fails, because the `foo` feature is not active
50+
}
51+
52+
#[stable(feature = "rust1", since = "1.0.0")]
53+
#[rustc_const_stable(feature = "cheese", since = "1.0.0")]
4054
const fn stable_const_context() {
4155
Unstable::func();
4256
//[unstable]~^ ERROR not yet stable as a const fn
4357
Foo::func();
4458
//[unstable]~^ ERROR not yet stable as a const fn
59+
const_context_not_const_stable()
60+
//[unstable]~^ ERROR not yet stable as a const fn
4561
}
4662

4763
fn main() {}

src/test/ui/rfc-2632-const-trait-impl/staged-api.stable.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,17 @@ LL | | }
99
|
1010
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
1111

12-
error: aborting due to previous error
12+
error: function has missing const stability attribute
13+
--> $DIR/staged-api.rs:42:1
14+
|
15+
LL | / pub const fn const_context_not_const_stable() {
16+
LL | |
17+
LL | | Unstable::func();
18+
LL | | // ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is
19+
... |
20+
LL | | // ^ fails, because the `foo` feature is not active
21+
LL | | }
22+
| |_^
23+
24+
error: aborting due to 2 previous errors
1325

src/test/ui/rfc-2632-const-trait-impl/staged-api.unstable.stderr

+26-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,36 @@ LL | Foo::func();
77
= help: add `#![feature(foo)]` to the crate attributes to enable
88

99
error: `<Foo as staged_api::MyTrait>::func` is not yet stable as a const fn
10-
--> $DIR/staged-api.rs:43:5
10+
--> $DIR/staged-api.rs:47:5
1111
|
1212
LL | Foo::func();
1313
| ^^^^^^^^^^^
1414
|
1515
= help: add `#![feature(foo)]` to the crate attributes to enable
1616

17-
error: aborting due to 2 previous errors
17+
error: `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn
18+
--> $DIR/staged-api.rs:55:5
19+
|
20+
LL | Unstable::func();
21+
| ^^^^^^^^^^^^^^^^
22+
|
23+
= help: const-stable functions can only call other const-stable functions
24+
25+
error: `<Foo as staged_api::MyTrait>::func` is not yet stable as a const fn
26+
--> $DIR/staged-api.rs:57:5
27+
|
28+
LL | Foo::func();
29+
| ^^^^^^^^^^^
30+
|
31+
= help: const-stable functions can only call other const-stable functions
32+
33+
error: `const_context_not_const_stable` is not yet stable as a const fn
34+
--> $DIR/staged-api.rs:59:5
35+
|
36+
LL | const_context_not_const_stable()
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
= help: const-stable functions can only call other const-stable functions
40+
41+
error: aborting due to 5 previous errors
1842

0 commit comments

Comments
 (0)