@@ -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 ,
@@ -1022,7 +1024,7 @@ fn compute_exhaustiveness_and_reachability<'p, 'tcx>(
10221024 } ;
10231025
10241026 debug ! ( "ty: {ty:?}" ) ;
1025- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level } ;
1027+ let pcx = & PatCtxt { cx, ty, is_top_level } ;
10261028
10271029 // Analyze the constructors present in this column.
10281030 let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
@@ -1166,7 +1168,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
11661168 let Some ( ty) = column. head_ty ( ) else {
11671169 return Vec :: new ( ) ;
11681170 } ;
1169- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1171+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
11701172
11711173 let set = column. analyze_ctors ( pcx) ;
11721174 if set. present . is_empty ( ) {
@@ -1207,16 +1209,15 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
12071209}
12081210
12091211/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
1210- #[ instrument( level = "debug" , skip( cx, lint_root ) ) ]
1212+ #[ instrument( level = "debug" , skip( cx) ) ]
12111213fn lint_overlapping_range_endpoints < ' p , ' tcx > (
12121214 cx : & MatchCheckCtxt < ' p , ' tcx > ,
12131215 column : & PatternColumn < ' p , ' tcx > ,
1214- lint_root : HirId ,
12151216) {
12161217 let Some ( ty) = column. head_ty ( ) else {
12171218 return ;
12181219 } ;
1219- let pcx = & PatCtxt { cx, ty, span : DUMMY_SP , is_top_level : false } ;
1220+ let pcx = & PatCtxt { cx, ty, is_top_level : false } ;
12201221
12211222 let set = column. analyze_ctors ( pcx) ;
12221223
@@ -1230,7 +1231,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
12301231 . collect ( ) ;
12311232 cx. tcx . emit_spanned_lint (
12321233 lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
1233- lint_root ,
1234+ cx . match_lint_level ,
12341235 this_span,
12351236 OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
12361237 ) ;
@@ -1275,7 +1276,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
12751276 // Recurse into the fields.
12761277 for ctor in set. present {
12771278 for col in column. specialize ( pcx, & ctor) {
1278- lint_overlapping_range_endpoints ( cx, & col, lint_root ) ;
1279+ lint_overlapping_range_endpoints ( cx, & col) ;
12791280 }
12801281 }
12811282 }
@@ -1316,9 +1317,7 @@ pub(crate) struct UsefulnessReport<'p, 'tcx> {
13161317pub ( crate ) fn compute_match_usefulness < ' p , ' tcx > (
13171318 cx : & MatchCheckCtxt < ' p , ' tcx > ,
13181319 arms : & [ MatchArm < ' p , ' tcx > ] ,
1319- lint_root : HirId ,
13201320 scrut_ty : Ty < ' tcx > ,
1321- scrut_span : Span ,
13221321) -> UsefulnessReport < ' p , ' tcx > {
13231322 let mut matrix = Matrix :: new ( cx, arms. iter ( ) , scrut_ty) ;
13241323 let non_exhaustiveness_witnesses =
@@ -1342,13 +1341,13 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
13421341
13431342 let pat_column = PatternColumn :: new ( matrix. heads ( ) . collect ( ) ) ;
13441343 // Lint on ranges that overlap on their endpoints, which is likely a mistake.
1345- lint_overlapping_range_endpoints ( cx, & pat_column, lint_root ) ;
1344+ lint_overlapping_range_endpoints ( cx, & pat_column) ;
13461345
13471346 // Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
13481347 // `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
13491348 if cx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
13501349 if !matches ! (
1351- cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , lint_root ) . 0 ,
1350+ cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , cx . match_lint_level ) . 0 ,
13521351 rustc_session:: lint:: Level :: Allow
13531352 ) {
13541353 let witnesses = collect_nonexhaustive_missing_variants ( cx, & pat_column) ;
@@ -1359,11 +1358,11 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
13591358 // NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
13601359 cx. tcx . emit_spanned_lint (
13611360 NON_EXHAUSTIVE_OMITTED_PATTERNS ,
1362- lint_root ,
1363- scrut_span,
1361+ cx . match_lint_level ,
1362+ cx . scrut_span ,
13641363 NonExhaustiveOmittedPattern {
13651364 scrut_ty,
1366- uncovered : Uncovered :: new ( scrut_span, cx, witnesses) ,
1365+ uncovered : Uncovered :: new ( cx . scrut_span , cx, witnesses) ,
13671366 } ,
13681367 ) ;
13691368 }
0 commit comments