Skip to content

Commit cfa5391

Browse files
authored
Rollup merge of #89428 - DevinR528:reachable-featuregate, r=Nadrieril,camelid
Feature gate the non_exhaustive_omitted_patterns lint Fixes #89374 Add the machinery to gate the new `non_exhaustive_omitted_patterns` lint. relates to #89105 and #89423
2 parents 4473b94 + 1433878 commit cfa5391

File tree

7 files changed

+154
-20
lines changed

7 files changed

+154
-20
lines changed

compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ declare_features! (
678678
/// Allows `#[doc(cfg_hide(...))]`.
679679
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
680680

681+
/// Allows using the `non_exhaustive_omitted_patterns` lint.
682+
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
683+
681684
// -------------------------------------------------------------------------
682685
// feature-group-end: actual feature gates
683686
// -------------------------------------------------------------------------

compiler/rustc_lint_defs/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
88
use rustc_span::edition::Edition;
9+
use rustc_span::symbol::sym;
910

1011
declare_lint! {
1112
/// The `forbidden_lint_groups` lint detects violations of
@@ -3476,6 +3477,8 @@ declare_lint! {
34763477
/// }
34773478
///
34783479
/// // in crate B
3480+
/// #![feature(non_exhaustive_omitted_patterns_lint)]
3481+
///
34793482
/// match Bar::A {
34803483
/// Bar::A => {},
34813484
/// #[warn(non_exhaustive_omitted_patterns)]
@@ -3512,6 +3515,7 @@ declare_lint! {
35123515
pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
35133516
Allow,
35143517
"detect when patterns of types marked `non_exhaustive` are missed",
3518+
@feature_gate = sym::non_exhaustive_omitted_patterns_lint;
35153519
}
35163520

35173521
declare_lint! {

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ symbols! {
893893
nomem,
894894
non_ascii_idents,
895895
non_exhaustive,
896+
non_exhaustive_omitted_patterns_lint,
896897
non_modrs_mods,
897898
none_error,
898899
nontemporal_store,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![deny(non_exhaustive_omitted_patterns)]
2+
//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
3+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
4+
#![allow(non_exhaustive_omitted_patterns)]
5+
//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
6+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
7+
8+
fn main() {
9+
enum Foo {
10+
A, B, C,
11+
}
12+
13+
#[allow(non_exhaustive_omitted_patterns)]
14+
match Foo::A {
15+
Foo::A => {}
16+
Foo::B => {}
17+
}
18+
//~^^^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
19+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
20+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
21+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
22+
23+
match Foo::A {
24+
Foo::A => {}
25+
Foo::B => {}
26+
#[warn(non_exhaustive_omitted_patterns)]
27+
_ => {}
28+
}
29+
//~^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
30+
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
2+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1
3+
|
4+
LL | #![deny(non_exhaustive_omitted_patterns)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
8+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
9+
10+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
11+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1
12+
|
13+
LL | #![allow(non_exhaustive_omitted_patterns)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
17+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
18+
19+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
20+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
21+
|
22+
LL | #[allow(non_exhaustive_omitted_patterns)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
26+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
27+
28+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
29+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
30+
|
31+
LL | #[allow(non_exhaustive_omitted_patterns)]
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
35+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
36+
37+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
38+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9
39+
|
40+
LL | #[warn(non_exhaustive_omitted_patterns)]
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
|
43+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
44+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
45+
46+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
47+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1
48+
|
49+
LL | #![deny(non_exhaustive_omitted_patterns)]
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
|
52+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
53+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
54+
55+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
56+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1
57+
|
58+
LL | #![allow(non_exhaustive_omitted_patterns)]
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
62+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
63+
64+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
65+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
66+
|
67+
LL | #[allow(non_exhaustive_omitted_patterns)]
68+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
|
70+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
71+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
72+
73+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
74+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
75+
|
76+
LL | #[allow(non_exhaustive_omitted_patterns)]
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78+
|
79+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
80+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
81+
82+
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
83+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9
84+
|
85+
LL | #[warn(non_exhaustive_omitted_patterns)]
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
89+
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
90+
91+
error: aborting due to 10 previous errors
92+
93+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Test that the `non_exhaustive_omitted_patterns` lint is triggered correctly.
22

3+
#![feature(non_exhaustive_omitted_patterns_lint)]
4+
35
// aux-build:enums.rs
46
extern crate enums;
57

src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
warning: some fields are not explicitly listed
2-
--> $DIR/reachable-patterns.rs:127:9
2+
--> $DIR/reachable-patterns.rs:129:9
33
|
44
LL | VariantNonExhaustive::Bar { x, .. } => {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `y` not listed
66
|
77
note: the lint level is defined here
8-
--> $DIR/reachable-patterns.rs:124:12
8+
--> $DIR/reachable-patterns.rs:126:12
99
|
1010
LL | #[warn(non_exhaustive_omitted_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
1313
= note: the pattern is of type `VariantNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
1414

1515
warning: some fields are not explicitly listed
16-
--> $DIR/reachable-patterns.rs:132:9
16+
--> $DIR/reachable-patterns.rs:134:9
1717
|
1818
LL | let FunctionalRecord { first_field, second_field, .. } = FunctionalRecord::default();
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `third_field` not listed
2020
|
2121
note: the lint level is defined here
22-
--> $DIR/reachable-patterns.rs:131:12
22+
--> $DIR/reachable-patterns.rs:133:12
2323
|
2424
LL | #[warn(non_exhaustive_omitted_patterns)]
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
2727
= note: the pattern is of type `FunctionalRecord` and the `non_exhaustive_omitted_patterns` attribute was found
2828

2929
warning: some fields are not explicitly listed
30-
--> $DIR/reachable-patterns.rs:140:29
30+
--> $DIR/reachable-patterns.rs:142:29
3131
|
3232
LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `second_field` not listed
3434
|
3535
note: the lint level is defined here
36-
--> $DIR/reachable-patterns.rs:139:12
36+
--> $DIR/reachable-patterns.rs:141:12
3737
|
3838
LL | #[warn(non_exhaustive_omitted_patterns)]
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
4141
= note: the pattern is of type `NormalStruct` and the `non_exhaustive_omitted_patterns` attribute was found
4242

4343
warning: some fields are not explicitly listed
44-
--> $DIR/reachable-patterns.rs:140:9
44+
--> $DIR/reachable-patterns.rs:142:9
4545
|
4646
LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `foo` not listed
@@ -50,63 +50,63 @@ LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = Nested
5050
= note: the pattern is of type `NestedStruct` and the `non_exhaustive_omitted_patterns` attribute was found
5151

5252
error: some variants are not matched explicitly
53-
--> $DIR/reachable-patterns.rs:54:9
53+
--> $DIR/reachable-patterns.rs:56:9
5454
|
5555
LL | _ => {}
5656
| ^ pattern `Struct { .. }` not covered
5757
|
5858
note: the lint level is defined here
59-
--> $DIR/reachable-patterns.rs:53:16
59+
--> $DIR/reachable-patterns.rs:55:16
6060
|
6161
LL | #[deny(non_exhaustive_omitted_patterns)]
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
= help: ensure that all variants are matched explicitly by adding the suggested match arms
6464
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
6565

6666
error: some variants are not matched explicitly
67-
--> $DIR/reachable-patterns.rs:61:9
67+
--> $DIR/reachable-patterns.rs:63:9
6868
|
6969
LL | _ => {}
7070
| ^ pattern `Tuple(_)` not covered
7171
|
7272
note: the lint level is defined here
73-
--> $DIR/reachable-patterns.rs:60:16
73+
--> $DIR/reachable-patterns.rs:62:16
7474
|
7575
LL | #[deny(non_exhaustive_omitted_patterns)]
7676
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7777
= help: ensure that all variants are matched explicitly by adding the suggested match arms
7878
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
7979

8080
error: some variants are not matched explicitly
81-
--> $DIR/reachable-patterns.rs:71:9
81+
--> $DIR/reachable-patterns.rs:73:9
8282
|
8383
LL | _ => {}
8484
| ^ pattern `Unit` not covered
8585
|
8686
note: the lint level is defined here
87-
--> $DIR/reachable-patterns.rs:70:16
87+
--> $DIR/reachable-patterns.rs:72:16
8888
|
8989
LL | #[deny(non_exhaustive_omitted_patterns)]
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9191
= help: ensure that all variants are matched explicitly by adding the suggested match arms
9292
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
9393

9494
error: some variants are not matched explicitly
95-
--> $DIR/reachable-patterns.rs:88:32
95+
--> $DIR/reachable-patterns.rs:90:32
9696
|
9797
LL | NestedNonExhaustive::A(_) => {}
9898
| ^ patterns `Tuple(_)` and `Struct { .. }` not covered
9999
|
100100
note: the lint level is defined here
101-
--> $DIR/reachable-patterns.rs:85:12
101+
--> $DIR/reachable-patterns.rs:87:12
102102
|
103103
LL | #[deny(non_exhaustive_omitted_patterns)]
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105105
= help: ensure that all variants are matched explicitly by adding the suggested match arms
106106
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
107107

108108
error: some variants are not matched explicitly
109-
--> $DIR/reachable-patterns.rs:90:9
109+
--> $DIR/reachable-patterns.rs:92:9
110110
|
111111
LL | _ => {}
112112
| ^ pattern `C` not covered
@@ -115,27 +115,27 @@ LL | _ => {}
115115
= note: the matched value is of type `NestedNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
116116

117117
error: some variants are not matched explicitly
118-
--> $DIR/reachable-patterns.rs:120:9
118+
--> $DIR/reachable-patterns.rs:122:9
119119
|
120120
LL | _ => {}
121121
| ^ patterns `HostUnreachable`, `NetworkUnreachable`, `NetworkDown` and 18 more not covered
122122
|
123123
note: the lint level is defined here
124-
--> $DIR/reachable-patterns.rs:97:12
124+
--> $DIR/reachable-patterns.rs:99:12
125125
|
126126
LL | #[deny(non_exhaustive_omitted_patterns)]
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128128
= help: ensure that all variants are matched explicitly by adding the suggested match arms
129129
= note: the matched value is of type `ErrorKind` and the `non_exhaustive_omitted_patterns` attribute was found
130130

131131
error: some variants are not matched explicitly
132-
--> $DIR/reachable-patterns.rs:157:9
132+
--> $DIR/reachable-patterns.rs:159:9
133133
|
134134
LL | _ => {}
135135
| ^ pattern `A(_)` not covered
136136
|
137137
note: the lint level is defined here
138-
--> $DIR/reachable-patterns.rs:155:12
138+
--> $DIR/reachable-patterns.rs:157:12
139139
|
140140
LL | #[deny(non_exhaustive_omitted_patterns)]
141141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)