pre-expansion gate try_blocks

This commit is contained in:
Mazdak Farrokhzad 2019-09-21 23:09:17 +02:00
parent 665a876e30
commit 1935ba658c
5 changed files with 13 additions and 8 deletions

View file

@ -495,9 +495,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"type ascription is experimental"); "type ascription is experimental");
} }
} }
ast::ExprKind::TryBlock(_) => {
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
}
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,
@ -811,6 +808,7 @@ pub fn check_crate(krate: &ast::Crate,
gate_all!(decl_macro, "`macro` is experimental"); gate_all!(decl_macro, "`macro` is experimental");
gate_all!(box_patterns, "box pattern syntax is experimental"); gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range 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); visit::walk_crate(&mut visitor, krate);
} }

View file

@ -1646,7 +1646,9 @@ impl<'a> Parser<'a> {
error.emit(); error.emit();
Err(error) Err(error)
} else { } 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))
} }
} }

View file

@ -44,6 +44,8 @@ crate struct GatedSpans {
pub box_patterns: Lock<Vec<Span>>, pub box_patterns: Lock<Vec<Span>>,
/// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`. /// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`.
pub exclusive_range_pattern: Lock<Vec<Span>>, 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. /// Info about a parsing session.

View file

@ -1,9 +1,12 @@
// compile-flags: --edition 2018 // compile-flags: --edition 2018
pub fn main() { #[cfg(FALSE)]
let try_result: Option<_> = try { //~ ERROR `try` expression is experimental fn foo() {
let try_result: Option<_> = try { //~ ERROR `try` blocks are unstable
let x = 5; let x = 5;
x x
}; };
assert_eq!(try_result, Some(5)); assert_eq!(try_result, Some(5));
} }
fn main() {}

View file

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