remove pat2021
This commit is contained in:
parent
3f7b98ebe0
commit
2a9db919ff
14 changed files with 35 additions and 80 deletions
|
@ -693,11 +693,7 @@ pub enum NonterminalKind {
|
||||||
/// edition of the span. This is used for diagnostics.
|
/// edition of the span. This is used for diagnostics.
|
||||||
inferred: bool,
|
inferred: bool,
|
||||||
},
|
},
|
||||||
Pat2021 {
|
PatWithOr,
|
||||||
/// 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,
|
|
||||||
},
|
|
||||||
Expr,
|
Expr,
|
||||||
Ty,
|
Ty,
|
||||||
Ident,
|
Ident,
|
||||||
|
@ -724,10 +720,9 @@ impl NonterminalKind {
|
||||||
Edition::Edition2015 | Edition::Edition2018 => {
|
Edition::Edition2015 | Edition::Edition2018 => {
|
||||||
NonterminalKind::PatParam { inferred: true }
|
NonterminalKind::PatParam { inferred: true }
|
||||||
}
|
}
|
||||||
Edition::Edition2021 => NonterminalKind::Pat2021 { inferred: true },
|
Edition::Edition2021 => NonterminalKind::PatWithOr,
|
||||||
},
|
},
|
||||||
sym::pat_param => NonterminalKind::PatParam { inferred: false },
|
sym::pat_param => NonterminalKind::PatParam { inferred: false },
|
||||||
sym::pat2021 => NonterminalKind::Pat2021 { inferred: false },
|
|
||||||
sym::expr => NonterminalKind::Expr,
|
sym::expr => NonterminalKind::Expr,
|
||||||
sym::ty => NonterminalKind::Ty,
|
sym::ty => NonterminalKind::Ty,
|
||||||
sym::ident => NonterminalKind::Ident,
|
sym::ident => NonterminalKind::Ident,
|
||||||
|
@ -746,9 +741,7 @@ impl NonterminalKind {
|
||||||
NonterminalKind::Block => sym::block,
|
NonterminalKind::Block => sym::block,
|
||||||
NonterminalKind::Stmt => sym::stmt,
|
NonterminalKind::Stmt => sym::stmt,
|
||||||
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
|
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
|
||||||
NonterminalKind::Pat2021 { inferred: false } => sym::pat2021,
|
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
|
||||||
NonterminalKind::PatParam { inferred: true }
|
|
||||||
| NonterminalKind::Pat2021 { inferred: true } => sym::pat,
|
|
||||||
NonterminalKind::Expr => sym::expr,
|
NonterminalKind::Expr => sym::expr,
|
||||||
NonterminalKind::Ty => sym::ty,
|
NonterminalKind::Ty => sym::ty,
|
||||||
NonterminalKind::Ident => sym::ident,
|
NonterminalKind::Ident => sym::ident,
|
||||||
|
|
|
@ -1116,7 +1116,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
|
||||||
_ => IsInFollow::No(TOKENS),
|
_ => IsInFollow::No(TOKENS),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NonterminalKind::Pat2021 { .. } => {
|
NonterminalKind::PatWithOr { .. } => {
|
||||||
const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`if`", "`in`"];
|
const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`if`", "`in`"];
|
||||||
match tok {
|
match tok {
|
||||||
TokenTree::Token(token) => match token.kind {
|
TokenTree::Token(token) => match token.kind {
|
||||||
|
|
|
@ -6,8 +6,8 @@ use rustc_ast::tokenstream;
|
||||||
use rustc_ast::{NodeId, DUMMY_NODE_ID};
|
use rustc_ast::{NodeId, DUMMY_NODE_ID};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_feature::Features;
|
use rustc_feature::Features;
|
||||||
use rustc_session::parse::{feature_err, ParseSess};
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, Ident};
|
||||||
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -62,18 +62,6 @@ pub(super) fn parse(
|
||||||
Some((frag, _)) => {
|
Some((frag, _)) => {
|
||||||
let span = token.span.with_lo(start_sp.lo());
|
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 =
|
let kind =
|
||||||
token::NonterminalKind::from_symbol(frag.name, || {
|
token::NonterminalKind::from_symbol(frag.name, || {
|
||||||
span.edition()
|
span.edition()
|
||||||
|
|
|
@ -609,9 +609,6 @@ declare_features! (
|
||||||
/// Allows arbitrary expressions in key-value attributes at parse time.
|
/// Allows arbitrary expressions in key-value attributes at parse time.
|
||||||
(active, extended_key_value_attributes, "1.50.0", Some(78835), None),
|
(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<const N: usize = 3>(...);`).
|
/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
|
||||||
(active, const_generics_defaults, "1.51.0", Some(44580), None),
|
(active, const_generics_defaults, "1.51.0", Some(44580), None),
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl<'a> Parser<'a> {
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
NonterminalKind::PatParam { .. } | NonterminalKind::Pat2021 { .. } => {
|
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
|
||||||
match token.kind {
|
match token.kind {
|
||||||
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
||||||
token::OpenDelim(token::Paren) | // tuple pattern
|
token::OpenDelim(token::Paren) | // tuple pattern
|
||||||
|
@ -76,7 +76,7 @@ impl<'a> Parser<'a> {
|
||||||
token::Lt | // path (UFCS constant)
|
token::Lt | // path (UFCS constant)
|
||||||
token::BinOp(token::Shl) => true, // path (double UFCS)
|
token::BinOp(token::Shl) => true, // path (double UFCS)
|
||||||
// leading vert `|` or-pattern
|
// 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),
|
token::Interpolated(ref nt) => may_be_ident(nt),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -120,10 +120,10 @@ impl<'a> Parser<'a> {
|
||||||
return Err(self.struct_span_err(self.token.span, "expected a statement"));
|
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 {
|
token::NtPat(self.collect_tokens_no_attrs(|this| match kind {
|
||||||
NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None),
|
NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None),
|
||||||
NonterminalKind::Pat2021 { .. } => {
|
NonterminalKind::PatWithOr { .. } => {
|
||||||
this.parse_pat_allow_top_alt(None, RecoverComma::No)
|
this.parse_pat_allow_top_alt(None, RecoverComma::No)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
|
@ -849,7 +849,6 @@ symbols! {
|
||||||
partial_ord,
|
partial_ord,
|
||||||
passes,
|
passes,
|
||||||
pat,
|
pat,
|
||||||
pat2021,
|
|
||||||
pat_param,
|
pat_param,
|
||||||
path,
|
path,
|
||||||
pattern_parentheses,
|
pattern_parentheses,
|
||||||
|
|
|
@ -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() {}
|
|
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
|
|
@ -1,10 +1,9 @@
|
||||||
// run-pass
|
// run-pass
|
||||||
|
// edition:2021
|
||||||
#![feature(edition_macro_pats)]
|
|
||||||
|
|
||||||
macro_rules! foo {
|
macro_rules! foo {
|
||||||
(a $x:pat_param) => {};
|
(a $x:pat_param) => {};
|
||||||
(b $x:pat2021) => {};
|
(b $x:pat) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
#![feature(edition_macro_pats)]
|
|
||||||
#![deny(or_patterns_back_compat)]
|
#![deny(or_patterns_back_compat)]
|
||||||
#![allow(unused_macros)]
|
#![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
|
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
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
#![feature(edition_macro_pats)]
|
|
||||||
#![deny(or_patterns_back_compat)]
|
#![deny(or_patterns_back_compat)]
|
||||||
#![allow(unused_macros)]
|
#![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! foo { ($x:pat | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
|
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) => {} }
|
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
|
||||||
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
|
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
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)]
|
LL | #![deny(or_patterns_back_compat)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
|
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)+) => {} }
|
LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} }
|
||||||
| ^^^^^^ help: use pat_param to preserve semantics: `$x: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
|
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) => {} }
|
LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
|
||||||
| ^^^^^^ help: use pat_param to preserve semantics: `$x: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
|
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 ),+ ) => {
|
LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
|
||||||
| ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param`
|
| ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param`
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#![feature(edition_macro_pats)]
|
// edition:2021
|
||||||
|
|
||||||
#![allow(unused_macros)]
|
#![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! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
|
||||||
macro_rules! qux { ($x:pat_param | $y:pat2021) => {} } // should be ok
|
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // 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! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
|
||||||
macro_rules! match_any {
|
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 {
|
match $expr {
|
||||||
$(
|
$(
|
||||||
$( $pat => $expr_arm, )+
|
$( $pat => $expr_arm, )+
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
|
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
|
||||||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32
|
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:4:28
|
||||||
|
|
|
|
||||||
LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} }
|
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
|
||||||
| ^ not allowed after `pat2021` fragments
|
| ^ not allowed after `pat` fragments
|
||||||
|
|
|
|
||||||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
||||||
|
|
||||||
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
|
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
|
||||||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32
|
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:7:28
|
||||||
|
|
|
|
||||||
LL | macro_rules! ogg { ($x:pat2021 | $y:pat_param) => {} }
|
LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
|
||||||
| ^ not allowed after `pat2021` fragments
|
| ^ not allowed after `pat` fragments
|
||||||
|
|
|
|
||||||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
||||||
|
|
||||||
error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
|
error: `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments
|
||||||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40
|
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:9:35
|
||||||
|
|
|
|
||||||
LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => {
|
LL | ( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => {
|
||||||
| ^ not allowed after `pat2021` fragments
|
| ^ not allowed after `pat` fragments
|
||||||
|
|
|
|
||||||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue