@@ -12,14 +12,38 @@ use rustc_session::lint::FutureIncompatibilityReason;
12
12
use rustc_span:: edition:: Edition ;
13
13
use rustc_span:: sym;
14
14
15
- use crate :: lints:: MacroExprFragment2023 ;
15
+ use crate :: lints:: MacroExprFragment2024 ;
16
16
use crate :: EarlyLintPass ;
17
17
18
18
declare_lint ! {
19
+ /// TODO: better explaination for this.
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
19
43
pub EDITION_2024_EXPR_FRAGMENT_SPECIFIER ,
20
44
Allow ,
21
45
"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.",
23
47
@future_incompatible = FutureIncompatibleInfo {
24
48
reason: FutureIncompatibilityReason :: EditionSemanticsChange ( Edition :: Edition2024 ) ,
25
49
reference: "issue #123742 <https://github.com/rust-lang/rust/issues/123742>" ,
@@ -30,11 +54,9 @@ declare_lint_pass!(Expr2024 => [EDITION_2024_EXPR_FRAGMENT_SPECIFIER,]);
30
54
31
55
impl Expr2024 {
32
56
fn check_tokens ( & mut self , cx : & crate :: EarlyContext < ' _ > , tokens : & TokenStream ) {
33
- // Check if the preceding token is `$`, because we want to allow `$async`, etc.
34
57
let mut prev_dollar = false ;
35
58
for tt in tokens. trees ( ) {
36
59
match tt {
37
- // Only report non-raw idents.
38
60
TokenTree :: Token ( token, _) => {
39
61
if token. kind == TokenKind :: Dollar {
40
62
prev_dollar = true ;
@@ -71,7 +93,7 @@ impl Expr2024 {
71
93
cx. builder . emit_span_lint (
72
94
& EDITION_2024_EXPR_FRAGMENT_SPECIFIER ,
73
95
token. span . into ( ) ,
74
- MacroExprFragment2023 { suggestion : token. span } ,
96
+ MacroExprFragment2024 { suggestion : token. span } ,
75
97
) ;
76
98
}
77
99
}
0 commit comments