]> git.lizzy.rs Git - rust.git/commitdiff
Hide "type ascription is experimental error" unless it's the only one
authorEsteban Küber <esteban@kuber.com.ar>
Wed, 13 Mar 2019 23:47:55 +0000 (16:47 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Sat, 23 Mar 2019 02:50:18 +0000 (19:50 -0700)
In order to minimize the verbosity of common syntax errors that are parsed
as type ascription, hide the feature gate error unless there are no other
errors being emitted by the parser.

src/libsyntax/feature_gate.rs
src/test/ui/suggestions/type-ascription-instead-of-let.rs
src/test/ui/suggestions/type-ascription-instead-of-let.stderr
src/test/ui/suggestions/type-ascription-instead-of-path.rs
src/test/ui/suggestions/type-ascription-instead-of-path.stderr

index 9beaabb0cd58ba857fc6b3175427568826aa10f9..2816efaeb70e0cbbcd5f3cf6164f0e2b3ec94971 100644 (file)
@@ -1836,8 +1836,12 @@ fn visit_expr(&mut self, e: &'a ast::Expr) {
                 gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
             }
             ast::ExprKind::Type(..) => {
-                gate_feature_post!(&self, type_ascription, e.span,
-                                  "type ascription is experimental");
+                // To avoid noise about type ascription in common syntax errors, only emit if it
+                // is the *only* error.
+                if self.context.parse_sess.span_diagnostic.err_count() == 0 {
+                    gate_feature_post!(&self, type_ascription, e.span,
+                                       "type ascription is experimental");
+                }
             }
             ast::ExprKind::ObsoleteInPlace(..) => {
                 // these get a hard error in ast-validation
index 51d3d32565f8ae990643c9eee5c1a8d204ef008a..0e1c307502728c7c8bedf38e64887a2e894be3d2 100644 (file)
@@ -4,7 +4,6 @@ fn main() {
     let closure_annotated = |value: i32| -> i32 {
         temp: i32 = fun(5i32);
         //~^ ERROR cannot find value `temp` in this scope
-        //~| ERROR type ascription is experimental
         temp + value + 1
         //~^ ERROR cannot find value `temp` in this scope
     };
index 7f6aaef49f72bdd892beb87bf9e3717ab4707ee4..92e4b5798c88944db86f6afeb97669b913b3ca14 100644 (file)
@@ -8,20 +8,11 @@ LL |         temp: i32 = fun(5i32);
    |         help: maybe you meant to write an assignment here: `let temp`
 
 error[E0425]: cannot find value `temp` in this scope
-  --> $DIR/type-ascription-instead-of-let.rs:8:9
+  --> $DIR/type-ascription-instead-of-let.rs:7:9
    |
 LL |         temp + value + 1
    |         ^^^^ not found in this scope
 
-error[E0658]: type ascription is experimental (see issue #23416)
-  --> $DIR/type-ascription-instead-of-let.rs:5:9
-   |
-LL |         temp: i32 = fun(5i32);
-   |         ^^^^^^^^^
-   |
-   = help: add #![feature(type_ascription)] to the crate attributes to enable
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
-Some errors occurred: E0425, E0658.
-For more information about an error, try `rustc --explain E0425`.
+For more information about this error, try `rustc --explain E0425`.
index a81996ed7bb6b4a6541a0a3b81ac935120f21b15..4c0fe6d8b5b4e29a3c65d4c882d31a049fb41be4 100644 (file)
@@ -2,5 +2,4 @@ fn main() {
     std:io::stdin();
     //~^ ERROR failed to resolve: use of undeclared type or module `io`
     //~| ERROR expected value, found module
-    //~| ERROR type ascription is experimental
 }
index 9908b3f679893a8570197d829987b9ebabd8e70f..1beb822d6a74946ec91823e537001384718bdef4 100644 (file)
@@ -12,15 +12,7 @@ LL |     std:io::stdin();
    |     |
    |     not a value
 
-error[E0658]: type ascription is experimental (see issue #23416)
-  --> $DIR/type-ascription-instead-of-path.rs:2:5
-   |
-LL |     std:io::stdin();
-   |     ^^^^^^^^^^^^^^^
-   |
-   = help: add #![feature(type_ascription)] to the crate attributes to enable
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
-Some errors occurred: E0423, E0433, E0658.
+Some errors occurred: E0423, E0433.
 For more information about an error, try `rustc --explain E0423`.