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