File tree 5 files changed +83
-4
lines changed
src/test/ui/rfc-2632-const-trait-impl
5 files changed +83
-4
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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`.
Original file line number Diff line number Diff line change @@ -33,15 +33,31 @@ const fn const_context() {
33
33
// ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is
34
34
// not const-stable.
35
35
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
37
38
}
38
39
39
40
#[ 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" ) ]
40
54
const fn stable_const_context ( ) {
41
55
Unstable :: func ( ) ;
42
56
//[unstable]~^ ERROR not yet stable as a const fn
43
57
Foo :: func ( ) ;
44
58
//[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
45
61
}
46
62
47
63
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -9,5 +9,17 @@ LL | | }
9
9
|
10
10
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
11
11
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
13
25
Original file line number Diff line number Diff line change @@ -7,12 +7,36 @@ LL | Foo::func();
7
7
= help: add `#![feature(foo)]` to the crate attributes to enable
8
8
9
9
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
11
11
|
12
12
LL | Foo::func();
13
13
| ^^^^^^^^^^^
14
14
|
15
15
= help: add `#![feature(foo)]` to the crate attributes to enable
16
16
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
18
42
You can’t perform that action at this time.
0 commit comments