Skip to content

Commit 38e7d42

Browse files
committed
Don't use per-arm lint levels
This makes things unnecessarily complicated for now
1 parent 013c2f3 commit 38e7d42

File tree

7 files changed

+51
-143
lines changed

7 files changed

+51
-143
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3814,9 +3814,9 @@ declare_lint! {
38143814
/// // in crate B
38153815
/// #![feature(non_exhaustive_omitted_patterns_lint)]
38163816
///
3817+
/// #[warn(non_exhaustive_omitted_patterns)]
38173818
/// match Bar::A {
38183819
/// Bar::A => {},
3819-
/// #[warn(non_exhaustive_omitted_patterns)]
38203820
/// _ => {},
38213821
/// }
38223822
/// ```

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,6 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
15961596
self.collect_unreachable_spans(&mut spans);
15971597
spans
15981598
}
1599-
16001599
fn collect_unreachable_spans(&self, spans: &mut Vec<Span>) {
16011600
// We don't look at subpatterns if we already reported the whole pattern as unreachable.
16021601
if !self.is_reachable() {

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
973973
.map(|arm| {
974974
debug!(?arm);
975975
let v = PatStack::from_pattern(arm.pat);
976-
is_useful(cx, &matrix, &v, RealArm, arm.hir_id, arm.has_guard, true);
976+
is_useful(cx, &matrix, &v, RealArm, lint_root, arm.has_guard, true);
977977
if !arm.has_guard {
978978
matrix.push(v);
979979
}

tests/ui/rfc-2008-non-exhaustive/omitted-patterns.rs

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Test that the `non_exhaustive_omitted_patterns` lint is triggered correctly.
22

33
#![feature(non_exhaustive_omitted_patterns_lint, unstable_test_feature)]
4+
#![deny(unreachable_patterns)]
45

56
// aux-build:enums.rs
67
extern crate enums;
@@ -31,37 +32,38 @@ pub enum Bar {
3132
C,
3233
}
3334

35+
fn no_lint() {
36+
let non_enum = NonExhaustiveEnum::Unit;
37+
// Ok: without the attribute
38+
match non_enum {
39+
NonExhaustiveEnum::Unit => {}
40+
NonExhaustiveEnum::Tuple(_) => {}
41+
_ => {}
42+
}
43+
}
44+
45+
#[warn(non_exhaustive_omitted_patterns)]
3446
fn main() {
3547
let enumeration = Bar::A;
3648

3749
// Ok: this is a crate local non_exhaustive enum
3850
match enumeration {
3951
Bar::A => {}
4052
Bar::B => {}
41-
#[deny(non_exhaustive_omitted_patterns)]
4253
_ => {}
4354
}
4455

4556
let non_enum = NonExhaustiveEnum::Unit;
4657

47-
// Ok: without the attribute
48-
match non_enum {
49-
NonExhaustiveEnum::Unit => {}
50-
NonExhaustiveEnum::Tuple(_) => {}
51-
_ => {}
52-
}
53-
5458
match non_enum {
5559
NonExhaustiveEnum::Unit => {}
5660
NonExhaustiveEnum::Tuple(_) => {}
57-
#[deny(non_exhaustive_omitted_patterns)]
5861
_ => {}
5962
}
6063
//~^^ some variants are not matched explicitly
6164

6265
match non_enum {
6366
NonExhaustiveEnum::Unit | NonExhaustiveEnum::Struct { .. } => {}
64-
#[deny(non_exhaustive_omitted_patterns)]
6567
_ => {}
6668
}
6769
//~^^ some variants are not matched explicitly
@@ -71,22 +73,18 @@ fn main() {
7173
NonExhaustiveEnum::Unit if x > 10 => {}
7274
NonExhaustiveEnum::Tuple(_) => {}
7375
NonExhaustiveEnum::Struct { .. } => {}
74-
#[deny(non_exhaustive_omitted_patterns)]
7576
_ => {}
7677
}
7778
//~^^ some variants are not matched explicitly
7879

7980
// Ok: all covered and not `unreachable-patterns`
80-
#[deny(unreachable_patterns)]
8181
match non_enum {
8282
NonExhaustiveEnum::Unit => {}
8383
NonExhaustiveEnum::Tuple(_) => {}
8484
NonExhaustiveEnum::Struct { .. } => {}
85-
#[deny(non_exhaustive_omitted_patterns)]
8685
_ => {}
8786
}
8887

89-
#[deny(non_exhaustive_omitted_patterns)]
9088
match NestedNonExhaustive::B {
9189
NestedNonExhaustive::A(NonExhaustiveEnum::Unit) => {}
9290
NestedNonExhaustive::A(_) => {}
@@ -96,68 +94,56 @@ fn main() {
9694
//~^^ some variants are not matched explicitly
9795
//~^^^^^ some variants are not matched explicitly
9896

99-
#[warn(non_exhaustive_omitted_patterns)]
10097
match VariantNonExhaustive::Baz(1, 2) {
10198
VariantNonExhaustive::Baz(_, _) => {}
10299
VariantNonExhaustive::Bar { x, .. } => {}
103100
}
104101
//~^^ some fields are not explicitly listed
105102

106-
#[warn(non_exhaustive_omitted_patterns)]
107103
let FunctionalRecord { first_field, second_field, .. } = FunctionalRecord::default();
108104
//~^ some fields are not explicitly listed
109105

110106
// Ok: this is local
111-
#[warn(non_exhaustive_omitted_patterns)]
112107
let Foo { a, b, .. } = Foo::default();
113108

114-
#[warn(non_exhaustive_omitted_patterns)]
115109
let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
116110
//~^ some fields are not explicitly listed
117111
//~^^ some fields are not explicitly listed
118112

119113
// Ok: this tests https://github.com/rust-lang/rust/issues/89382
120-
#[warn(non_exhaustive_omitted_patterns)]
121114
let MixedVisFields { a, b, .. } = MixedVisFields::default();
122115

123116
// Ok: because this only has 1 variant
124-
#[deny(non_exhaustive_omitted_patterns)]
125117
match NonExhaustiveSingleVariant::A(true) {
126118
NonExhaustiveSingleVariant::A(true) => {}
127119
_ => {}
128120
}
129121

130122
// No variants are mentioned
131-
#[deny(non_exhaustive_omitted_patterns)]
132123
match NonExhaustiveSingleVariant::A(true) {
133124
_ => {}
134125
}
135126
//~^^ some variants are not matched explicitly
136-
#[deny(non_exhaustive_omitted_patterns)]
137127
match Some(NonExhaustiveSingleVariant::A(true)) {
138128
Some(_) => {}
139129
None => {}
140130
}
141-
#[deny(non_exhaustive_omitted_patterns)]
142131
match Some(&NonExhaustiveSingleVariant::A(true)) {
143132
Some(_) => {}
144133
None => {}
145134
}
146135

147136
// Ok: we don't lint on `if let` expressions
148-
#[deny(non_exhaustive_omitted_patterns)]
149137
if let NonExhaustiveEnum::Tuple(_) = non_enum {}
150138

151139
match UnstableEnum::Stable {
152140
UnstableEnum::Stable => {}
153141
UnstableEnum::Stable2 => {}
154-
#[deny(non_exhaustive_omitted_patterns)]
155142
_ => {}
156143
}
157144
//~^^ some variants are not matched explicitly
158145

159146
// Ok: the feature is on and all variants are matched
160-
#[deny(non_exhaustive_omitted_patterns)]
161147
match UnstableEnum::Stable {
162148
UnstableEnum::Stable => {}
163149
UnstableEnum::Stable2 => {}
@@ -166,68 +152,56 @@ fn main() {
166152
}
167153

168154
// Ok: the feature is on and both variants are matched
169-
#[deny(non_exhaustive_omitted_patterns)]
170155
match OnlyUnstableEnum::Unstable {
171156
OnlyUnstableEnum::Unstable => {}
172157
OnlyUnstableEnum::Unstable2 => {}
173158
_ => {}
174159
}
175160

176-
#[deny(non_exhaustive_omitted_patterns)]
177161
match OnlyUnstableEnum::Unstable {
178162
OnlyUnstableEnum::Unstable => {}
179163
_ => {}
180164
}
181165
//~^^ some variants are not matched explicitly
182166

183-
#[warn(non_exhaustive_omitted_patterns)]
184167
let OnlyUnstableStruct { unstable, .. } = OnlyUnstableStruct::new();
185168
//~^ some fields are not explicitly listed
186169

187170
// OK: both unstable fields are matched with feature on
188-
#[warn(non_exhaustive_omitted_patterns)]
189171
let OnlyUnstableStruct { unstable, unstable2, .. } = OnlyUnstableStruct::new();
190172

191-
#[warn(non_exhaustive_omitted_patterns)]
192173
let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
193174
//~^ some fields are not explicitly listed
194175

195176
// OK: both unstable and stable fields are matched with feature on
196-
#[warn(non_exhaustive_omitted_patterns)]
197177
let UnstableStruct { stable, stable2, unstable, .. } = UnstableStruct::default();
198178

199179
// Ok: local bindings are allowed
200-
#[deny(non_exhaustive_omitted_patterns)]
201180
let local = NonExhaustiveEnum::Unit;
202181

203182
// Ok: missing patterns will be blocked by the pattern being refutable
204-
#[deny(non_exhaustive_omitted_patterns)]
205183
let local_refutable @ NonExhaustiveEnum::Unit = NonExhaustiveEnum::Unit;
206184
//~^ refutable pattern in local binding
207185

208186
// Check that matching on a reference results in a correctly spanned diagnostic
209-
#[deny(non_exhaustive_omitted_patterns)]
210187
match &non_enum {
211188
NonExhaustiveEnum::Unit => {}
212189
NonExhaustiveEnum::Tuple(_) => {}
213190
_ => {}
214191
}
215192
//~^^ some variants are not matched explicitly
216193

217-
#[deny(non_exhaustive_omitted_patterns)]
218194
match (true, &non_enum) {
219195
(true, NonExhaustiveEnum::Unit) => {}
220196
_ => {}
221197
}
222198

223-
#[deny(non_exhaustive_omitted_patterns)]
224199
match (&non_enum, true) {
225200
(NonExhaustiveEnum::Unit, true) => {}
226201
_ => {}
227202
}
228203
//~^^ some variants are not matched explicitly
229204

230-
#[deny(non_exhaustive_omitted_patterns)]
231205
match Some(&non_enum) {
232206
Some(NonExhaustiveEnum::Unit | NonExhaustiveEnum::Tuple(_)) => {}
233207
_ => {}

0 commit comments

Comments
 (0)