Skip to content

Commit

Permalink
pre-expansion gate try_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 23, 2019
1 parent 665a876 commit 1935ba6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"type ascription is experimental");
}
}
ast::ExprKind::TryBlock(_) => {
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
}
ast::ExprKind::Block(_, opt_label) => {
if let Some(label) = opt_label {
gate_feature_post!(&self, label_break_value, label.ident.span,
Expand Down Expand Up @@ -811,6 +808,7 @@ pub fn check_crate(krate: &ast::Crate,
gate_all!(decl_macro, "`macro` is experimental");
gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
gate_all!(try_blocks, "`try` blocks are unstable");

visit::walk_crate(&mut visitor, krate);
}
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,9 @@ impl<'a> Parser<'a> {
error.emit();
Err(error)
} else {
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
let span = span_lo.to(body.span);
self.sess.gated_spans.try_blocks.borrow_mut().push(span);
Ok(self.mk_expr(span, ExprKind::TryBlock(body), attrs))
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/sess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ crate struct GatedSpans {
pub box_patterns: Lock<Vec<Span>>,
/// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`.
pub exclusive_range_pattern: Lock<Vec<Span>>,
/// Spans collected for gating `try_blocks`, e.g. `try { a? + b? }`.
pub try_blocks: Lock<Vec<Span>>,
}

/// Info about a parsing session.
Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/feature-gates/feature-gate-try_blocks.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// compile-flags: --edition 2018

pub fn main() {
let try_result: Option<_> = try { //~ ERROR `try` expression is experimental
#[cfg(FALSE)]
fn foo() {
let try_result: Option<_> = try { //~ ERROR `try` blocks are unstable
let x = 5;
x
};
assert_eq!(try_result, Some(5));
}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/feature-gates/feature-gate-try_blocks.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: `try` expression is experimental
--> $DIR/feature-gate-try_blocks.rs:4:33
error[E0658]: `try` blocks are unstable
--> $DIR/feature-gate-try_blocks.rs:5:33
|
LL | let try_result: Option<_> = try {
| _________________________________^
Expand Down

0 comments on commit 1935ba6

Please sign in to comment.