From e4ed8865786a787a7b0c045f7674569b6be0e9bc Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 22 Sep 2019 00:06:51 +0200 Subject: [PATCH] pre-expansion gate box_syntax --- src/libsyntax/feature_gate/check.rs | 7 +------ src/libsyntax/parse/parser/expr.rs | 4 +++- src/libsyntax/sess.rs | 2 ++ src/test/ui/feature-gates/feature-gate-box_syntax.rs | 5 ++++- src/test/ui/feature-gates/feature-gate-box_syntax.stderr | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 4e273fc9374f..7243f5c03201 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -153,9 +153,6 @@ fn leveled_feature_err<'a, S: Into>( } -const EXPLAIN_BOX_SYNTAX: &str = - "box expression syntax is experimental; you can call `Box::new` instead"; - pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = "attributes on expressions are experimental"; @@ -503,9 +500,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_expr(&mut self, e: &'a ast::Expr) { match e.kind { - ast::ExprKind::Box(_) => { - gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX); - } ast::ExprKind::Type(..) => { // To avoid noise about type ascription in common syntax errors, only emit if it // is the *only* error. @@ -809,6 +803,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental"); gate_all!(try_blocks, "`try` blocks are unstable"); gate_all!(label_break_value, "labels on blocks are unstable"); + gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead"); visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 395f3a3a4dfe..e7dd15654d80 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -453,7 +453,9 @@ impl<'a> Parser<'a> { self.bump(); let e = self.parse_prefix_expr(None); let (span, e) = self.interpolated_or_expr_span(e)?; - (lo.to(span), ExprKind::Box(e)) + let span = lo.to(span); + self.sess.gated_spans.box_syntax.borrow_mut().push(span); + (span, ExprKind::Box(e)) } token::Ident(..) if self.token.is_ident_named(sym::not) => { // `not` is just an ordinary identifier in Rust-the-language, diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index ac6be3036ce6..febaa7147750 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -48,6 +48,8 @@ crate struct GatedSpans { pub try_blocks: Lock>, /// Spans collected for gating `label_break_value`, e.g. `'label: { ... }`. pub label_break_value: Lock>, + /// Spans collected for gating `box_syntax`, e.g. `box $expr`. + pub box_syntax: Lock>, } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-box_syntax.rs b/src/test/ui/feature-gates/feature-gate-box_syntax.rs index 778660cc0b54..c23953a9e099 100644 --- a/src/test/ui/feature-gates/feature-gate-box_syntax.rs +++ b/src/test/ui/feature-gates/feature-gate-box_syntax.rs @@ -1,6 +1,9 @@ // Test that the use of the box syntax is gated by `box_syntax` feature gate. -fn main() { +#[cfg(FALSE)] +fn foo() { let x = box 3; //~^ ERROR box expression syntax is experimental; you can call `Box::new` instead } + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-box_syntax.stderr b/src/test/ui/feature-gates/feature-gate-box_syntax.stderr index 61b0534d2dc3..cbafa5025770 100644 --- a/src/test/ui/feature-gates/feature-gate-box_syntax.stderr +++ b/src/test/ui/feature-gates/feature-gate-box_syntax.stderr @@ -1,5 +1,5 @@ error[E0658]: box expression syntax is experimental; you can call `Box::new` instead - --> $DIR/feature-gate-box_syntax.rs:4:13 + --> $DIR/feature-gate-box_syntax.rs:5:13 | LL | let x = box 3; | ^^^^^