Skip to content

Commit 1935ba6

Browse files
committed
pre-expansion gate try_blocks
1 parent 665a876 commit 1935ba6

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

src/libsyntax/feature_gate/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
495495
"type ascription is experimental");
496496
}
497497
}
498-
ast::ExprKind::TryBlock(_) => {
499-
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
500-
}
501498
ast::ExprKind::Block(_, opt_label) => {
502499
if let Some(label) = opt_label {
503500
gate_feature_post!(&self, label_break_value, label.ident.span,
@@ -811,6 +808,7 @@ pub fn check_crate(krate: &ast::Crate,
811808
gate_all!(decl_macro, "`macro` is experimental");
812809
gate_all!(box_patterns, "box pattern syntax is experimental");
813810
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
811+
gate_all!(try_blocks, "`try` blocks are unstable");
814812

815813
visit::walk_crate(&mut visitor, krate);
816814
}

src/libsyntax/parse/parser/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,9 @@ impl<'a> Parser<'a> {
16461646
error.emit();
16471647
Err(error)
16481648
} else {
1649-
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
1649+
let span = span_lo.to(body.span);
1650+
self.sess.gated_spans.try_blocks.borrow_mut().push(span);
1651+
Ok(self.mk_expr(span, ExprKind::TryBlock(body), attrs))
16501652
}
16511653
}
16521654

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ crate struct GatedSpans {
4444
pub box_patterns: Lock<Vec<Span>>,
4545
/// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`.
4646
pub exclusive_range_pattern: Lock<Vec<Span>>,
47+
/// Spans collected for gating `try_blocks`, e.g. `try { a? + b? }`.
48+
pub try_blocks: Lock<Vec<Span>>,
4749
}
4850

4951
/// Info about a parsing session.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// compile-flags: --edition 2018
22

3-
pub fn main() {
4-
let try_result: Option<_> = try { //~ ERROR `try` expression is experimental
3+
#[cfg(FALSE)]
4+
fn foo() {
5+
let try_result: Option<_> = try { //~ ERROR `try` blocks are unstable
56
let x = 5;
67
x
78
};
89
assert_eq!(try_result, Some(5));
910
}
11+
12+
fn main() {}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0658]: `try` expression is experimental
2-
--> $DIR/feature-gate-try_blocks.rs:4:33
1+
error[E0658]: `try` blocks are unstable
2+
--> $DIR/feature-gate-try_blocks.rs:5:33
33
|
44
LL | let try_result: Option<_> = try {
55
| _________________________________^

0 commit comments

Comments
 (0)