diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 4735ebae9d42e8ef61b33bf7a7d477ee10c56729..9395da60b3886f0d1debb676f1dfcf445e25f2bf 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -24,7 +24,7 @@ #![feature(unicode_internals)] #![feature(step_trait)] #![feature(slice_concat_ext)] -#![feature(if_while_or_patterns)] +#![cfg_attr(stage0, feature(if_while_or_patterns))] #![feature(try_from)] #![feature(reverse_bits)] #![cfg_attr(stage0, feature(underscore_imports))] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index cddec3eb23a5a3c53b16cde059f4ded7cb22044f..45b3ba604c62f8e5bfa2c54810ef916fb26174fc 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -384,9 +384,6 @@ pub fn walk_feature_fields(&self, mut f: F) // Infer static outlives requirements (RFC 2093). (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None), - // Multiple patterns with `|` in `if let` and `while let`. - (active, if_while_or_patterns, "1.26.0", Some(48215), None), - // Allows macro invocations in `extern {}` blocks. (active, macros_in_extern, "1.27.0", Some(49476), None), @@ -688,6 +685,8 @@ pub fn walk_feature_fields(&self, mut f: F) (accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None), // `#[cfg_attr(predicate, multiple, attributes, here)]` (accepted, cfg_attr_multi, "1.33.0", Some(54881), None), + // Top level or-patterns (`p | q`) in `if let` and `while let`. + (accepted, if_while_or_patterns, "1.33.0", Some(48215), None), ); // If you change this, please modify `src/doc/unstable-book` as well. You must @@ -1701,12 +1700,6 @@ fn visit_expr(&mut self, e: &'a ast::Expr) { ast::ExprKind::TryBlock(_) => { gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental"); } - ast::ExprKind::IfLet(ref pats, ..) | ast::ExprKind::WhileLet(ref pats, ..) => { - if pats.len() > 1 { - gate_feature_post!(&self, if_while_or_patterns, e.span, - "multiple patterns in `if let` and `while let` are unstable"); - } - } ast::ExprKind::Block(_, opt_label) => { if let Some(label) = opt_label { gate_feature_post!(&self, label_break_value, label.ident.span, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1e4a26b353759ab244289f2b1845e400627618f4..b90eeaca54b9777ad09f3a4b02538971318de24f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3660,8 +3660,6 @@ fn parse_match_expr(&mut self, mut attrs: ThinVec) -> PResult<'a, P PResult<'a, Option>> { /// Parse patterns, separated by '|' s fn parse_pats(&mut self) -> PResult<'a, Vec>> { + // Allow a '|' before the pats (RFC 1925 + RFC 2530) + self.eat(&token::BinOp(token::Or)); + let mut pats = Vec::new(); loop { pats.push(self.parse_top_level_pat()?); diff --git a/src/test/run-pass/rfcs/rfc-2175-or-if-while-let/basic.rs b/src/test/run-pass/rfcs/rfc-2175-or-if-while-let/basic.rs index f9bd2f471ae9dac755f84c9430d475e63f4391c4..22f04c58f3b3c3c35865633f3420fe405efd7deb 100644 --- a/src/test/run-pass/rfcs/rfc-2175-or-if-while-let/basic.rs +++ b/src/test/run-pass/rfcs/rfc-2175-or-if-while-let/basic.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code)] -#![feature(if_while_or_patterns)] enum E { V(u8), @@ -19,4 +18,16 @@ fn main() { assert_eq!(x, 10); e = W; } + + // Accept leading `|`: + + let mut e = V(10); + + if let | V(x) | U(x) = e { + assert_eq!(x, 10); + } + while let | V(x) | U(x) = e { + assert_eq!(x, 10); + e = W; + } } diff --git a/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.rs b/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.rs deleted file mode 100644 index 233185f92e3f50bc5d19d847f74db55678b895ab..0000000000000000000000000000000000000000 --- a/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - if let 0 | 1 = 0 { //~ ERROR multiple patterns in `if let` and `while let` are unstable - ; - } - while let 0 | 1 = 1 { //~ ERROR multiple patterns in `if let` and `while let` are unstable - break; - } -} diff --git a/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.stderr b/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.stderr deleted file mode 100644 index ff991819a92186a9aa1c8cf008ae72c5e0c7753e..0000000000000000000000000000000000000000 --- a/src/test/ui/feature-gates/feature-gate-if_while_or_patterns.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0658]: multiple patterns in `if let` and `while let` are unstable (see issue #48215) - --> $DIR/feature-gate-if_while_or_patterns.rs:2:5 - | -LL | / if let 0 | 1 = 0 { //~ ERROR multiple patterns in `if let` and `while let` are unstable -LL | | ; -LL | | } - | |_____^ - | - = help: add #![feature(if_while_or_patterns)] to the crate attributes to enable - -error[E0658]: multiple patterns in `if let` and `while let` are unstable (see issue #48215) - --> $DIR/feature-gate-if_while_or_patterns.rs:5:5 - | -LL | / while let 0 | 1 = 1 { //~ ERROR multiple patterns in `if let` and `while let` are unstable -LL | | break; -LL | | } - | |_____^ - | - = help: add #![feature(if_while_or_patterns)] to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`.