Skip to content

Commit

Permalink
pre-expansion gate box_syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 23, 2019
1 parent 137ded8 commit e4ed886
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
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 @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/sess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/feature-gates/feature-gate-box_syntax.rs
Original file line number Diff line number Diff line change
@@ -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() {}
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-box_syntax.stderr
Original file line number Diff line number Diff line change
@@ -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;
| ^^^^^
Expand Down

0 comments on commit e4ed886

Please sign in to comment.