stabilize top level or-pats in if/while let.
This commit is contained in:
parent
b43986184b
commit
561483e4e8
6 changed files with 18 additions and 44 deletions
|
@ -24,7 +24,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
||||||
#![feature(unicode_internals)]
|
#![feature(unicode_internals)]
|
||||||
#![feature(step_trait)]
|
#![feature(step_trait)]
|
||||||
#![feature(slice_concat_ext)]
|
#![feature(slice_concat_ext)]
|
||||||
#![feature(if_while_or_patterns)]
|
#![cfg_attr(stage0, feature(if_while_or_patterns))]
|
||||||
#![feature(try_from)]
|
#![feature(try_from)]
|
||||||
#![feature(reverse_bits)]
|
#![feature(reverse_bits)]
|
||||||
#![cfg_attr(stage0, feature(underscore_imports))]
|
#![cfg_attr(stage0, feature(underscore_imports))]
|
||||||
|
|
|
@ -384,9 +384,6 @@ declare_features! (
|
||||||
// Infer static outlives requirements (RFC 2093).
|
// Infer static outlives requirements (RFC 2093).
|
||||||
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
|
(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.
|
// Allows macro invocations in `extern {}` blocks.
|
||||||
(active, macros_in_extern, "1.27.0", Some(49476), None),
|
(active, macros_in_extern, "1.27.0", Some(49476), None),
|
||||||
|
|
||||||
|
@ -688,6 +685,8 @@ declare_features! (
|
||||||
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None),
|
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None),
|
||||||
// `#[cfg_attr(predicate, multiple, attributes, here)]`
|
// `#[cfg_attr(predicate, multiple, attributes, here)]`
|
||||||
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
|
(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
|
// If you change this, please modify `src/doc/unstable-book` as well. You must
|
||||||
|
@ -1701,12 +1700,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
ast::ExprKind::TryBlock(_) => {
|
ast::ExprKind::TryBlock(_) => {
|
||||||
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
|
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) => {
|
ast::ExprKind::Block(_, opt_label) => {
|
||||||
if let Some(label) = opt_label {
|
if let Some(label) = opt_label {
|
||||||
gate_feature_post!(&self, label_break_value, label.ident.span,
|
gate_feature_post!(&self, label_break_value, label.ident.span,
|
||||||
|
|
|
@ -3660,8 +3660,6 @@ impl<'a> Parser<'a> {
|
||||||
maybe_whole!(self, NtArm, |x| x);
|
maybe_whole!(self, NtArm, |x| x);
|
||||||
|
|
||||||
let attrs = self.parse_outer_attributes()?;
|
let attrs = self.parse_outer_attributes()?;
|
||||||
// Allow a '|' before the pats (RFC 1925)
|
|
||||||
self.eat(&token::BinOp(token::Or));
|
|
||||||
let pats = self.parse_pats()?;
|
let pats = self.parse_pats()?;
|
||||||
let guard = if self.eat_keyword(keywords::If) {
|
let guard = if self.eat_keyword(keywords::If) {
|
||||||
Some(Guard::If(self.parse_expr()?))
|
Some(Guard::If(self.parse_expr()?))
|
||||||
|
@ -3768,6 +3766,9 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// Parse patterns, separated by '|' s
|
/// Parse patterns, separated by '|' s
|
||||||
fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
|
fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
|
||||||
|
// Allow a '|' before the pats (RFC 1925 + RFC 2530)
|
||||||
|
self.eat(&token::BinOp(token::Or));
|
||||||
|
|
||||||
let mut pats = Vec::new();
|
let mut pats = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
pats.push(self.parse_top_level_pat()?);
|
pats.push(self.parse_top_level_pat()?);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// run-pass
|
// run-pass
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![feature(if_while_or_patterns)]
|
|
||||||
|
|
||||||
enum E {
|
enum E {
|
||||||
V(u8),
|
V(u8),
|
||||||
|
@ -19,4 +18,16 @@ fn main() {
|
||||||
assert_eq!(x, 10);
|
assert_eq!(x, 10);
|
||||||
e = W;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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`.
|
|
Loading…
Add table
Add a link
Reference in a new issue