]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0542.md
fn must be const if marked with stability attribut
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0542.md
1 The `since` value is missing in a stability attribute.
2
3 Erroneous code example:
4
5 ```compile_fail,E0542
6 #![feature(staged_api)]
7 #![stable(since = "1.0.0", feature = "test")]
8
9 #[stable(feature = "_stable_fn")] // invalid
10 fn _stable_fn() {}
11
12 #[rustc_const_stable(feature = "_stable_const_fn")] // invalid
13 const fn _stable_const_fn() {}
14
15 #[stable(feature = "_deprecated_fn", since = "0.1.0")]
16 #[rustc_deprecated(
17     reason = "explanation for deprecation"
18 )] // invalid
19 fn _deprecated_fn() {}
20 ```
21
22 To fix this issue, you need to provide the `since` field. Example:
23
24 ```
25 #![feature(staged_api)]
26 #![stable(since = "1.0.0", feature = "test")]
27
28 #[stable(feature = "_stable_fn", since = "1.0.0")] // ok!
29 fn _stable_fn() {}
30
31 #[rustc_const_stable(feature = "_stable_const_fn", since = "1.0.0")] // ok!
32 const fn _stable_const_fn() {}
33
34 #[stable(feature = "_deprecated_fn", since = "0.1.0")]
35 #[rustc_deprecated(
36     since = "1.0.0",
37     reason = "explanation for deprecation"
38 )] // ok!
39 fn _deprecated_fn() {}
40 ```
41
42 See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
43 of the Book and the [Stability attributes][stability-attributes] section of the
44 Rustc Dev Guide for more details.
45
46 [how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
47 [stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html