lotsoftools

Understanding Rust Error E0547

Rust Error E0547: Missing issue value in stability attribute

In Rust, error E0547 occurs when the issue value is missing in a stability attribute. Stability attributes are used to indicate the stability level of an API feature, i.e., whether it is a stable, deprecated, or unstable feature.

Erroneous Code Example

#![allow(unused)]
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]

fn main() {
    #[unstable(feature = "_unstable_fn")] // invalid
    fn _unstable_fn() {}

    #[rustc_const_unstable(feature = "_unstable_const_fn")] // invalid
    const fn _unstable_const_fn() {}
}

The above code example lacks the issue field in the unstable and rustc_const_unstable attributes, which leads to error E0547.

Solution

To fix this issue, you need to provide the issue field in the stability attributes. The issue field can be set to a valid issue number or 'none' if not referring to a specific issue.

Corrected Code Example

#![allow(unused)]
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]

fn main() {
    #[unstable(feature = "_unstable_fn", issue = "none")] // ok!
    fn _unstable_fn() {}

    #[rustc_const_unstable(
        feature = "_unstable_const_fn",
        issue = "none"
    )] // ok!
    const fn _unstable_const_fn() {}
}

By adding the issue field, the code now compiles without error. For more information, refer to the How Rust is Made and 'Nightly Rust' appendix of the Rust Book and the Stability attributes section of the Rustc Dev Guide.

Recommended Reading