@@ -311,7 +311,10 @@ use super::deconstruct_pat::{
311
311
Constructor , ConstructorSet , DeconstructedPat , IntRange , MaybeInfiniteInt , SplitConstructorSet ,
312
312
WitnessPat ,
313
313
} ;
314
- use crate :: errors:: { NonExhaustiveOmittedPattern , Overlap , OverlappingRangeEndpoints , Uncovered } ;
314
+ use crate :: errors:: {
315
+ NonExhaustiveOmittedPattern , NonExhaustiveOmittedPatternLintOnArm , Overlap ,
316
+ OverlappingRangeEndpoints , Uncovered ,
317
+ } ;
315
318
316
319
use rustc_data_structures:: captures:: Captures ;
317
320
@@ -1149,28 +1152,45 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1149
1152
1150
1153
// Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
1151
1154
// `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
1152
- if cx. refutable
1153
- && non_exhaustiveness_witnesses. is_empty ( )
1154
- && !matches ! (
1155
+ if cx. refutable && non_exhaustiveness_witnesses. is_empty ( ) {
1156
+ if !matches ! (
1155
1157
cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , lint_root) . 0 ,
1156
1158
rustc_session:: lint:: Level :: Allow
1157
- )
1158
- {
1159
- let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
1160
- if !witnesses. is_empty ( ) {
1161
- // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
1162
- // is not exhaustive enough.
1163
- //
1164
- // NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
1165
- cx. tcx . emit_spanned_lint (
1166
- NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1167
- lint_root,
1168
- scrut_span,
1169
- NonExhaustiveOmittedPattern {
1170
- scrut_ty,
1171
- uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1172
- } ,
1173
- ) ;
1159
+ ) {
1160
+ let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
1161
+
1162
+ if !witnesses. is_empty ( ) {
1163
+ // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
1164
+ // is not exhaustive enough.
1165
+ //
1166
+ // NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
1167
+ cx. tcx . emit_spanned_lint (
1168
+ NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1169
+ lint_root,
1170
+ scrut_span,
1171
+ NonExhaustiveOmittedPattern {
1172
+ scrut_ty,
1173
+ uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1174
+ } ,
1175
+ ) ;
1176
+ }
1177
+ } else {
1178
+ // We used to allow putting the `#[allow(non_exhaustive_omitted_patterns)]` on a match
1179
+ // arm. This no longer makes sense so we warn users, to avoid silently breaking their
1180
+ // usage of the lint.
1181
+ for arm in arms {
1182
+ if !matches ! (
1183
+ cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , arm. hir_id) . 0 ,
1184
+ rustc_session:: lint:: Level :: Allow
1185
+ ) {
1186
+ cx. tcx . emit_spanned_lint (
1187
+ NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1188
+ arm. hir_id ,
1189
+ arm. pat . span ( ) ,
1190
+ NonExhaustiveOmittedPatternLintOnArm ,
1191
+ ) ;
1192
+ }
1193
+ }
1174
1194
}
1175
1195
}
1176
1196
0 commit comments