Skip to content

Commit 81b876b

Browse files
committed
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.
1 parent 72a3089 commit 81b876b

5 files changed

+11
-26
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18361836
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
18371837
}
18381838
ast::ExprKind::Type(..) => {
1839-
gate_feature_post!(&self, type_ascription, e.span,
1840-
"type ascription is experimental");
1839+
// To avoid noise about type ascription in common syntax errors, only emit if it
1840+
// is the *only* error.
1841+
if self.context.parse_sess.span_diagnostic.err_count() == 0 {
1842+
gate_feature_post!(&self, type_ascription, e.span,
1843+
"type ascription is experimental");
1844+
}
18411845
}
18421846
ast::ExprKind::ObsoleteInPlace(..) => {
18431847
// these get a hard error in ast-validation

src/test/ui/suggestions/type-ascription-instead-of-let.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ fn main() {
44
let closure_annotated = |value: i32| -> i32 {
55
temp: i32 = fun(5i32);
66
//~^ ERROR cannot find value `temp` in this scope
7-
//~| ERROR type ascription is experimental
87
temp + value + 1
98
//~^ ERROR cannot find value `temp` in this scope
109
};

src/test/ui/suggestions/type-ascription-instead-of-let.stderr

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,11 @@ LL | temp: i32 = fun(5i32);
88
| help: maybe you meant to write an assignment here: `let temp`
99

1010
error[E0425]: cannot find value `temp` in this scope
11-
--> $DIR/type-ascription-instead-of-let.rs:8:9
11+
--> $DIR/type-ascription-instead-of-let.rs:7:9
1212
|
1313
LL | temp + value + 1
1414
| ^^^^ not found in this scope
1515

16-
error[E0658]: type ascription is experimental (see issue #23416)
17-
--> $DIR/type-ascription-instead-of-let.rs:5:9
18-
|
19-
LL | temp: i32 = fun(5i32);
20-
| ^^^^^^^^^
21-
|
22-
= help: add #![feature(type_ascription)] to the crate attributes to enable
23-
24-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2517

26-
Some errors occurred: E0425, E0658.
27-
For more information about an error, try `rustc --explain E0425`.
18+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/suggestions/type-ascription-instead-of-path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ fn main() {
22
std:io::stdin();
33
//~^ ERROR failed to resolve: use of undeclared type or module `io`
44
//~| ERROR expected value, found module
5-
//~| ERROR type ascription is experimental
65
}

src/test/ui/suggestions/type-ascription-instead-of-path.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ LL | std:io::stdin();
1212
| |
1313
| not a value
1414

15-
error[E0658]: type ascription is experimental (see issue #23416)
16-
--> $DIR/type-ascription-instead-of-path.rs:2:5
17-
|
18-
LL | std:io::stdin();
19-
| ^^^^^^^^^^^^^^^
20-
|
21-
= help: add #![feature(type_ascription)] to the crate attributes to enable
22-
23-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2416

25-
Some errors occurred: E0423, E0433, E0658.
17+
Some errors occurred: E0423, E0433.
2618
For more information about an error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)