Skip to content

Commit ca075d2

Browse files
committed
Auto merge of rust-lang#83386 - mark-i-m:stabilize-pat2015, r=nikomatsakis
Stabilize `:pat_param` and remove `:pat2021` Blocked on rust-lang#83384 cc `@rust-lang/lang` rust-lang#79278 If I understand `@nikomatsakis` in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/or.20patterns/near/231133873, another FCP is not needed. r? `@nikomatsakis`
2 parents da43ee8 + 2a9db91 commit ca075d2

15 files changed

+66
-121
lines changed

compiler/rustc_ast/src/token.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,12 @@ pub enum NonterminalKind {
688688
Item,
689689
Block,
690690
Stmt,
691-
Pat2015 {
692-
/// Keep track of whether the user used `:pat2015` or `:pat` and we inferred it from the
693-
/// edition of the span. This is used for diagnostics.
694-
inferred: bool,
695-
},
696-
Pat2021 {
697-
/// Keep track of whether the user used `:pat2015` or `:pat` and we inferred it from the
691+
PatParam {
692+
/// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the
698693
/// edition of the span. This is used for diagnostics.
699694
inferred: bool,
700695
},
696+
PatWithOr,
701697
Expr,
702698
Ty,
703699
Ident,
@@ -722,12 +718,11 @@ impl NonterminalKind {
722718
sym::stmt => NonterminalKind::Stmt,
723719
sym::pat => match edition() {
724720
Edition::Edition2015 | Edition::Edition2018 => {
725-
NonterminalKind::Pat2015 { inferred: true }
721+
NonterminalKind::PatParam { inferred: true }
726722
}
727-
Edition::Edition2021 => NonterminalKind::Pat2021 { inferred: true },
723+
Edition::Edition2021 => NonterminalKind::PatWithOr,
728724
},
729-
sym::pat2015 => NonterminalKind::Pat2015 { inferred: false },
730-
sym::pat2021 => NonterminalKind::Pat2021 { inferred: false },
725+
sym::pat_param => NonterminalKind::PatParam { inferred: false },
731726
sym::expr => NonterminalKind::Expr,
732727
sym::ty => NonterminalKind::Ty,
733728
sym::ident => NonterminalKind::Ident,
@@ -745,10 +740,8 @@ impl NonterminalKind {
745740
NonterminalKind::Item => sym::item,
746741
NonterminalKind::Block => sym::block,
747742
NonterminalKind::Stmt => sym::stmt,
748-
NonterminalKind::Pat2015 { inferred: false } => sym::pat2015,
749-
NonterminalKind::Pat2021 { inferred: false } => sym::pat2021,
750-
NonterminalKind::Pat2015 { inferred: true }
751-
| NonterminalKind::Pat2021 { inferred: true } => sym::pat,
743+
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
744+
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
752745
NonterminalKind::Expr => sym::expr,
753746
NonterminalKind::Ty => sym::ty,
754747
NonterminalKind::Ident => sym::ident,

compiler/rustc_expand/src/mbe/macro_rules.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -955,15 +955,15 @@ fn check_matcher_core(
955955
if let TokenTree::MetaVarDecl(span, name, Some(kind)) = *token {
956956
for next_token in &suffix_first.tokens {
957957
// Check if the old pat is used and the next token is `|`.
958-
if let NonterminalKind::Pat2015 { inferred: true } = kind {
958+
if let NonterminalKind::PatParam { inferred: true } = kind {
959959
if let TokenTree::Token(token) = next_token {
960960
if let BinOp(token) = token.kind {
961961
if let token::BinOpToken::Or = token {
962-
// It is suggestion to use pat2015, for example: $x:pat -> $x:pat2015.
962+
// It is suggestion to use pat_param, for example: $x:pat -> $x:pat_param.
963963
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
964964
span,
965965
name,
966-
Some(NonterminalKind::Pat2015 { inferred: false }),
966+
Some(NonterminalKind::PatParam { inferred: false }),
967967
));
968968
sess.buffer_lint_with_diagnostic(
969969
&OR_PATTERNS_BACK_COMPAT,
@@ -1105,7 +1105,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
11051105
_ => IsInFollow::No(TOKENS),
11061106
}
11071107
}
1108-
NonterminalKind::Pat2015 { .. } => {
1108+
NonterminalKind::PatParam { .. } => {
11091109
const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"];
11101110
match tok {
11111111
TokenTree::Token(token) => match token.kind {
@@ -1116,7 +1116,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
11161116
_ => IsInFollow::No(TOKENS),
11171117
}
11181118
}
1119-
NonterminalKind::Pat2021 { .. } => {
1119+
NonterminalKind::PatWithOr { .. } => {
11201120
const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`if`", "`in`"];
11211121
match tok {
11221122
TokenTree::Token(token) => match token.kind {

compiler/rustc_expand/src/mbe/quoted.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_ast::tokenstream;
66
use rustc_ast::{NodeId, DUMMY_NODE_ID};
77
use rustc_ast_pretty::pprust;
88
use rustc_feature::Features;
9-
use rustc_session::parse::{feature_err, ParseSess};
10-
use rustc_span::symbol::{kw, sym, Ident};
9+
use rustc_session::parse::ParseSess;
10+
use rustc_span::symbol::{kw, Ident};
1111

1212
use rustc_span::Span;
1313

@@ -62,21 +62,6 @@ pub(super) fn parse(
6262
Some((frag, _)) => {
6363
let span = token.span.with_lo(start_sp.lo());
6464

65-
match frag.name {
66-
sym::pat2015 | sym::pat2021 => {
67-
if !features.edition_macro_pats {
68-
feature_err(
69-
sess,
70-
sym::edition_macro_pats,
71-
frag.span,
72-
"`pat2015` and `pat2021` are unstable.",
73-
)
74-
.emit();
75-
}
76-
}
77-
_ => {}
78-
}
79-
8065
let kind =
8166
token::NonterminalKind::from_symbol(frag.name, || {
8267
span.edition()

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,6 @@ declare_features! (
607607
/// Allows arbitrary expressions in key-value attributes at parse time.
608608
(active, extended_key_value_attributes, "1.50.0", Some(78835), None),
609609

610-
/// `:pat2015` and `:pat2021` macro matchers.
611-
(active, edition_macro_pats, "1.51.0", Some(54883), None),
612-
613610
/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
614611
(active, const_generics_defaults, "1.51.0", Some(44580), None),
615612

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ pub trait LintContext: Sized {
710710
db.note(&note);
711711
}
712712
BuiltinLintDiagnostics::OrPatternsBackCompat(span,suggestion) => {
713-
db.span_suggestion(span, "use pat2015 to preserve semantics", suggestion, Applicability::MachineApplicable);
713+
db.span_suggestion(span, "use pat_param to preserve semantics", suggestion, Applicability::MachineApplicable);
714714
}
715715
}
716716
// Rewrap `db`, and pass control to the user.

compiler/rustc_parse/src/parser/nonterminal.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ impl<'a> Parser<'a> {
6161
},
6262
_ => false,
6363
},
64-
NonterminalKind::Pat2015 { .. } | NonterminalKind::Pat2021 { .. } => match token.kind {
64+
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
65+
match token.kind {
6566
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
6667
token::OpenDelim(token::Paren) | // tuple pattern
6768
token::OpenDelim(token::Bracket) | // slice pattern
@@ -75,10 +76,11 @@ impl<'a> Parser<'a> {
7576
token::Lt | // path (UFCS constant)
7677
token::BinOp(token::Shl) => true, // path (double UFCS)
7778
// leading vert `|` or-pattern
78-
token::BinOp(token::Or) => matches!(kind, NonterminalKind::Pat2021 {..}),
79+
token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr {..}),
7980
token::Interpolated(ref nt) => may_be_ident(nt),
8081
_ => false,
81-
},
82+
}
83+
}
8284
NonterminalKind::Lifetime => match token.kind {
8385
token::Lifetime(_) => true,
8486
token::Interpolated(ref nt) => {
@@ -118,10 +120,10 @@ impl<'a> Parser<'a> {
118120
return Err(self.struct_span_err(self.token.span, "expected a statement"));
119121
}
120122
},
121-
NonterminalKind::Pat2015 { .. } | NonterminalKind::Pat2021 { .. } => {
123+
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
122124
token::NtPat(self.collect_tokens_no_attrs(|this| match kind {
123-
NonterminalKind::Pat2015 { .. } => this.parse_pat_no_top_alt(None),
124-
NonterminalKind::Pat2021 { .. } => {
125+
NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None),
126+
NonterminalKind::PatWithOr { .. } => {
125127
this.parse_pat_allow_top_alt(None, RecoverComma::No)
126128
}
127129
_ => unreachable!(),

compiler/rustc_span/src/symbol.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,7 @@ symbols! {
853853
partial_ord,
854854
passes,
855855
pat,
856-
pat2015,
857-
pat2021,
856+
pat_param,
858857
path,
859858
pattern_parentheses,
860859
phantom_data,

src/test/ui/feature-gates/feature-gate-edition_macro_pats.rs

-8
This file was deleted.

src/test/ui/feature-gates/feature-gate-edition_macro_pats.stderr

-21
This file was deleted.

src/test/ui/macros/edition-macro-pats.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// run-pass
2-
3-
#![feature(edition_macro_pats)]
2+
// edition:2021
43

54
macro_rules! foo {
6-
(a $x:pat2015) => {};
7-
(b $x:pat2021) => {};
5+
(a $x:pat_param) => {};
6+
(b $x:pat) => {};
87
}
98

109
fn main() {

src/test/ui/macros/macro-or-patterns-back-compat.fixed

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// run-rustfix
22

3-
#![feature(edition_macro_pats)]
43
#![deny(or_patterns_back_compat)]
54
#![allow(unused_macros)]
6-
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
7-
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
8-
macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok
9-
macro_rules! qux { ($x:pat2015 | $y:pat) => {} } // should be ok
10-
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
5+
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
6+
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
7+
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
8+
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
9+
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
1110
macro_rules! match_any {
12-
( $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
11+
( $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
1312
match $expr {
1413
$(
1514
$( $pat => $expr_arm, )+

src/test/ui/macros/macro-or-patterns-back-compat.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// run-rustfix
22

3-
#![feature(edition_macro_pats)]
43
#![deny(or_patterns_back_compat)]
54
#![allow(unused_macros)]
65
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
76
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
8-
macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok
9-
macro_rules! qux { ($x:pat2015 | $y:pat) => {} } // should be ok
10-
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
7+
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
8+
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
9+
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
1110
macro_rules! match_any {
1211
( $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
1312
match $expr {
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
2-
--> $DIR/macro-or-patterns-back-compat.rs:6:21
2+
--> $DIR/macro-or-patterns-back-compat.rs:5:21
33
|
44
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
5-
| ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015`
5+
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
66
|
77
note: the lint level is defined here
8-
--> $DIR/macro-or-patterns-back-compat.rs:4:9
8+
--> $DIR/macro-or-patterns-back-compat.rs:3:9
99
|
1010
LL | #![deny(or_patterns_back_compat)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
14-
--> $DIR/macro-or-patterns-back-compat.rs:7:23
14+
--> $DIR/macro-or-patterns-back-compat.rs:6:23
1515
|
1616
LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} }
17-
| ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015`
17+
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
1818

1919
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
20-
--> $DIR/macro-or-patterns-back-compat.rs:10:21
20+
--> $DIR/macro-or-patterns-back-compat.rs:9:21
2121
|
22-
LL | macro_rules! ogg { ($x:pat | $y:pat2015) => {} }
23-
| ^^^^^^ help: use pat2015 to preserve semantics: `$x:pat2015`
22+
LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
23+
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
2424

2525
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
26-
--> $DIR/macro-or-patterns-back-compat.rs:12:26
26+
--> $DIR/macro-or-patterns-back-compat.rs:11:26
2727
|
2828
LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
29-
| ^^^^^^^^ help: use pat2015 to preserve semantics: `$pat:pat2015`
29+
| ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param`
3030

3131
error: aborting due to 4 previous errors
3232

src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#![feature(edition_macro_pats)]
1+
// edition:2021
2+
23
#![allow(unused_macros)]
3-
macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
4-
macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok
5-
macro_rules! qux { ($x:pat2015 | $y:pat2021) => {} } // should be ok
6-
macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
4+
macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
5+
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
6+
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
7+
macro_rules! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
78
macro_rules! match_any {
8-
( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
9+
( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments
910
match $expr {
1011
$(
1112
$( $pat => $expr_arm, )+

src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
2-
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32
1+
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
2+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:4:28
33
|
4-
LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} }
5-
| ^ not allowed after `pat2021` fragments
4+
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
5+
| ^ not allowed after `pat` fragments
66
|
77
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
88

9-
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
10-
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32
9+
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
10+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:7:28
1111
|
12-
LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} }
13-
| ^ not allowed after `pat2021` fragments
12+
LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
13+
| ^ not allowed after `pat` fragments
1414
|
1515
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
1616

17-
error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
18-
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40
17+
error: `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments
18+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:9:35
1919
|
20-
LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => {
21-
| ^ not allowed after `pat2021` fragments
20+
LL | ( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => {
21+
| ^ not allowed after `pat` fragments
2222
|
2323
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
2424

0 commit comments

Comments
 (0)