@@ -521,8 +521,12 @@ pub(crate) struct MatchCheckCtxt<'p, 'tcx> {
521521 pub ( crate ) module : DefId ,
522522 pub ( crate ) param_env : ty:: ParamEnv < ' tcx > ,
523523 pub ( crate ) pattern_arena : & ' p TypedArena < DeconstructedPat < ' p , ' tcx > > ,
524+ /// Lint level at the match.
525+ pub ( crate ) match_lint_level : HirId ,
524526 /// The span of the whole match, if applicable.
525527 pub ( crate ) match_span : Option < Span > ,
528+ /// Span of the scrutinee.
529+ pub ( crate ) scrut_span : Span ,
526530 /// Only produce `NON_EXHAUSTIVE_OMITTED_PATTERNS` lint on refutable patterns.
527531 pub ( crate ) refutable : bool ,
528532}
@@ -552,8 +556,6 @@ pub(super) struct PatCtxt<'a, 'p, 'tcx> {
552556 pub ( super ) cx : & ' a MatchCheckCtxt < ' p , ' tcx > ,
553557 /// Type of the current column under investigation.
554558 pub ( super ) ty : Ty < ' tcx > ,
555- /// Span of the current pattern under investigation.
556- pub ( super ) span : Span ,
557559 /// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
558560 /// subpattern.
559561 pub ( super ) is_top_level : bool ,
@@ -1020,7 +1022,7 @@ fn compute_exhaustiveness_and_reachability<'p, 'tcx>(
10201022 } ;
10211023
10221024 debug ! ( "ty: {ty:?}" ) ;
1023- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level } ;
1025+ let pcx = & PatCtxt { cx, ty, is_top_level } ;
10241026
10251027 // Analyze the constructors present in this column.
10261028 let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
@@ -1169,7 +1171,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
11691171 let Some ( ty) = column. head_ty ( ) else {
11701172 return Vec :: new ( ) ;
11711173 } ;
1172- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1174+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
11731175
11741176 let set = column. analyze_ctors ( pcx) ;
11751177 if set. present . is_empty ( ) {
@@ -1210,16 +1212,15 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
12101212}
12111213
12121214/// 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) ) ]
12141216fn lint_overlapping_range_endpoints < ' p , ' tcx > (
12151217 cx : & MatchCheckCtxt < ' p , ' tcx > ,
12161218 column : & PatternColumn < ' p , ' tcx > ,
1217- lint_root : HirId ,
12181219) {
12191220 let Some ( ty) = column. head_ty ( ) else {
12201221 return ;
12211222 } ;
1222- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1223+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
12231224
12241225 let set = column. analyze_ctors ( pcx) ;
12251226
@@ -1233,7 +1234,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
12331234 . collect ( ) ;
12341235 cx. tcx . emit_spanned_lint (
12351236 lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
1236- lint_root ,
1237+ cx . match_lint_level ,
12371238 this_span,
12381239 OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
12391240 ) ;
@@ -1278,7 +1279,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
12781279 // Recurse into the fields.
12791280 for ctor in set. present {
12801281 for col in column. specialize ( pcx, & ctor) {
1281- lint_overlapping_range_endpoints ( cx, & col, lint_root ) ;
1282+ lint_overlapping_range_endpoints ( cx, & col) ;
12821283 }
12831284 }
12841285 }
@@ -1319,9 +1320,7 @@ pub(crate) struct UsefulnessReport<'p, 'tcx> {
13191320pub ( crate ) fn compute_match_usefulness < ' p , ' tcx > (
13201321 cx : & MatchCheckCtxt < ' p , ' tcx > ,
13211322 arms : & [ MatchArm < ' p , ' tcx > ] ,
1322- lint_root : HirId ,
13231323 scrut_ty : Ty < ' tcx > ,
1324- scrut_span : Span ,
13251324) -> UsefulnessReport < ' p , ' tcx > {
13261325 let mut matrix = Matrix :: new ( cx, arms. iter ( ) , scrut_ty) ;
13271326 let non_exhaustiveness_witnesses =
@@ -1345,13 +1344,13 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
13451344
13461345 let pat_column = PatternColumn :: new ( matrix. heads ( ) . collect ( ) ) ;
13471346 // 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) ;
13491348
13501349 // Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
13511350 // `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
13521351 if cx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
13531352 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 ,
13551354 rustc_session:: lint:: Level :: Allow
13561355 ) {
13571356 let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
@@ -1362,11 +1361,11 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
13621361 // NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
13631362 cx. tcx . emit_spanned_lint (
13641363 NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1365- lint_root ,
1366- scrut_span,
1364+ cx . match_lint_level ,
1365+ cx . scrut_span ,
13671366 NonExhaustiveOmittedPattern {
13681367 scrut_ty,
1369- uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1368+ uncovered : Uncovered :: new ( cx . scrut_span , cx, witnesses) ,
13701369 } ,
13711370 ) ;
13721371 }
0 commit comments