Skip to content

Commit 9a5d725

Browse files
varkorfanzier
authored andcommitted
Make pre-expansion gate slightly less obnoxious
1 parent f015a2e commit 9a5d725

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,11 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
630630
gate_all!(const_trait_impl, "const trait impls are experimental");
631631
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
632632
gate_all!(inline_const, "inline-const is experimental");
633-
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
633+
if parse_sess.span_diagnostic.err_count() == 0 {
634+
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
635+
// involved, so we only emit errors where there are no other parsing errors.
636+
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
637+
}
634638

635639
// All uses of `gate_all!` below this point were added in #65742,
636640
// and subsequently disabled (with the non-early gating readded).

src/test/ui/cross/cross-file-errors/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ mod underscore;
44
fn main() {
55
underscore!();
66
//~^ ERROR expected expression, found reserved identifier `_`
7+
//~^^ ERROR destructuring assignments are unstable
78
}

src/test/ui/cross/cross-file-errors/main.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
error[E0658]: destructuring assignments are unstable
2+
--> $DIR/underscore.rs:8:9
3+
|
4+
LL | _
5+
| ^
6+
|
7+
::: $DIR/main.rs:5:5
8+
|
9+
LL | underscore!();
10+
| -------------- in this macro invocation
11+
|
12+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
13+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
14+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
15+
116
error: expected expression, found reserved identifier `_`
217
--> $DIR/underscore.rs:8:9
318
|
@@ -11,5 +26,6 @@ LL | underscore!();
1126
|
1227
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1328

14-
error: aborting due to previous error
29+
error: aborting due to 2 previous errors
1530

31+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ fn main() {
1010
let _: usize = foo(_, _);
1111
//~^ ERROR expected expression
1212
//~| ERROR expected expression
13+
//~| ERROR destructuring assignments are unstable
14+
//~| ERROR destructuring assignments are unstable
1315
let _: S = S(_, _);
1416
//~^ ERROR expected expression
1517
//~| ERROR expected expression
18+
//~| ERROR destructuring assignments are unstable
19+
//~| ERROR destructuring assignments are unstable
1620
let _: usize = T::baz(_, _);
1721
//~^ ERROR expected expression
1822
//~| ERROR expected expression
23+
//~| ERROR destructuring assignments are unstable
24+
//~| ERROR destructuring assignments are unstable
1925
}

src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.stderr

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1+
error[E0658]: destructuring assignments are unstable
2+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:10:24
3+
|
4+
LL | let _: usize = foo(_, _);
5+
| ^
6+
|
7+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
8+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
9+
10+
error[E0658]: destructuring assignments are unstable
11+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:10:27
12+
|
13+
LL | let _: usize = foo(_, _);
14+
| ^
15+
|
16+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
17+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
18+
19+
error[E0658]: destructuring assignments are unstable
20+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:15:18
21+
|
22+
LL | let _: S = S(_, _);
23+
| ^
24+
|
25+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
26+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
27+
28+
error[E0658]: destructuring assignments are unstable
29+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:15:21
30+
|
31+
LL | let _: S = S(_, _);
32+
| ^
33+
|
34+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
35+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
36+
37+
error[E0658]: destructuring assignments are unstable
38+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:20:27
39+
|
40+
LL | let _: usize = T::baz(_, _);
41+
| ^
42+
|
43+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
44+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
45+
46+
error[E0658]: destructuring assignments are unstable
47+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:20:30
48+
|
49+
LL | let _: usize = T::baz(_, _);
50+
| ^
51+
|
52+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
53+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
54+
155
error: expected expression, found reserved identifier `_`
256
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:10:24
357
|
@@ -11,28 +65,29 @@ LL | let _: usize = foo(_, _);
1165
| ^ expected expression
1266

1367
error: expected expression, found reserved identifier `_`
14-
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:13:18
68+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:15:18
1569
|
1670
LL | let _: S = S(_, _);
1771
| ^ expected expression
1872

1973
error: expected expression, found reserved identifier `_`
20-
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:13:21
74+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:15:21
2175
|
2276
LL | let _: S = S(_, _);
2377
| ^ expected expression
2478

2579
error: expected expression, found reserved identifier `_`
26-
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:16:27
80+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:20:27
2781
|
2882
LL | let _: usize = T::baz(_, _);
2983
| ^ expected expression
3084

3185
error: expected expression, found reserved identifier `_`
32-
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:16:30
86+
--> $DIR/fn-or-tuple-struct-with-underscore-args.rs:20:30
3387
|
3488
LL | let _: usize = T::baz(_, _);
3589
| ^ expected expression
3690

37-
error: aborting due to 6 previous errors
91+
error: aborting due to 12 previous errors
3892

93+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)