diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-22 00:06:51 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-24 00:32:03 +0200 |
| commit | e4ed8865786a787a7b0c045f7674569b6be0e9bc (patch) | |
| tree | fd5bde6d3fba8bce56b1a8dee06ef74e0b141f84 | |
| parent | 137ded8ab1edf5112c45e0b6854272ae2e9d3a6d (diff) | |
| download | rust-e4ed8865786a787a7b0c045f7674569b6be0e9bc.tar.gz rust-e4ed8865786a787a7b0c045f7674569b6be0e9bc.zip | |
pre-expansion gate box_syntax
| -rw-r--r-- | src/libsyntax/feature_gate/check.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/expr.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/sess.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-box_syntax.rs | 5 | ||||
| -rw-r--r-- | 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 4e273fc9374..7243f5c0320 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<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 @@ 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 395f3a3a4df..e7dd15654d8 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 ac6be3036ce..febaa714775 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -48,6 +48,8 @@ crate struct GatedSpans { 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. 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 778660cc0b5..c23953a9e09 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 61b0534d2dc..cbafa502577 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; | ^^^^^ |
