pre-expansion gate box_syntax

This commit is contained in:
Mazdak Farrokhzad 2019-09-22 00:06:51 +02:00
parent 137ded8ab1
commit e4ed886578
5 changed files with 11 additions and 9 deletions

View 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 @@ 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);
}

View file

@ -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,

View file

@ -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.

View 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() {}

View 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;
| ^^^^^