Skip to content

Commit 21852e4

Browse files
committed
Move if let behind a feature gate
1 parent 0274c70 commit 21852e4

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

src/doc/rust.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,8 @@ The currently implemented features of the reference compiler are:
24572457
whether this will continue as a feature or not. For these reasons,
24582458
the glob import statement has been hidden behind this feature flag.
24592459

2460+
* `if_let` - Allows use of the `if let` desugaring syntax.
2461+
24602462
* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
24612463
are inherently unstable and no promise about them is made.
24622464

src/librustc/front/feature_gate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
7070
("unboxed_closures", Active),
7171
("import_shadowing", Active),
7272

73+
("if_let", Active),
74+
7375
// if you change this list without updating src/doc/rust.md, cmr will be sad
7476

7577
// A temporary feature gate used to enable parser extensions needed
@@ -339,6 +341,14 @@ impl<'a> Visitor<()> for Context<'a> {
339341
"unboxed closures are a work-in-progress \
340342
feature with known bugs");
341343
}
344+
ast::ExprIfLet(..) |
345+
ast::ExprMatch(_, _, ast::MatchIfLetDesugar) => {
346+
// note: at the point where we check feature-gates, the AST desugaring
347+
// should not have happened, but the ExprMatch check is included just
348+
// in case.
349+
self.gate_feature("if_let", e.span,
350+
"`if let` desugaring is experimental");
351+
}
342352
_ => {}
343353
}
344354
visit::walk_expr(self, e, ());

src/test/compile-fail/if-let.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(macro_rules)]
11+
#![feature(macro_rules,if_let)]
1212

1313
fn macros() {
1414
macro_rules! foo{

src/test/compile-fail/lint-unnecessary-parens.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![deny(unnecessary_parens)]
12+
#![feature(if_let)]
1213

1314
#[deriving(Eq, PartialEq)]
1415
struct X { y: bool }

src/test/run-pass/if-let.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(if_let)]
12+
1113
pub fn main() {
1214
let x = Some(3i);
1315
if let Some(y) = x {

0 commit comments

Comments
 (0)