From 1935ba658c576f14397c2c7a26a6642cf08f26a6 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 21 Sep 2019 23:09:17 +0200 Subject: pre-expansion gate try_blocks --- src/libsyntax/parse/parser/expr.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse/parser/expr.rs') diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 67a530ec683..2e34422b918 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -1646,7 +1646,9 @@ impl<'a> Parser<'a> { error.emit(); Err(error) } else { - Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs)) + let span = span_lo.to(body.span); + self.sess.gated_spans.try_blocks.borrow_mut().push(span); + Ok(self.mk_expr(span, ExprKind::TryBlock(body), attrs)) } } -- cgit 1.4.1-3-g733a5 From 137ded8ab1edf5112c45e0b6854272ae2e9d3a6d Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 21 Sep 2019 23:54:05 +0200 Subject: pre-expansion gate label_break_value --- src/libsyntax/feature_gate/check.rs | 7 +------ src/libsyntax/parse/parser/expr.rs | 4 ++++ src/libsyntax/sess.rs | 2 ++ src/test/ui/feature-gates/feature-gate-label_break_value.rs | 5 ++++- src/test/ui/feature-gates/feature-gate-label_break_value.stderr | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/libsyntax/parse/parser/expr.rs') diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index ab8781feef0..4e273fc9374 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -514,12 +514,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "type ascription is experimental"); } } - ast::ExprKind::Block(_, opt_label) => { - if let Some(label) = opt_label { - gate_feature_post!(&self, label_break_value, label.ident.span, - "labels on blocks are unstable"); - } - } _ => {} } visit::walk_expr(self, e) @@ -814,6 +808,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(box_patterns, "box pattern syntax is experimental"); 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"); visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 2e34422b918..395f3a3a4df 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -1260,6 +1260,10 @@ impl<'a> Parser<'a> { blk_mode: BlockCheckMode, outer_attrs: ThinVec, ) -> PResult<'a, P> { + if let Some(label) = opt_label { + self.sess.gated_spans.label_break_value.borrow_mut().push(label.ident.span); + } + self.expect(&token::OpenDelim(token::Brace))?; let mut attrs = outer_attrs; diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 3582d897272..ac6be3036ce 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -46,6 +46,8 @@ crate struct GatedSpans { pub exclusive_range_pattern: Lock>, /// Spans collected for gating `try_blocks`, e.g. `try { a? + b? }`. pub try_blocks: Lock>, + /// Spans collected for gating `label_break_value`, e.g. `'label: { ... }`. + pub label_break_value: Lock>, } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-label_break_value.rs b/src/test/ui/feature-gates/feature-gate-label_break_value.rs index 6fc38f45517..8d7ecd27b45 100644 --- a/src/test/ui/feature-gates/feature-gate-label_break_value.rs +++ b/src/test/ui/feature-gates/feature-gate-label_break_value.rs @@ -1,5 +1,8 @@ -pub fn main() { +#[cfg(FALSE)] +pub fn foo() { 'a: { //~ ERROR labels on blocks are unstable break 'a; } } + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-label_break_value.stderr b/src/test/ui/feature-gates/feature-gate-label_break_value.stderr index a417e0eec22..6a861d3e04f 100644 --- a/src/test/ui/feature-gates/feature-gate-label_break_value.stderr +++ b/src/test/ui/feature-gates/feature-gate-label_break_value.stderr @@ -1,5 +1,5 @@ error[E0658]: labels on blocks are unstable - --> $DIR/feature-gate-label_break_value.rs:2:5 + --> $DIR/feature-gate-label_break_value.rs:3:5 | LL | 'a: { | ^^ -- cgit 1.4.1-3-g733a5 From e4ed8865786a787a7b0c045f7674569b6be0e9bc Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 22 Sep 2019 00:06:51 +0200 Subject: pre-expansion gate box_syntax --- src/libsyntax/feature_gate/check.rs | 7 +------ src/libsyntax/parse/parser/expr.rs | 4 +++- src/libsyntax/sess.rs | 2 ++ src/test/ui/feature-gates/feature-gate-box_syntax.rs | 5 ++++- src/test/ui/feature-gates/feature-gate-box_syntax.stderr | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/libsyntax/parse/parser/expr.rs') 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>( } -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>, /// Spans collected for gating `label_break_value`, e.g. `'label: { ... }`. pub label_break_value: Lock>, + /// Spans collected for gating `box_syntax`, e.g. `box $expr`. + pub box_syntax: Lock>, } /// 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; | ^^^^^ -- cgit 1.4.1-3-g733a5 From 15a6c09b6e8a977f2c6f5a73de01a20d00b37930 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 22 Sep 2019 00:19:02 +0200 Subject: pre-expansion gate type_ascription --- src/libsyntax/feature_gate/check.rs | 21 ++++++--------------- src/libsyntax/parse/parser/expr.rs | 1 + src/libsyntax/sess.rs | 2 ++ .../feature-gates/feature-gate-type_ascription.rs | 5 ++++- .../feature-gate-type_ascription.stderr | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src/libsyntax/parse/parser/expr.rs') diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 7243f5c0320..502b1c0f743 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -498,21 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } - fn visit_expr(&mut self, e: &'a ast::Expr) { - match e.kind { - ast::ExprKind::Type(..) => { - // To avoid noise about type ascription in common syntax errors, only emit if it - // is the *only* error. - if self.parse_sess.span_diagnostic.err_count() == 0 { - gate_feature_post!(&self, type_ascription, e.span, - "type ascription is experimental"); - } - } - _ => {} - } - visit::walk_expr(self, e) - } - fn visit_pat(&mut self, pattern: &'a ast::Pat) { match &pattern.kind { PatKind::Slice(pats) => { @@ -805,6 +790,12 @@ pub fn check_crate(krate: &ast::Crate, 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"); + // To avoid noise about type ascription in common syntax errors, + // only emit if it is the *only* error. (Also check it last.) + if parse_sess.span_diagnostic.err_count() == 0 { + gate_all!(type_ascription, "type ascription is experimental"); + } + visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index e7dd15654d8..97b1092452a 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -252,6 +252,7 @@ impl<'a> Parser<'a> { self.last_type_ascription = Some((self.prev_span, maybe_path)); lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?; + self.sess.gated_spans.type_ascription.borrow_mut().push(lhs.span); continue } else if op == AssocOp::DotDot || op == AssocOp::DotDotEq { // If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index febaa714775..28a0868d5dd 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -50,6 +50,8 @@ crate struct GatedSpans { pub label_break_value: Lock>, /// Spans collected for gating `box_syntax`, e.g. `box $expr`. pub box_syntax: Lock>, + /// Spans collected for gating `type_ascription`, e.g. `42: usize`. + pub type_ascription: Lock>, } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-type_ascription.rs b/src/test/ui/feature-gates/feature-gate-type_ascription.rs index 7a597157300..655891d802c 100644 --- a/src/test/ui/feature-gates/feature-gate-type_ascription.rs +++ b/src/test/ui/feature-gates/feature-gate-type_ascription.rs @@ -1,5 +1,8 @@ // Type ascription is unstable -fn main() { +#[cfg(FALSE)] +fn foo() { let a = 10: u8; //~ ERROR type ascription is experimental } + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-type_ascription.stderr b/src/test/ui/feature-gates/feature-gate-type_ascription.stderr index 83f95529f0d..d63d624c6c1 100644 --- a/src/test/ui/feature-gates/feature-gate-type_ascription.stderr +++ b/src/test/ui/feature-gates/feature-gate-type_ascription.stderr @@ -1,5 +1,5 @@ error[E0658]: type ascription is experimental - --> $DIR/feature-gate-type_ascription.rs:4:13 + --> $DIR/feature-gate-type_ascription.rs:5:13 | LL | let a = 10: u8; | ^^^^^^ -- cgit 1.4.1-3-g733a5