Skip to content

Commit ee3e9ac

Browse files
authored
Rollup merge of rust-lang#47947 - goodmanjonathan:stabilize_match_beginning_vert, r=petrochenkov
Stabilize feature(match_beginning_vert) With this feature stabilized, match expressions can optionally have a `|` at the beginning of each arm. Reference PR: rust-lang/reference#231 Closes rust-lang#44101
2 parents 4655895 + a99b5db commit ee3e9ac

File tree

9 files changed

+32
-103
lines changed

9 files changed

+32
-103
lines changed

src/doc/unstable-book/src/language-features/match-beginning-vert.md

-23
This file was deleted.

src/libsyntax/ast.rs

-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ pub struct Arm {
883883
pub pats: Vec<P<Pat>>,
884884
pub guard: Option<P<Expr>>,
885885
pub body: P<Expr>,
886-
pub beginning_vert: Option<Span>, // For RFC 1925 feature gate
887886
}
888887

889888
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

src/libsyntax/ext/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
883883
pats,
884884
guard: None,
885885
body: expr,
886-
beginning_vert: None,
887886
}
888887
}
889888

src/libsyntax/feature_gate.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,6 @@ declare_features! (
386386
// allow `#[must_use]` on functions and comparison operators (RFC 1940)
387387
(active, fn_must_use, "1.21.0", Some(43302)),
388388

389-
// allow '|' at beginning of match arms (RFC 1925)
390-
(active, match_beginning_vert, "1.21.0", Some(44101)),
391-
392389
// Future-proofing enums/structs with #[non_exhaustive] attribute (RFC 2008)
393390
(active, non_exhaustive, "1.22.0", Some(44109)),
394391

@@ -545,6 +542,8 @@ declare_features! (
545542
(accepted, abi_sysv64, "1.24.0", Some(36167)),
546543
// Allows `repr(align(16))` struct attribute (RFC 1358)
547544
(accepted, repr_align, "1.24.0", Some(33626)),
545+
// allow '|' at beginning of match arms (RFC 1925)
546+
(accepted, match_beginning_vert, "1.25.0", Some(44101)),
548547
);
549548

550549
// If you change this, please modify src/doc/unstable-book as well. You must
@@ -1683,11 +1682,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16831682
}
16841683

16851684
fn visit_arm(&mut self, arm: &'a ast::Arm) {
1686-
if let Some(span) = arm.beginning_vert {
1687-
gate_feature_post!(&self, match_beginning_vert,
1688-
span,
1689-
"Use of a '|' at the beginning of a match arm is experimental")
1690-
}
16911685
visit::walk_arm(self, arm)
16921686
}
16931687

src/libsyntax/fold.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,13 @@ pub fn fold_thin_attrs<T: Folder>(attrs: ThinVec<Attribute>, fld: &mut T) -> Thi
340340
fold_attrs(attrs.into(), fld).into()
341341
}
342342

343-
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body, beginning_vert}: Arm,
343+
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm,
344344
fld: &mut T) -> Arm {
345345
Arm {
346346
attrs: fold_attrs(attrs, fld),
347347
pats: pats.move_map(|x| fld.fold_pat(x)),
348348
guard: guard.map(|x| fld.fold_expr(x)),
349349
body: fld.fold_expr(body),
350-
beginning_vert,
351350
}
352351
}
353352

src/libsyntax/parse/parser.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -3398,11 +3398,7 @@ impl<'a> Parser<'a> {
33983398

33993399
let attrs = self.parse_outer_attributes()?;
34003400
// Allow a '|' before the pats (RFC 1925)
3401-
let beginning_vert = if self.eat(&token::BinOp(token::Or)) {
3402-
Some(self.prev_span)
3403-
} else {
3404-
None
3405-
};
3401+
self.eat(&token::BinOp(token::Or));
34063402
let pats = self.parse_pats()?;
34073403
let guard = if self.eat_keyword(keywords::If) {
34083404
Some(self.parse_expr()?)
@@ -3426,7 +3422,6 @@ impl<'a> Parser<'a> {
34263422
pats,
34273423
guard,
34283424
body: expr,
3429-
beginning_vert,
34303425
})
34313426
}
34323427

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Foo {
12+
A,
13+
B,
14+
C,
15+
D,
16+
E,
17+
}
18+
use Foo::*;
19+
20+
fn main() {
21+
for foo in &[A, B, C, D, E] {
22+
match *foo {
23+
| A => println!("A"),
24+
| B | C if 1 < 2 => println!("BC!"),
25+
| _ => {},
26+
}
27+
}
28+
}

src/test/ui/feature-gate-match_beginning_vert.rs

-36
This file was deleted.

src/test/ui/feature-gate-match_beginning_vert.stderr

-26
This file was deleted.

0 commit comments

Comments
 (0)