Skip to content

Commit e4ed886

Browse files
committed
pre-expansion gate box_syntax
1 parent 137ded8 commit e4ed886

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/libsyntax/feature_gate/check.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
153153

154154
}
155155

156-
const EXPLAIN_BOX_SYNTAX: &str =
157-
"box expression syntax is experimental; you can call `Box::new` instead";
158-
159156
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
160157
"attributes on expressions are experimental";
161158

@@ -503,9 +500,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
503500

504501
fn visit_expr(&mut self, e: &'a ast::Expr) {
505502
match e.kind {
506-
ast::ExprKind::Box(_) => {
507-
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
508-
}
509503
ast::ExprKind::Type(..) => {
510504
// To avoid noise about type ascription in common syntax errors, only emit if it
511505
// is the *only* error.
@@ -809,6 +803,7 @@ pub fn check_crate(krate: &ast::Crate,
809803
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
810804
gate_all!(try_blocks, "`try` blocks are unstable");
811805
gate_all!(label_break_value, "labels on blocks are unstable");
806+
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
812807

813808
visit::walk_crate(&mut visitor, krate);
814809
}

src/libsyntax/parse/parser/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ impl<'a> Parser<'a> {
453453
self.bump();
454454
let e = self.parse_prefix_expr(None);
455455
let (span, e) = self.interpolated_or_expr_span(e)?;
456-
(lo.to(span), ExprKind::Box(e))
456+
let span = lo.to(span);
457+
self.sess.gated_spans.box_syntax.borrow_mut().push(span);
458+
(span, ExprKind::Box(e))
457459
}
458460
token::Ident(..) if self.token.is_ident_named(sym::not) => {
459461
// `not` is just an ordinary identifier in Rust-the-language,

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ crate struct GatedSpans {
4848
pub try_blocks: Lock<Vec<Span>>,
4949
/// Spans collected for gating `label_break_value`, e.g. `'label: { ... }`.
5050
pub label_break_value: Lock<Vec<Span>>,
51+
/// Spans collected for gating `box_syntax`, e.g. `box $expr`.
52+
pub box_syntax: Lock<Vec<Span>>,
5153
}
5254

5355
/// Info about a parsing session.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Test that the use of the box syntax is gated by `box_syntax` feature gate.
22

3-
fn main() {
3+
#[cfg(FALSE)]
4+
fn foo() {
45
let x = box 3;
56
//~^ ERROR box expression syntax is experimental; you can call `Box::new` instead
67
}
8+
9+
fn main() {}

src/test/ui/feature-gates/feature-gate-box_syntax.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: box expression syntax is experimental; you can call `Box::new` instead
2-
--> $DIR/feature-gate-box_syntax.rs:4:13
2+
--> $DIR/feature-gate-box_syntax.rs:5:13
33
|
44
LL | let x = box 3;
55
| ^^^^^

0 commit comments

Comments
 (0)