@@ -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 ,
@@ -1020,7 +1022,7 @@ fn compute_exhaustiveness_and_reachability<'p, 'tcx>(
1020
1022
} ;
1021
1023
1022
1024
debug ! ( "ty: {ty:?}" ) ;
1023
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level } ;
1025
+ let pcx = & PatCtxt { cx, ty, is_top_level } ;
1024
1026
1025
1027
// Analyze the constructors present in this column.
1026
1028
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
@@ -1169,7 +1171,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
1169
1171
let Some ( ty) = column. head_ty ( ) else {
1170
1172
return Vec :: new ( ) ;
1171
1173
} ;
1172
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1174
+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
1173
1175
1174
1176
let set = column. analyze_ctors ( pcx) ;
1175
1177
if set. present . is_empty ( ) {
@@ -1210,16 +1212,15 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
1210
1212
}
1211
1213
1212
1214
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
1213
- #[ instrument( level = "debug" , skip( cx, lint_root ) ) ]
1215
+ #[ instrument( level = "debug" , skip( cx) ) ]
1214
1216
fn lint_overlapping_range_endpoints < ' p , ' tcx > (
1215
1217
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1216
1218
column : & PatternColumn < ' p , ' tcx > ,
1217
- lint_root : HirId ,
1218
1219
) {
1219
1220
let Some ( ty) = column. head_ty ( ) else {
1220
1221
return ;
1221
1222
} ;
1222
- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1223
+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
1223
1224
1224
1225
let set = column. analyze_ctors ( pcx) ;
1225
1226
@@ -1233,7 +1234,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
1233
1234
. collect ( ) ;
1234
1235
cx. tcx . emit_spanned_lint (
1235
1236
lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
1236
- lint_root ,
1237
+ cx . match_lint_level ,
1237
1238
this_span,
1238
1239
OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
1239
1240
) ;
@@ -1278,7 +1279,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
1278
1279
// Recurse into the fields.
1279
1280
for ctor in set. present {
1280
1281
for col in column. specialize ( pcx, & ctor) {
1281
- lint_overlapping_range_endpoints ( cx, & col, lint_root ) ;
1282
+ lint_overlapping_range_endpoints ( cx, & col) ;
1282
1283
}
1283
1284
}
1284
1285
}
@@ -1319,9 +1320,7 @@ pub(crate) struct UsefulnessReport<'p, 'tcx> {
1319
1320
pub ( crate ) fn compute_match_usefulness < ' p , ' tcx > (
1320
1321
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1321
1322
arms : & [ MatchArm < ' p , ' tcx > ] ,
1322
- lint_root : HirId ,
1323
1323
scrut_ty : Ty < ' tcx > ,
1324
- scrut_span : Span ,
1325
1324
) -> UsefulnessReport < ' p , ' tcx > {
1326
1325
let mut matrix = Matrix :: new ( cx, arms. iter ( ) , scrut_ty) ;
1327
1326
let non_exhaustiveness_witnesses =
@@ -1345,13 +1344,13 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1345
1344
1346
1345
let pat_column = PatternColumn :: new ( matrix. heads ( ) . collect ( ) ) ;
1347
1346
// Lint on ranges that overlap on their endpoints, which is likely a mistake.
1348
- lint_overlapping_range_endpoints ( cx, & pat_column, lint_root ) ;
1347
+ lint_overlapping_range_endpoints ( cx, & pat_column) ;
1349
1348
1350
1349
// Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
1351
1350
// `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
1352
1351
if cx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
1353
1352
if !matches ! (
1354
- cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , lint_root ) . 0 ,
1353
+ cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , cx . match_lint_level ) . 0 ,
1355
1354
rustc_session:: lint:: Level :: Allow
1356
1355
) {
1357
1356
let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
@@ -1362,11 +1361,11 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1362
1361
// NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
1363
1362
cx. tcx . emit_spanned_lint (
1364
1363
NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1365
- lint_root ,
1366
- scrut_span,
1364
+ cx . match_lint_level ,
1365
+ cx . scrut_span ,
1367
1366
NonExhaustiveOmittedPattern {
1368
1367
scrut_ty,
1369
- uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1368
+ uncovered : Uncovered :: new ( cx . scrut_span , cx, witnesses) ,
1370
1369
} ,
1371
1370
) ;
1372
1371
}
0 commit comments