From 81b876b6a3e3e489fdad8514f69b67264ab1d338 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Mar 2019 16:47:55 -0700 Subject: [PATCH] Hide "type ascription is experimental error" unless it's the only one 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 | 8 ++++++-- .../suggestions/type-ascription-instead-of-let.rs | 1 - .../type-ascription-instead-of-let.stderr | 15 +++------------ .../type-ascription-instead-of-path.rs | 1 - .../type-ascription-instead-of-path.stderr | 12 ++---------- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9beaabb0cd5..2816efaeb70 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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 diff --git a/src/test/ui/suggestions/type-ascription-instead-of-let.rs b/src/test/ui/suggestions/type-ascription-instead-of-let.rs index 51d3d32565f..0e1c3075027 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-let.rs +++ b/src/test/ui/suggestions/type-ascription-instead-of-let.rs @@ -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 }; diff --git a/src/test/ui/suggestions/type-ascription-instead-of-let.stderr b/src/test/ui/suggestions/type-ascription-instead-of-let.stderr index 7f6aaef49f7..92e4b5798c8 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-let.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-let.stderr @@ -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`. diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path.rs b/src/test/ui/suggestions/type-ascription-instead-of-path.rs index a81996ed7bb..4c0fe6d8b5b 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-path.rs +++ b/src/test/ui/suggestions/type-ascription-instead-of-path.rs @@ -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 } diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr index 9908b3f6798..1beb822d6a7 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr @@ -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`. -- 2.44.0