Understanding Rust Error E0705
Introduction to Rust Error E0705
Rust Error E0705 occurs when a #![feature] attribute is declared for a feature that is stable in the current edition, but not in all editions. This error is intended to help developers avoid using unstable features in their code.
Error E0705 Example
Here's an example of Rust code that triggers Error E0705:
#![allow(unused)]
#![feature(rust_2018_preview)]
#![feature(test_2018_feature)] // error: the feature
fn main() {
// `test_2018_feature` is
// included in the Rust 2018 edition
}
Explanation of the Example
In the erroneous code example, the feature attribute `test_2018_feature` is included in the Rust 2018 edition. However, the code is compiled with the Rust 2015 edition, causing Rust Error E0705 to be thrown.
How to Fix Error E0705
To fix Rust Error E0705, you can remove the #![feature] attribute or ensure that the feature attribute only exists in the proper edition scope.
Fixed Example
Here's a corrected version of the previous code example:
#![allow(unused)]
#![feature(rust_2018_preview)]
#[cfg(feature = "test_2018_feature")]
fn main() {
// `test_2018_feature` is
// included in the Rust 2018 edition
}
Summary
Rust Error E0705 is triggered when a #![feature] attribute is declared for a stable feature in the current edition, but not in other editions. To resolve this error, remove the problematic #![feature] attribute or make sure the attribute is only present within the correct edition scope.