@@ -12,14 +12,38 @@ use rustc_session::lint::FutureIncompatibilityReason;
1212use rustc_span:: edition:: Edition ;
1313use rustc_span:: sym;
1414
15- use crate :: lints:: MacroExprFragment2023 ;
15+ use crate :: lints:: MacroExprFragment2024 ;
1616use crate :: EarlyLintPass ;
1717
1818declare_lint ! {
19+ /// FIXME: better docs for the lint.
20+ ///
21+ /// ### Explanation
22+ ///
23+ /// Rust [editions] allow the language to evolve without breaking
24+ /// backwards compatibility. This lint catches code that uses new keywords
25+ /// that are added to the language that are used as identifiers (such as a
26+ /// variable name, function name, etc.). If you switch the compiler to a
27+ /// new edition without updating the code, then it will fail to compile if
28+ /// you are using a new keyword as an identifier.
29+ ///
30+ /// FIXME: change this: You can manually change the identifiers from `expr` to `expr2021`,
31+ /// or use a [raw identifier], for example `r#gen`, to transition to a new edition.
32+ ///
33+ /// This lint solves the problem automatically. It is "allow" by default
34+ /// because the code is perfectly valid in older editions. The [`cargo
35+ /// fix`] tool with the `--edition` flag will switch this lint to "warn"
36+ /// and automatically apply the suggested fix from the compiler (which is
37+ /// to use a raw identifier). This provides a completely automated way to
38+ /// update old code for a new edition.
39+ ///
40+ /// [editions]: https://doc.rust-lang.org/edition-guide/
41+ /// [raw identifier]: https://doc.rust-lang.org/reference/identifiers.html
42+ /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1943 pub EDITION_2024_EXPR_FRAGMENT_SPECIFIER ,
2044 Allow ,
2145 "The `expr` fragment specifier will accept more expressions in the 2024 edition. \
22- To keep the existing before , use the `expr_2021` fragment specifier.",
46+ To keep the existing behavior , use the `expr_2021` fragment specifier.",
2347 @future_incompatible = FutureIncompatibleInfo {
2448 reason: FutureIncompatibilityReason :: EditionSemanticsChange ( Edition :: Edition2024 ) ,
2549 reference: "issue #123742 <https://github.com/rust-lang/rust/issues/123742>" ,
@@ -30,11 +54,9 @@ declare_lint_pass!(Expr2024 => [EDITION_2024_EXPR_FRAGMENT_SPECIFIER,]);
3054
3155impl Expr2024 {
3256 fn check_tokens ( & mut self , cx : & crate :: EarlyContext < ' _ > , tokens : & TokenStream ) {
33- // Check if the preceding token is `$`, because we want to allow `$async`, etc.
3457 let mut prev_dollar = false ;
3558 for tt in tokens. trees ( ) {
3659 match tt {
37- // Only report non-raw idents.
3860 TokenTree :: Token ( token, _) => {
3961 if token. kind == TokenKind :: Dollar {
4062 prev_dollar = true ;
@@ -71,7 +93,7 @@ impl Expr2024 {
7193 cx. builder . emit_span_lint (
7294 & EDITION_2024_EXPR_FRAGMENT_SPECIFIER ,
7395 token. span . into ( ) ,
74- MacroExprFragment2023 { suggestion : token. span } ,
96+ MacroExprFragment2024 { suggestion : token. span } ,
7597 ) ;
7698 }
7799}
0 commit comments