]> git.lizzy.rs Git - rust.git/blob - tests/ui/rfc-2632-const-trait-impl/staged-api.rs
Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisa
[rust.git] / tests / ui / rfc-2632-const-trait-impl / staged-api.rs
1 // revisions: stable unstable
2
3 #![cfg_attr(unstable, feature(unstable))] // The feature from the ./auxiliary/staged-api.rs file.
4 #![feature(const_trait_impl)]
5 #![feature(staged_api)]
6 #![stable(feature = "rust1", since = "1.0.0")]
7
8 // aux-build: staged-api.rs
9 extern crate staged_api;
10
11 use staged_api::*;
12
13 #[stable(feature = "rust1", since = "1.0.0")]
14 pub struct Foo;
15
16 #[stable(feature = "rust1", since = "1.0.0")]
17 #[cfg_attr(unstable, rustc_const_unstable(feature = "foo", issue = "none"))]
18 #[cfg_attr(stable, rustc_const_stable(feature = "foo", since = "1.0.0"))]
19 impl const MyTrait for Foo {
20     //[stable]~^ ERROR trait implementations cannot be const stable yet
21     fn func() {}
22 }
23
24 // Const stability has no impact on usage in non-const contexts.
25 fn non_const_context() {
26     Unstable::func();
27     Foo::func();
28 }
29
30 #[unstable(feature = "none", issue = "none")]
31 const fn const_context() {
32     Unstable::func();
33     // ^ This is okay regardless of whether the `unstable` feature is enabled, as this function is
34     // not const-stable.
35     Foo::func();
36     //[unstable]~^ ERROR not yet stable as a const fn
37     // ^ fails, because the `foo` feature is not active
38 }
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")]
54 const fn stable_const_context() {
55     Unstable::func();
56     //[unstable]~^ ERROR not yet stable as a const fn
57     Foo::func();
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
61 }
62
63 fn main() {}