]> git.lizzy.rs Git - rust.git/commitdiff
pre-expansion gate box_syntax
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Sep 2019 22:06:51 +0000 (00:06 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Wed, 23 Oct 2019 22:32:03 +0000 (00:32 +0200)
src/libsyntax/feature_gate/check.rs
src/libsyntax/parse/parser/expr.rs
src/libsyntax/sess.rs
src/test/ui/feature-gates/feature-gate-box_syntax.rs
src/test/ui/feature-gates/feature-gate-box_syntax.stderr

index 4e273fc9374fca4a40d729256ba7e0f56abf5e52..7243f5c032016e22d789a5d3c87f9b101284eef0 100644 (file)
@@ -153,9 +153,6 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
 
 }
 
-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 @@ fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
 
     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 @@ macro_rules! gate_all {
     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);
 }
index 395f3a3a4dfe1e323c2521fcf52c236c86fdce71..e7dd15654d8062bf55138ffa5881a0404056a06a 100644 (file)
@@ -453,7 +453,9 @@ fn parse_prefix_expr(
                 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,
index ac6be3036ce6493cceaa3812b0b873f46622c197..febaa71477509a76ca10fbd449a4b5c990d3ec44 100644 (file)
@@ -48,6 +48,8 @@
     pub try_blocks: Lock<Vec<Span>>,
     /// Spans collected for gating `label_break_value`, e.g. `'label: { ... }`.
     pub label_break_value: Lock<Vec<Span>>,
+    /// Spans collected for gating `box_syntax`, e.g. `box $expr`.
+    pub box_syntax: Lock<Vec<Span>>,
 }
 
 /// Info about a parsing session.
index 778660cc0b54991d1b456e33f18095a108f091d3..c23953a9e099e1dfa279390e63506790b6ea8aa9 100644 (file)
@@ -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() {}
index 61b0534d2dc3ec129e0a193d8c16bc75969e72f5..cbafa50257706e53cb7efde0f8de5fd1360310ed 100644 (file)
@@ -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;
    |             ^^^^^