1
- use rustc_pattern_analysis:: constructor:: Constructor ;
2
- use rustc_pattern_analysis:: cx:: MatchCheckCtxt ;
3
1
use rustc_pattern_analysis:: errors:: Uncovered ;
4
- use rustc_pattern_analysis:: pat:: { DeconstructedPat , WitnessPat } ;
5
- use rustc_pattern_analysis:: usefulness:: { Usefulness , UsefulnessReport } ;
2
+ use rustc_pattern_analysis:: rustc:: {
3
+ Constructor , DeconstructedPat , RustcCtxt as MatchCheckCtxt , Usefulness , UsefulnessReport ,
4
+ WitnessPat ,
5
+ } ;
6
6
use rustc_pattern_analysis:: { analyze_match, MatchArm } ;
7
7
8
8
use crate :: errors:: * ;
9
9
10
- use rustc_arena:: TypedArena ;
10
+ use rustc_arena:: { DroplessArena , TypedArena } ;
11
11
use rustc_ast:: Mutability ;
12
12
use rustc_data_structures:: fx:: FxHashSet ;
13
13
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -31,13 +31,15 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
31
31
let ( thir, expr) = tcx. thir_body ( def_id) ?;
32
32
let thir = thir. borrow ( ) ;
33
33
let pattern_arena = TypedArena :: default ( ) ;
34
+ let dropless_arena = DroplessArena :: default ( ) ;
34
35
let mut visitor = MatchVisitor {
35
36
tcx,
36
37
thir : & * thir,
37
38
param_env : tcx. param_env ( def_id) ,
38
39
lint_level : tcx. local_def_id_to_hir_id ( def_id) ,
39
40
let_source : LetSource :: None ,
40
41
pattern_arena : & pattern_arena,
42
+ dropless_arena : & dropless_arena,
41
43
error : Ok ( ( ) ) ,
42
44
} ;
43
45
visitor. visit_expr ( & thir[ expr] ) ;
@@ -82,6 +84,7 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
82
84
lint_level : HirId ,
83
85
let_source : LetSource ,
84
86
pattern_arena : & ' p TypedArena < DeconstructedPat < ' p , ' tcx > > ,
87
+ dropless_arena : & ' p DroplessArena ,
85
88
/// Tracks if we encountered an error while checking this body. That the first function to
86
89
/// report it stores it here. Some functions return `Result` to allow callers to short-circuit
87
90
/// on error, but callers don't need to store it here again.
@@ -382,6 +385,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
382
385
param_env : self . param_env ,
383
386
module : self . tcx . parent_module ( self . lint_level ) . to_def_id ( ) ,
384
387
pattern_arena : self . pattern_arena ,
388
+ dropless_arena : self . dropless_arena ,
385
389
match_lint_level : self . lint_level ,
386
390
whole_match_span,
387
391
scrut_span,
@@ -425,7 +429,8 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
425
429
let arm = & self . thir . arms [ arm] ;
426
430
let got_error = self . with_lint_level ( arm. lint_level , |this| {
427
431
let Ok ( pat) = this. lower_pattern ( & cx, & arm. pattern ) else { return true } ;
428
- let arm = MatchArm { pat, hir_id : this. lint_level , has_guard : arm. guard . is_some ( ) } ;
432
+ let arm =
433
+ MatchArm { pat, arm_data : this. lint_level , has_guard : arm. guard . is_some ( ) } ;
429
434
tarms. push ( arm) ;
430
435
false
431
436
} ) ;
@@ -548,7 +553,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
548
553
) -> Result < ( MatchCheckCtxt < ' p , ' tcx > , UsefulnessReport < ' p , ' tcx > ) , ErrorGuaranteed > {
549
554
let cx = self . new_cx ( refutability, None , scrut, pat. span ) ;
550
555
let pat = self . lower_pattern ( & cx, pat) ?;
551
- let arms = [ MatchArm { pat, hir_id : self . lint_level , has_guard : false } ] ;
556
+ let arms = [ MatchArm { pat, arm_data : self . lint_level , has_guard : false } ] ;
552
557
let report = analyze_match ( & cx, & arms, pat. ty ( ) ) ;
553
558
Ok ( ( cx, report) )
554
559
}
@@ -847,34 +852,34 @@ fn report_arm_reachability<'p, 'tcx>(
847
852
) ;
848
853
} ;
849
854
850
- use Usefulness :: * ;
851
855
let mut catchall = None ;
852
856
for ( arm, is_useful) in report. arm_usefulness . iter ( ) {
853
857
match is_useful {
854
- Redundant => report_unreachable_pattern ( arm. pat . span ( ) , arm. hir_id , catchall) ,
855
- Useful ( redundant_spans) if redundant_spans. is_empty ( ) => { }
858
+ Usefulness :: Redundant => {
859
+ report_unreachable_pattern ( * arm. pat . span ( ) , arm. arm_data , catchall)
860
+ }
861
+ Usefulness :: Useful ( redundant_spans) if redundant_spans. is_empty ( ) => { }
856
862
// The arm is reachable, but contains redundant subpatterns (from or-patterns).
857
- Useful ( redundant_spans) => {
863
+ Usefulness :: Useful ( redundant_spans) => {
858
864
let mut redundant_spans = redundant_spans. clone ( ) ;
859
865
// Emit lints in the order in which they occur in the file.
860
866
redundant_spans. sort_unstable ( ) ;
861
867
for span in redundant_spans {
862
- report_unreachable_pattern ( span, arm. hir_id , None ) ;
868
+ report_unreachable_pattern ( span, arm. arm_data , None ) ;
863
869
}
864
870
}
865
871
}
866
872
if !arm. has_guard && catchall. is_none ( ) && pat_is_catchall ( arm. pat ) {
867
- catchall = Some ( arm. pat . span ( ) ) ;
873
+ catchall = Some ( * arm. pat . span ( ) ) ;
868
874
}
869
875
}
870
876
}
871
877
872
878
/// Checks for common cases of "catchall" patterns that may not be intended as such.
873
879
fn pat_is_catchall ( pat : & DeconstructedPat < ' _ , ' _ > ) -> bool {
874
- use Constructor :: * ;
875
880
match pat. ctor ( ) {
876
- Wildcard => true ,
877
- Single => pat. iter_fields ( ) . all ( |pat| pat_is_catchall ( pat) ) ,
881
+ Constructor :: Wildcard => true ,
882
+ Constructor :: Struct | Constructor :: Ref => pat. iter_fields ( ) . all ( |pat| pat_is_catchall ( pat) ) ,
878
883
_ => false ,
879
884
}
880
885
}
@@ -885,7 +890,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
885
890
thir : & Thir < ' tcx > ,
886
891
scrut_ty : Ty < ' tcx > ,
887
892
sp : Span ,
888
- witnesses : Vec < WitnessPat < ' tcx > > ,
893
+ witnesses : Vec < WitnessPat < ' p , ' tcx > > ,
889
894
arms : & [ ArmId ] ,
890
895
expr_span : Span ,
891
896
) -> ErrorGuaranteed {
@@ -1082,10 +1087,10 @@ fn report_non_exhaustive_match<'p, 'tcx>(
1082
1087
1083
1088
fn joined_uncovered_patterns < ' p , ' tcx > (
1084
1089
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1085
- witnesses : & [ WitnessPat < ' tcx > ] ,
1090
+ witnesses : & [ WitnessPat < ' p , ' tcx > ] ,
1086
1091
) -> String {
1087
1092
const LIMIT : usize = 3 ;
1088
- let pat_to_str = |pat : & WitnessPat < ' tcx > | cx. hoist_witness_pat ( pat) . to_string ( ) ;
1093
+ let pat_to_str = |pat : & WitnessPat < ' p , ' tcx > | cx. hoist_witness_pat ( pat) . to_string ( ) ;
1089
1094
match witnesses {
1090
1095
[ ] => bug ! ( ) ,
1091
1096
[ witness] => format ! ( "`{}`" , cx. hoist_witness_pat( witness) ) ,
@@ -1103,7 +1108,7 @@ fn joined_uncovered_patterns<'p, 'tcx>(
1103
1108
1104
1109
fn collect_non_exhaustive_tys < ' tcx > (
1105
1110
cx : & MatchCheckCtxt < ' _ , ' tcx > ,
1106
- pat : & WitnessPat < ' tcx > ,
1111
+ pat : & WitnessPat < ' _ , ' tcx > ,
1107
1112
non_exhaustive_tys : & mut FxHashSet < Ty < ' tcx > > ,
1108
1113
) {
1109
1114
if matches ! ( pat. ctor( ) , Constructor :: NonExhaustive ) {
@@ -1122,7 +1127,7 @@ fn collect_non_exhaustive_tys<'tcx>(
1122
1127
fn report_adt_defined_here < ' tcx > (
1123
1128
tcx : TyCtxt < ' tcx > ,
1124
1129
ty : Ty < ' tcx > ,
1125
- witnesses : & [ WitnessPat < ' tcx > ] ,
1130
+ witnesses : & [ WitnessPat < ' _ , ' tcx > ] ,
1126
1131
point_at_non_local_ty : bool ,
1127
1132
) -> Option < AdtDefinedHere < ' tcx > > {
1128
1133
let ty = ty. peel_refs ( ) ;
@@ -1144,15 +1149,14 @@ fn report_adt_defined_here<'tcx>(
1144
1149
Some ( AdtDefinedHere { adt_def_span, ty, variants } )
1145
1150
}
1146
1151
1147
- fn maybe_point_at_variant < ' a , ' tcx : ' a > (
1152
+ fn maybe_point_at_variant < ' a , ' p : ' a , ' tcx : ' p > (
1148
1153
tcx : TyCtxt < ' tcx > ,
1149
1154
def : AdtDef < ' tcx > ,
1150
- patterns : impl Iterator < Item = & ' a WitnessPat < ' tcx > > ,
1155
+ patterns : impl Iterator < Item = & ' a WitnessPat < ' p , ' tcx > > ,
1151
1156
) -> Vec < Span > {
1152
- use Constructor :: * ;
1153
1157
let mut covered = vec ! [ ] ;
1154
1158
for pattern in patterns {
1155
- if let Variant ( variant_index) = pattern. ctor ( ) {
1159
+ if let Constructor :: Variant ( variant_index) = pattern. ctor ( ) {
1156
1160
if let ty:: Adt ( this_def, _) = pattern. ty ( ) . kind ( )
1157
1161
&& this_def. did ( ) != def. did ( )
1158
1162
{
0 commit comments