@@ -521,8 +521,12 @@ pub(crate) struct MatchCheckCtxt<'p, 'tcx> {
521
521
pub ( crate ) module : DefId ,
522
522
pub ( crate ) param_env : ty:: ParamEnv < ' tcx > ,
523
523
pub ( crate ) pattern_arena : & ' p TypedArena < DeconstructedPat < ' p , ' tcx > > ,
524
+ /// Lint level at the match.
525
+ pub ( crate ) match_lint_level : HirId ,
524
526
/// The span of the whole match, if applicable.
525
527
pub ( crate ) match_span : Option < Span > ,
528
+ /// Span of the scrutinee.
529
+ pub ( crate ) scrut_span : Span ,
526
530
/// Only produce `NON_EXHAUSTIVE_OMITTED_PATTERNS` lint on refutable patterns.
527
531
pub ( crate ) refutable : bool ,
528
532
}
@@ -552,8 +556,6 @@ pub(super) struct PatCtxt<'a, 'p, 'tcx> {
552
556
pub ( super ) cx : & ' a MatchCheckCtxt < ' p , ' tcx > ,
553
557
/// Type of the current column under investigation.
554
558
pub ( super ) ty : Ty < ' tcx > ,
555
- /// Span of the current pattern under investigation.
556
- pub ( super ) span : Span ,
557
559
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
558
560
/// subpattern.
559
561
pub ( super ) is_top_level : bool ,
@@ -1023,7 +1025,7 @@ fn compute_exhaustiveness_and_reachability<'p, 'tcx>(
1023
1025
} ;
1024
1026
1025
1027
debug ! ( "ty: {ty:?}" ) ;
1026
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level } ;
1028
+ let pcx = & PatCtxt { cx, ty, is_top_level } ;
1027
1029
1028
1030
// Analyze the constructors present in this column.
1029
1031
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
@@ -1167,7 +1169,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
1167
1169
let Some ( ty) = column. head_ty ( ) else {
1168
1170
return Vec :: new ( ) ;
1169
1171
} ;
1170
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1172
+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
1171
1173
1172
1174
let set = column. analyze_ctors ( pcx) ;
1173
1175
if set. present . is_empty ( ) {
@@ -1208,16 +1210,15 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
1208
1210
}
1209
1211
1210
1212
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
1211
- #[ instrument( level = "debug" , skip( cx, lint_root ) ) ]
1213
+ #[ instrument( level = "debug" , skip( cx) ) ]
1212
1214
fn lint_overlapping_range_endpoints < ' p , ' tcx > (
1213
1215
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1214
1216
column : & PatternColumn < ' p , ' tcx > ,
1215
- lint_root : HirId ,
1216
1217
) {
1217
1218
let Some ( ty) = column. head_ty ( ) else {
1218
1219
return ;
1219
1220
} ;
1220
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1221
+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
1221
1222
1222
1223
let set = column. analyze_ctors ( pcx) ;
1223
1224
@@ -1231,7 +1232,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
1231
1232
. collect ( ) ;
1232
1233
cx. tcx . emit_spanned_lint (
1233
1234
lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
1234
- lint_root ,
1235
+ cx . match_lint_level ,
1235
1236
this_span,
1236
1237
OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
1237
1238
) ;
@@ -1276,7 +1277,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
1276
1277
// Recurse into the fields.
1277
1278
for ctor in set. present {
1278
1279
for col in column. specialize ( pcx, & ctor) {
1279
- lint_overlapping_range_endpoints ( cx, & col, lint_root ) ;
1280
+ lint_overlapping_range_endpoints ( cx, & col) ;
1280
1281
}
1281
1282
}
1282
1283
}
@@ -1317,9 +1318,7 @@ pub(crate) struct UsefulnessReport<'p, 'tcx> {
1317
1318
pub ( crate ) fn compute_match_usefulness < ' p , ' tcx > (
1318
1319
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1319
1320
arms : & [ MatchArm < ' p , ' tcx > ] ,
1320
- lint_root : HirId ,
1321
1321
scrut_ty : Ty < ' tcx > ,
1322
- scrut_span : Span ,
1323
1322
) -> UsefulnessReport < ' p , ' tcx > {
1324
1323
let mut matrix = Matrix :: new ( cx, arms. iter ( ) , scrut_ty) ;
1325
1324
let non_exhaustiveness_witnesses =
@@ -1343,13 +1342,13 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1343
1342
1344
1343
let pat_column = PatternColumn :: new ( matrix. heads ( ) . collect ( ) ) ;
1345
1344
// Lint on ranges that overlap on their endpoints, which is likely a mistake.
1346
- lint_overlapping_range_endpoints ( cx, & pat_column, lint_root ) ;
1345
+ lint_overlapping_range_endpoints ( cx, & pat_column) ;
1347
1346
1348
1347
// Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
1349
1348
// `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
1350
1349
if cx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
1351
1350
if !matches ! (
1352
- cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , lint_root ) . 0 ,
1351
+ cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , cx . match_lint_level ) . 0 ,
1353
1352
rustc_session:: lint:: Level :: Allow
1354
1353
) {
1355
1354
let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
@@ -1360,11 +1359,11 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1360
1359
// NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
1361
1360
cx. tcx . emit_spanned_lint (
1362
1361
NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1363
- lint_root ,
1364
- scrut_span,
1362
+ cx . match_lint_level ,
1363
+ cx . scrut_span ,
1365
1364
NonExhaustiveOmittedPattern {
1366
1365
scrut_ty,
1367
- uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1366
+ uncovered : Uncovered :: new ( cx . scrut_span , cx, witnesses) ,
1368
1367
} ,
1369
1368
) ;
1370
1369
}
0 commit comments