From ebc4acee91dc9871d1c90f0d7a38aff0580dd18a Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 22 Mar 2021 13:53:16 -0500 Subject: [PATCH 1/4] stabilize :pat2015, leave :pat2021 gated --- compiler/rustc_expand/src/mbe/quoted.rs | 23 ++++++++----------- compiler/rustc_feature/src/active.rs | 2 +- .../feature-gate-edition_macro_pats.rs | 4 ++-- .../feature-gate-edition_macro_pats.stderr | 13 ++--------- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index e205cb65d0229..c3e7448b63090 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -62,19 +62,16 @@ pub(super) fn parse( Some((frag, _)) => { let span = token.span.with_lo(start_sp.lo()); - match frag.name { - sym::pat2015 | sym::pat2021 => { - if !features.edition_macro_pats { - feature_err( - sess, - sym::edition_macro_pats, - frag.span, - "`pat2015` and `pat2021` are unstable.", - ) - .emit(); - } - } - _ => {} + if matches!(frag.name, sym::pat2021) + && !features.edition_macro_pats + { + feature_err( + sess, + sym::edition_macro_pats, + frag.span, + "`pat2021` is unstable.", + ) + .emit(); } let kind = diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1a91eb600a91b..774f21b2dd885 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -609,7 +609,7 @@ declare_features! ( /// Allows arbitrary expressions in key-value attributes at parse time. (active, extended_key_value_attributes, "1.50.0", Some(78835), None), - /// `:pat2015` and `:pat2021` macro matchers. + /// `:pat2021` macro matcher. (active, edition_macro_pats, "1.51.0", Some(54883), None), /// Allows const generics to have default values (e.g. `struct Foo(...);`). diff --git a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs index 430a9437cee34..e9f813f83ae98 100644 --- a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs +++ b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs @@ -1,8 +1,8 @@ // Feature gate test for `edition_macro_pats` feature. macro_rules! foo { - ($x:pat2015) => {}; //~ERROR `pat2015` and `pat2021` are unstable - ($x:pat2021) => {}; //~ERROR `pat2015` and `pat2021` are unstable + ($x:pat2015) => {}; // ok + ($x:pat2021) => {}; //~ERROR `pat2021` is unstable } fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr index d25bcaf929bcd..dc1f52d87a820 100644 --- a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr +++ b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr @@ -1,13 +1,4 @@ -error[E0658]: `pat2015` and `pat2021` are unstable. - --> $DIR/feature-gate-edition_macro_pats.rs:4:9 - | -LL | ($x:pat2015) => {}; - | ^^^^^^^ - | - = note: see issue #54883 for more information - = help: add `#![feature(edition_macro_pats)]` to the crate attributes to enable - -error[E0658]: `pat2015` and `pat2021` are unstable. +error[E0658]: `pat2021` is unstable. --> $DIR/feature-gate-edition_macro_pats.rs:5:9 | LL | ($x:pat2021) => {}; @@ -16,6 +7,6 @@ LL | ($x:pat2021) => {}; = note: see issue #54883 for more information = help: add `#![feature(edition_macro_pats)]` to the crate attributes to enable -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. From 0566ccc72fc49e0a30fedebca754c8cc10bb1a73 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 14 Apr 2021 20:34:51 -0500 Subject: [PATCH 2/4] rename pat2015 to pat_param --- compiler/rustc_ast/src/token.rs | 14 +++++++------- compiler/rustc_expand/src/mbe/macro_rules.rs | 8 ++++---- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_parse/src/parser/nonterminal.rs | 10 ++++++---- compiler/rustc_span/src/symbol.rs | 2 +- .../feature-gate-edition_macro_pats.rs | 2 +- src/test/ui/macros/edition-macro-pats.rs | 2 +- .../ui/macros/macro-or-patterns-back-compat.fixed | 12 ++++++------ .../ui/macros/macro-or-patterns-back-compat.rs | 6 +++--- .../ui/macros/macro-or-patterns-back-compat.stderr | 10 +++++----- 10 files changed, 35 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 10d48a55bb54e..3bd2d0fa324a4 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -688,13 +688,13 @@ pub enum NonterminalKind { Item, Block, Stmt, - Pat2015 { - /// Keep track of whether the user used `:pat2015` or `:pat` and we inferred it from the + PatParam { + /// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the /// edition of the span. This is used for diagnostics. inferred: bool, }, Pat2021 { - /// Keep track of whether the user used `:pat2015` or `:pat` and we inferred it from the + /// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the /// edition of the span. This is used for diagnostics. inferred: bool, }, @@ -722,11 +722,11 @@ impl NonterminalKind { sym::stmt => NonterminalKind::Stmt, sym::pat => match edition() { Edition::Edition2015 | Edition::Edition2018 => { - NonterminalKind::Pat2015 { inferred: true } + NonterminalKind::PatParam { inferred: true } } Edition::Edition2021 => NonterminalKind::Pat2021 { inferred: true }, }, - sym::pat2015 => NonterminalKind::Pat2015 { inferred: false }, + sym::pat_param => NonterminalKind::PatParam { inferred: false }, sym::pat2021 => NonterminalKind::Pat2021 { inferred: false }, sym::expr => NonterminalKind::Expr, sym::ty => NonterminalKind::Ty, @@ -745,9 +745,9 @@ impl NonterminalKind { NonterminalKind::Item => sym::item, NonterminalKind::Block => sym::block, NonterminalKind::Stmt => sym::stmt, - NonterminalKind::Pat2015 { inferred: false } => sym::pat2015, + NonterminalKind::PatParam { inferred: false } => sym::pat_param, NonterminalKind::Pat2021 { inferred: false } => sym::pat2021, - NonterminalKind::Pat2015 { inferred: true } + NonterminalKind::PatParam { inferred: true } | NonterminalKind::Pat2021 { inferred: true } => sym::pat, NonterminalKind::Expr => sym::expr, NonterminalKind::Ty => sym::ty, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index bc45c57596e15..7a2fa3d247512 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -955,15 +955,15 @@ fn check_matcher_core( if let TokenTree::MetaVarDecl(span, name, Some(kind)) = *token { for next_token in &suffix_first.tokens { // Check if the old pat is used and the next token is `|`. - if let NonterminalKind::Pat2015 { inferred: true } = kind { + if let NonterminalKind::PatParam { inferred: true } = kind { if let TokenTree::Token(token) = next_token { if let BinOp(token) = token.kind { if let token::BinOpToken::Or = token { - // It is suggestion to use pat2015, for example: $x:pat -> $x:pat2015. + // It is suggestion to use pat_param, for example: $x:pat -> $x:pat_param. let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl( span, name, - Some(NonterminalKind::Pat2015 { inferred: false }), + Some(NonterminalKind::PatParam { inferred: false }), )); sess.buffer_lint_with_diagnostic( &OR_PATTERNS_BACK_COMPAT, @@ -1105,7 +1105,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { _ => IsInFollow::No(TOKENS), } } - NonterminalKind::Pat2015 { .. } => { + NonterminalKind::PatParam { .. } => { const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"]; match tok { TokenTree::Token(token) => match token.kind { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index b3a19bfbf7532..c1d6a4f1de1ff 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -710,7 +710,7 @@ pub trait LintContext: Sized { db.note(¬e); } BuiltinLintDiagnostics::OrPatternsBackCompat(span,suggestion) => { - db.span_suggestion(span, "use pat2015 to preserve semantics", suggestion, Applicability::MachineApplicable); + db.span_suggestion(span, "use pat_param to preserve semantics", suggestion, Applicability::MachineApplicable); } } // Rewrap `db`, and pass control to the user. diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 5c4a2785d6e26..5635fbbb978ea 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -61,7 +61,8 @@ impl<'a> Parser<'a> { }, _ => false, }, - NonterminalKind::Pat2015 { .. } | NonterminalKind::Pat2021 { .. } => match token.kind { + NonterminalKind::PatParam { .. } | NonterminalKind::Pat2021 { .. } => { + match token.kind { token::Ident(..) | // box, ref, mut, and other identifiers (can stricten) token::OpenDelim(token::Paren) | // tuple pattern token::OpenDelim(token::Bracket) | // slice pattern @@ -78,7 +79,8 @@ impl<'a> Parser<'a> { token::BinOp(token::Or) => matches!(kind, NonterminalKind::Pat2021 {..}), token::Interpolated(ref nt) => may_be_ident(nt), _ => false, - }, + } + } NonterminalKind::Lifetime => match token.kind { token::Lifetime(_) => true, token::Interpolated(ref nt) => { @@ -118,9 +120,9 @@ impl<'a> Parser<'a> { return Err(self.struct_span_err(self.token.span, "expected a statement")); } }, - NonterminalKind::Pat2015 { .. } | NonterminalKind::Pat2021 { .. } => { + NonterminalKind::PatParam { .. } | NonterminalKind::Pat2021 { .. } => { token::NtPat(self.collect_tokens_no_attrs(|this| match kind { - NonterminalKind::Pat2015 { .. } => this.parse_pat_no_top_alt(None), + NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None), NonterminalKind::Pat2021 { .. } => { this.parse_pat_allow_top_alt(None, RecoverComma::No) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 42e521a20a3c3..db0d0b9966c94 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -849,8 +849,8 @@ symbols! { partial_ord, passes, pat, - pat2015, pat2021, + pat_param, path, pattern_parentheses, phantom_data, diff --git a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs index e9f813f83ae98..fdd8626c760b1 100644 --- a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs +++ b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs @@ -1,7 +1,7 @@ // Feature gate test for `edition_macro_pats` feature. macro_rules! foo { - ($x:pat2015) => {}; // ok + ($x:pat_param) => {}; // ok ($x:pat2021) => {}; //~ERROR `pat2021` is unstable } diff --git a/src/test/ui/macros/edition-macro-pats.rs b/src/test/ui/macros/edition-macro-pats.rs index 58f9271030583..963a9c01a3b69 100644 --- a/src/test/ui/macros/edition-macro-pats.rs +++ b/src/test/ui/macros/edition-macro-pats.rs @@ -3,7 +3,7 @@ #![feature(edition_macro_pats)] macro_rules! foo { - (a $x:pat2015) => {}; + (a $x:pat_param) => {}; (b $x:pat2021) => {}; } diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.fixed b/src/test/ui/macros/macro-or-patterns-back-compat.fixed index f089f0fda4e77..e0bd4cdde24d1 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.fixed +++ b/src/test/ui/macros/macro-or-patterns-back-compat.fixed @@ -3,13 +3,13 @@ #![feature(edition_macro_pats)] #![deny(or_patterns_back_compat)] #![allow(unused_macros)] -macro_rules! foo { ($x:pat2015 | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro -macro_rules! bar { ($($x:pat2015)+ | $($y:pat)+) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro -macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok -macro_rules! qux { ($x:pat2015 | $y:pat) => {} } // should be ok -macro_rules! ogg { ($x:pat2015 | $y:pat2015) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! foo { ($x:pat_param | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! bar { ($($x:pat_param)+ | $($y:pat)+) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok +macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok +macro_rules! ogg { ($x:pat_param | $y:pat_param) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro macro_rules! match_any { - ( $expr:expr , $( $( $pat:pat2015 )|+ => $expr_arm:expr ),+ ) => { //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + ( $expr:expr , $( $( $pat:pat_param )|+ => $expr_arm:expr ),+ ) => { //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro match $expr { $( $( $pat => $expr_arm, )+ diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.rs b/src/test/ui/macros/macro-or-patterns-back-compat.rs index 0252581d5f168..9ff072dc3235f 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.rs +++ b/src/test/ui/macros/macro-or-patterns-back-compat.rs @@ -5,9 +5,9 @@ #![allow(unused_macros)] macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro -macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok -macro_rules! qux { ($x:pat2015 | $y:pat) => {} } // should be ok -macro_rules! ogg { ($x:pat | $y:pat2015) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok +macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok +macro_rules! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro macro_rules! match_any { ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro match $expr { diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.stderr b/src/test/ui/macros/macro-or-patterns-back-compat.stderr index d8f19fa580779..970f62f6cff48 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.stderr +++ b/src/test/ui/macros/macro-or-patterns-back-compat.stderr @@ -2,7 +2,7 @@ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, whi --> $DIR/macro-or-patterns-back-compat.rs:6:21 | LL | macro_rules! foo { ($x:pat | $y:pat) => {} } - | ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015` + | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` | note: the lint level is defined here --> $DIR/macro-or-patterns-back-compat.rs:4:9 @@ -14,19 +14,19 @@ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, whi --> $DIR/macro-or-patterns-back-compat.rs:7:23 | LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } - | ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015` + | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro --> $DIR/macro-or-patterns-back-compat.rs:10:21 | -LL | macro_rules! ogg { ($x:pat | $y:pat2015) => {} } - | ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015` +LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} } + | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro --> $DIR/macro-or-patterns-back-compat.rs:12:26 | LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { - | ^^^^^^^^ help: use pat2015 to preserve semantics: `$pat:pat2015` + | ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param` error: aborting due to 4 previous errors From 3f7b98ebe0238e3bacbeedc57c76d825eabc689c Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 15 Apr 2021 14:27:29 -0500 Subject: [PATCH 3/4] update test --- src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs | 6 +++--- .../ui/macros/macro-pat2021-pattern-followed-by-or.stderr | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs index edd3f3e7646b8..1b8189e094842 100644 --- a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs +++ b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs @@ -1,9 +1,9 @@ #![feature(edition_macro_pats)] #![allow(unused_macros)] macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments -macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok -macro_rules! qux { ($x:pat2015 | $y:pat2021) => {} } // should be ok -macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments +macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok +macro_rules! qux { ($x:pat_param | $y:pat2021) => {} } // should be ok +macro_rules! ogg { ($x:pat2021 | $y:pat_param) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments macro_rules! match_any { ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments match $expr { diff --git a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr index fe0b40cd86e12..e74e8870806e3 100644 --- a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr +++ b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr @@ -9,7 +9,7 @@ LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments --> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32 | -LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } +LL | macro_rules! ogg { ($x:pat2021 | $y:pat_param) => {} } | ^ not allowed after `pat2021` fragments | = note: allowed there are: `=>`, `,`, `=`, `if` or `in` From 2a9db919ffb30ca09a015877b6ab2ffab5633249 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 27 Apr 2021 21:15:59 -0500 Subject: [PATCH 4/4] remove pat2021 --- compiler/rustc_ast/src/token.rs | 13 +++------- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_expand/src/mbe/quoted.rs | 16 ++----------- compiler/rustc_feature/src/active.rs | 3 --- .../rustc_parse/src/parser/nonterminal.rs | 8 +++---- compiler/rustc_span/src/symbol.rs | 1 - .../feature-gate-edition_macro_pats.rs | 8 ------- .../feature-gate-edition_macro_pats.stderr | 12 ---------- src/test/ui/macros/edition-macro-pats.rs | 5 ++-- .../macro-or-patterns-back-compat.fixed | 1 - .../macros/macro-or-patterns-back-compat.rs | 1 - .../macro-or-patterns-back-compat.stderr | 10 ++++---- .../macro-pat2021-pattern-followed-by-or.rs | 11 +++++---- ...acro-pat2021-pattern-followed-by-or.stderr | 24 +++++++++---------- 14 files changed, 35 insertions(+), 80 deletions(-) delete mode 100644 src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 3bd2d0fa324a4..15f46ef5d7fe5 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -693,11 +693,7 @@ pub enum NonterminalKind { /// edition of the span. This is used for diagnostics. inferred: bool, }, - Pat2021 { - /// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the - /// edition of the span. This is used for diagnostics. - inferred: bool, - }, + PatWithOr, Expr, Ty, Ident, @@ -724,10 +720,9 @@ impl NonterminalKind { Edition::Edition2015 | Edition::Edition2018 => { NonterminalKind::PatParam { inferred: true } } - Edition::Edition2021 => NonterminalKind::Pat2021 { inferred: true }, + Edition::Edition2021 => NonterminalKind::PatWithOr, }, sym::pat_param => NonterminalKind::PatParam { inferred: false }, - sym::pat2021 => NonterminalKind::Pat2021 { inferred: false }, sym::expr => NonterminalKind::Expr, sym::ty => NonterminalKind::Ty, sym::ident => NonterminalKind::Ident, @@ -746,9 +741,7 @@ impl NonterminalKind { NonterminalKind::Block => sym::block, NonterminalKind::Stmt => sym::stmt, NonterminalKind::PatParam { inferred: false } => sym::pat_param, - NonterminalKind::Pat2021 { inferred: false } => sym::pat2021, - NonterminalKind::PatParam { inferred: true } - | NonterminalKind::Pat2021 { inferred: true } => sym::pat, + NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat, NonterminalKind::Expr => sym::expr, NonterminalKind::Ty => sym::ty, NonterminalKind::Ident => sym::ident, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 7a2fa3d247512..91d4a0f0d6581 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -1116,7 +1116,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { _ => IsInFollow::No(TOKENS), } } - NonterminalKind::Pat2021 { .. } => { + NonterminalKind::PatWithOr { .. } => { const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`if`", "`in`"]; match tok { TokenTree::Token(token) => match token.kind { diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index c3e7448b63090..aca02ef93f8b5 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -6,8 +6,8 @@ use rustc_ast::tokenstream; use rustc_ast::{NodeId, DUMMY_NODE_ID}; use rustc_ast_pretty::pprust; use rustc_feature::Features; -use rustc_session::parse::{feature_err, ParseSess}; -use rustc_span::symbol::{kw, sym, Ident}; +use rustc_session::parse::ParseSess; +use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; @@ -62,18 +62,6 @@ pub(super) fn parse( Some((frag, _)) => { let span = token.span.with_lo(start_sp.lo()); - if matches!(frag.name, sym::pat2021) - && !features.edition_macro_pats - { - feature_err( - sess, - sym::edition_macro_pats, - frag.span, - "`pat2021` is unstable.", - ) - .emit(); - } - let kind = token::NonterminalKind::from_symbol(frag.name, || { span.edition() diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 774f21b2dd885..3151aa349d636 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -609,9 +609,6 @@ declare_features! ( /// Allows arbitrary expressions in key-value attributes at parse time. (active, extended_key_value_attributes, "1.50.0", Some(78835), None), - /// `:pat2021` macro matcher. - (active, edition_macro_pats, "1.51.0", Some(54883), None), - /// Allows const generics to have default values (e.g. `struct Foo(...);`). (active, const_generics_defaults, "1.51.0", Some(44580), None), diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 5635fbbb978ea..0c43e304f1ee2 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -61,7 +61,7 @@ impl<'a> Parser<'a> { }, _ => false, }, - NonterminalKind::PatParam { .. } | NonterminalKind::Pat2021 { .. } => { + NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => { match token.kind { token::Ident(..) | // box, ref, mut, and other identifiers (can stricten) token::OpenDelim(token::Paren) | // tuple pattern @@ -76,7 +76,7 @@ impl<'a> Parser<'a> { token::Lt | // path (UFCS constant) token::BinOp(token::Shl) => true, // path (double UFCS) // leading vert `|` or-pattern - token::BinOp(token::Or) => matches!(kind, NonterminalKind::Pat2021 {..}), + token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr {..}), token::Interpolated(ref nt) => may_be_ident(nt), _ => false, } @@ -120,10 +120,10 @@ impl<'a> Parser<'a> { return Err(self.struct_span_err(self.token.span, "expected a statement")); } }, - NonterminalKind::PatParam { .. } | NonterminalKind::Pat2021 { .. } => { + NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => { token::NtPat(self.collect_tokens_no_attrs(|this| match kind { NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None), - NonterminalKind::Pat2021 { .. } => { + NonterminalKind::PatWithOr { .. } => { this.parse_pat_allow_top_alt(None, RecoverComma::No) } _ => unreachable!(), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index db0d0b9966c94..a7f493569d32a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -849,7 +849,6 @@ symbols! { partial_ord, passes, pat, - pat2021, pat_param, path, pattern_parentheses, diff --git a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs deleted file mode 100644 index fdd8626c760b1..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Feature gate test for `edition_macro_pats` feature. - -macro_rules! foo { - ($x:pat_param) => {}; // ok - ($x:pat2021) => {}; //~ERROR `pat2021` is unstable -} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr b/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr deleted file mode 100644 index dc1f52d87a820..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `pat2021` is unstable. - --> $DIR/feature-gate-edition_macro_pats.rs:5:9 - | -LL | ($x:pat2021) => {}; - | ^^^^^^^ - | - = note: see issue #54883 for more information - = help: add `#![feature(edition_macro_pats)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/macros/edition-macro-pats.rs b/src/test/ui/macros/edition-macro-pats.rs index 963a9c01a3b69..040894712a8ca 100644 --- a/src/test/ui/macros/edition-macro-pats.rs +++ b/src/test/ui/macros/edition-macro-pats.rs @@ -1,10 +1,9 @@ // run-pass - -#![feature(edition_macro_pats)] +// edition:2021 macro_rules! foo { (a $x:pat_param) => {}; - (b $x:pat2021) => {}; + (b $x:pat) => {}; } fn main() { diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.fixed b/src/test/ui/macros/macro-or-patterns-back-compat.fixed index e0bd4cdde24d1..f829129d516b2 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.fixed +++ b/src/test/ui/macros/macro-or-patterns-back-compat.fixed @@ -1,6 +1,5 @@ // run-rustfix -#![feature(edition_macro_pats)] #![deny(or_patterns_back_compat)] #![allow(unused_macros)] macro_rules! foo { ($x:pat_param | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.rs b/src/test/ui/macros/macro-or-patterns-back-compat.rs index 9ff072dc3235f..1cdaa1cd6317b 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.rs +++ b/src/test/ui/macros/macro-or-patterns-back-compat.rs @@ -1,6 +1,5 @@ // run-rustfix -#![feature(edition_macro_pats)] #![deny(or_patterns_back_compat)] #![allow(unused_macros)] macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.stderr b/src/test/ui/macros/macro-or-patterns-back-compat.stderr index 970f62f6cff48..01d220dd0b114 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.stderr +++ b/src/test/ui/macros/macro-or-patterns-back-compat.stderr @@ -1,29 +1,29 @@ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:6:21 + --> $DIR/macro-or-patterns-back-compat.rs:5:21 | LL | macro_rules! foo { ($x:pat | $y:pat) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` | note: the lint level is defined here - --> $DIR/macro-or-patterns-back-compat.rs:4:9 + --> $DIR/macro-or-patterns-back-compat.rs:3:9 | LL | #![deny(or_patterns_back_compat)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:7:23 + --> $DIR/macro-or-patterns-back-compat.rs:6:23 | LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:10:21 + --> $DIR/macro-or-patterns-back-compat.rs:9:21 | LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:12:26 + --> $DIR/macro-or-patterns-back-compat.rs:11:26 | LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { | ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param` diff --git a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs index 1b8189e094842..b4be03aaddd58 100644 --- a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs +++ b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs @@ -1,11 +1,12 @@ -#![feature(edition_macro_pats)] +// edition:2021 + #![allow(unused_macros)] -macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments +macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok -macro_rules! qux { ($x:pat_param | $y:pat2021) => {} } // should be ok -macro_rules! ogg { ($x:pat2021 | $y:pat_param) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments +macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok +macro_rules! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments macro_rules! match_any { - ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments + ( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments match $expr { $( $( $pat => $expr_arm, )+ diff --git a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr index e74e8870806e3..8aebe98515f4d 100644 --- a/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr +++ b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr @@ -1,24 +1,24 @@ -error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments - --> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32 +error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:4:28 | -LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } - | ^ not allowed after `pat2021` fragments +LL | macro_rules! foo { ($x:pat | $y:pat) => {} } + | ^ not allowed after `pat` fragments | = note: allowed there are: `=>`, `,`, `=`, `if` or `in` -error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments - --> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32 +error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:7:28 | -LL | macro_rules! ogg { ($x:pat2021 | $y:pat_param) => {} } - | ^ not allowed after `pat2021` fragments +LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} } + | ^ not allowed after `pat` fragments | = note: allowed there are: `=>`, `,`, `=`, `if` or `in` -error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments - --> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40 +error: `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:9:35 | -LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { - | ^ not allowed after `pat2021` fragments +LL | ( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => { + | ^ not allowed after `pat` fragments | = note: allowed there are: `=>`, `,`, `=`, `if` or `in`