Skip to content

Commit 2de8f59

Browse files
fixup! Adds expr_2024 migration lit
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 1952cff commit 2de8f59

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

compiler/rustc_lint/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub struct BuiltinTypeAliasGenericBounds<'a, 'b> {
325325

326326
#[derive(LintDiagnostic)]
327327
#[diag(lint_macro_expr_fragment_specifier_2024_migration)]
328-
pub struct MacroExprFragment2023 {
328+
pub struct MacroExprFragment2024 {
329329
#[suggestion(code = "expr_2021", applicability = "machine-applicable")]
330330
pub suggestion: Span,
331331
}

compiler/rustc_lint/src/macro_expr_fragment_specifier_2024_migration.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,38 @@ use rustc_session::lint::FutureIncompatibilityReason;
1212
use rustc_span::edition::Edition;
1313
use rustc_span::sym;
1414

15-
use crate::lints::MacroExprFragment2023;
15+
use crate::lints::MacroExprFragment2024;
1616
use crate::EarlyLintPass;
1717

1818
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
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

3155
impl 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

Comments
 (0)