1- use rustc_pattern_analysis:: constructor:: Constructor ;
2- use rustc_pattern_analysis:: cx:: MatchCheckCtxt ;
31use 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 , RustcMatchCheckCtxt as MatchCheckCtxt , Usefulness ,
4+ UsefulnessReport , WitnessPat ,
5+ } ;
66use rustc_pattern_analysis:: { analyze_match, MatchArm } ;
77
88use crate :: errors:: * ;
99
10- use rustc_arena:: TypedArena ;
10+ use rustc_arena:: { DroplessArena , TypedArena } ;
1111use rustc_ast:: Mutability ;
1212use rustc_data_structures:: fx:: FxIndexSet ;
1313use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -31,13 +31,15 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
3131 let ( thir, expr) = tcx. thir_body ( def_id) ?;
3232 let thir = thir. borrow ( ) ;
3333 let pattern_arena = TypedArena :: default ( ) ;
34+ let dropless_arena = DroplessArena :: default ( ) ;
3435 let mut visitor = MatchVisitor {
3536 tcx,
3637 thir : & * thir,
3738 param_env : tcx. param_env ( def_id) ,
3839 lint_level : tcx. local_def_id_to_hir_id ( def_id) ,
3940 let_source : LetSource :: None ,
4041 pattern_arena : & pattern_arena,
42+ dropless_arena : & dropless_arena,
4143 error : Ok ( ( ) ) ,
4244 } ;
4345 visitor. visit_expr ( & thir[ expr] ) ;
@@ -82,6 +84,7 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
8284 lint_level : HirId ,
8385 let_source : LetSource ,
8486 pattern_arena : & ' p TypedArena < DeconstructedPat < ' p , ' tcx > > ,
87+ dropless_arena : & ' p DroplessArena ,
8588 /// Tracks if we encountered an error while checking this body. That the first function to
8689 /// report it stores it here. Some functions return `Result` to allow callers to short-circuit
8790 /// on error, but callers don't need to store it here again.
@@ -382,6 +385,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
382385 param_env : self . param_env ,
383386 module : self . tcx . parent_module ( self . lint_level ) . to_def_id ( ) ,
384387 pattern_arena : self . pattern_arena ,
388+ dropless_arena : self . dropless_arena ,
385389 match_lint_level : self . lint_level ,
386390 whole_match_span,
387391 scrut_span,
@@ -425,7 +429,8 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
425429 let arm = & self . thir . arms [ arm] ;
426430 let got_error = self . with_lint_level ( arm. lint_level , |this| {
427431 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 ( ) } ;
429434 tarms. push ( arm) ;
430435 false
431436 } ) ;
@@ -548,7 +553,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
548553 ) -> Result < ( MatchCheckCtxt < ' p , ' tcx > , UsefulnessReport < ' p , ' tcx > ) , ErrorGuaranteed > {
549554 let cx = self . new_cx ( refutability, None , scrut, pat. span ) ;
550555 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 } ] ;
552557 let report = analyze_match ( & cx, & arms, pat. ty ( ) ) ;
553558 Ok ( ( cx, report) )
554559 }
@@ -847,34 +852,34 @@ fn report_arm_reachability<'p, 'tcx>(
847852 ) ;
848853 } ;
849854
850- use Usefulness :: * ;
851855 let mut catchall = None ;
852856 for ( arm, is_useful) in report. arm_usefulness . iter ( ) {
853857 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 . data ( ) , arm. arm_data , catchall)
860+ }
861+ Usefulness :: Useful ( redundant_subpats) if redundant_subpats. is_empty ( ) => { }
856862 // The arm is reachable, but contains redundant subpatterns (from or-patterns).
857- Useful ( redundant_spans ) => {
858- let mut redundant_spans = redundant_spans . clone ( ) ;
863+ Usefulness :: Useful ( redundant_subpats ) => {
864+ let mut redundant_subpats = redundant_subpats . clone ( ) ;
859865 // Emit lints in the order in which they occur in the file.
860- redundant_spans . sort_unstable ( ) ;
861- for span in redundant_spans {
862- report_unreachable_pattern ( span , arm. hir_id , None ) ;
866+ redundant_subpats . sort_unstable_by_key ( |pat| pat . data ( ) ) ;
867+ for pat in redundant_subpats {
868+ report_unreachable_pattern ( * pat . data ( ) , arm. arm_data , None ) ;
863869 }
864870 }
865871 }
866872 if !arm. has_guard && catchall. is_none ( ) && pat_is_catchall ( arm. pat ) {
867- catchall = Some ( arm. pat . span ( ) ) ;
873+ catchall = Some ( * arm. pat . data ( ) ) ;
868874 }
869875 }
870876}
871877
872878/// Checks for common cases of "catchall" patterns that may not be intended as such.
873879fn pat_is_catchall ( pat : & DeconstructedPat < ' _ , ' _ > ) -> bool {
874- use Constructor :: * ;
875880 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) ) ,
878883 _ => false ,
879884 }
880885}
@@ -885,7 +890,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
885890 thir : & Thir < ' tcx > ,
886891 scrut_ty : Ty < ' tcx > ,
887892 sp : Span ,
888- witnesses : Vec < WitnessPat < ' tcx > > ,
893+ witnesses : Vec < WitnessPat < ' p , ' tcx > > ,
889894 arms : & [ ArmId ] ,
890895 expr_span : Span ,
891896) -> ErrorGuaranteed {
@@ -1082,10 +1087,10 @@ fn report_non_exhaustive_match<'p, 'tcx>(
10821087
10831088fn joined_uncovered_patterns < ' p , ' tcx > (
10841089 cx : & MatchCheckCtxt < ' p , ' tcx > ,
1085- witnesses : & [ WitnessPat < ' tcx > ] ,
1090+ witnesses : & [ WitnessPat < ' p , ' tcx > ] ,
10861091) -> String {
10871092 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 ( ) ;
10891094 match witnesses {
10901095 [ ] => bug ! ( ) ,
10911096 [ witness] => format ! ( "`{}`" , cx. hoist_witness_pat( witness) ) ,
@@ -1103,7 +1108,7 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11031108
11041109fn collect_non_exhaustive_tys < ' tcx > (
11051110 cx : & MatchCheckCtxt < ' _ , ' tcx > ,
1106- pat : & WitnessPat < ' tcx > ,
1111+ pat : & WitnessPat < ' _ , ' tcx > ,
11071112 non_exhaustive_tys : & mut FxIndexSet < Ty < ' tcx > > ,
11081113) {
11091114 if matches ! ( pat. ctor( ) , Constructor :: NonExhaustive ) {
@@ -1122,7 +1127,7 @@ fn collect_non_exhaustive_tys<'tcx>(
11221127fn report_adt_defined_here < ' tcx > (
11231128 tcx : TyCtxt < ' tcx > ,
11241129 ty : Ty < ' tcx > ,
1125- witnesses : & [ WitnessPat < ' tcx > ] ,
1130+ witnesses : & [ WitnessPat < ' _ , ' tcx > ] ,
11261131 point_at_non_local_ty : bool ,
11271132) -> Option < AdtDefinedHere < ' tcx > > {
11281133 let ty = ty. peel_refs ( ) ;
@@ -1144,15 +1149,14 @@ fn report_adt_defined_here<'tcx>(
11441149 Some ( AdtDefinedHere { adt_def_span, ty, variants } )
11451150}
11461151
1147- fn maybe_point_at_variant < ' a , ' tcx : ' a > (
1152+ fn maybe_point_at_variant < ' a , ' p : ' a , ' tcx : ' p > (
11481153 tcx : TyCtxt < ' tcx > ,
11491154 def : AdtDef < ' tcx > ,
1150- patterns : impl Iterator < Item = & ' a WitnessPat < ' tcx > > ,
1155+ patterns : impl Iterator < Item = & ' a WitnessPat < ' p , ' tcx > > ,
11511156) -> Vec < Span > {
1152- use Constructor :: * ;
11531157 let mut covered = vec ! [ ] ;
11541158 for pattern in patterns {
1155- if let Variant ( variant_index) = pattern. ctor ( ) {
1159+ if let Constructor :: Variant ( variant_index) = pattern. ctor ( ) {
11561160 if let ty:: Adt ( this_def, _) = pattern. ty ( ) . kind ( )
11571161 && this_def. did ( ) != def. did ( )
11581162 {
0 commit comments