Static rustc_lint::builtin::KEYWORD_IDENTS_2024
source · pub static KEYWORD_IDENTS_2024: &Lint
Expand description
The keyword_idents_2024
lint detects edition keywords being used as an
identifier.
§Example
#![deny(keyword_idents_2024)]
// edition 2015
fn gen() {}
{{produces}}
§Explanation
Rust editions allow the language to evolve without breaking backwards compatibility. This lint catches code that uses new keywords that are added to the language that are used as identifiers (such as a variable name, function name, etc.). If you switch the compiler to a new edition without updating the code, then it will fail to compile if you are using a new keyword as an identifier.
You can manually change the identifiers to a non-keyword, or use a
raw identifier, for example r#gen
, to transition to a new edition.
This lint solves the problem automatically. It is “allow” by default
because the code is perfectly valid in older editions. The cargo fix
tool with the --edition
flag will switch this lint to “warn”
and automatically apply the suggested fix from the compiler (which is
to use a raw identifier). This provides a completely automated way to
update old code for a new edition.