about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-22 00:19:02 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-10-24 00:32:03 +0200
commit15a6c09b6e8a977f2c6f5a73de01a20d00b37930 (patch)
treec367b20d8aed10f33996bbbb5227b99c7150dad7 /src
parente4ed8865786a787a7b0c045f7674569b6be0e9bc (diff)
downloadrust-15a6c09b6e8a977f2c6f5a73de01a20d00b37930.tar.gz
rust-15a6c09b6e8a977f2c6f5a73de01a20d00b37930.zip
pre-expansion gate type_ascription
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/feature_gate/check.rs21
-rw-r--r--src/libsyntax/parse/parser/expr.rs1
-rw-r--r--src/libsyntax/sess.rs2
-rw-r--r--src/test/ui/feature-gates/feature-gate-type_ascription.rs5
-rw-r--r--src/test/ui/feature-gates/feature-gate-type_ascription.stderr2
5 files changed, 14 insertions, 17 deletions
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<Vec<Span>>,
     /// Spans collected for gating `box_syntax`, e.g. `box $expr`.
     pub box_syntax: Lock<Vec<Span>>,
+    /// Spans collected for gating `type_ascription`, e.g. `42: usize`.
+    pub type_ascription: Lock<Vec<Span>>,
 }
 
 /// 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;
    |             ^^^^^^