@@ -11,15 +11,15 @@ use hir_def::{ItemContainerId, Lookup};
1111use hir_expand:: name;
1212use itertools:: Itertools ;
1313use rustc_hash:: FxHashSet ;
14+ use rustc_pattern_analysis:: usefulness:: { compute_match_usefulness, ValidityConstraint } ;
1415use triomphe:: Arc ;
1516use typed_arena:: Arena ;
1617
1718use crate :: {
1819 db:: HirDatabase ,
1920 diagnostics:: match_check:: {
2021 self ,
21- deconstruct_pat:: DeconstructedPat ,
22- usefulness:: { compute_match_usefulness, MatchCheckCtx } ,
22+ pat_analysis:: { self , DeconstructedPat , MatchCheckCtx , WitnessPat } ,
2323 } ,
2424 display:: HirDisplay ,
2525 InferenceResult , Ty , TyExt ,
@@ -152,7 +152,14 @@ impl ExprValidator {
152152 }
153153
154154 let pattern_arena = Arena :: new ( ) ;
155- let cx = MatchCheckCtx :: new ( self . owner . module ( db. upcast ( ) ) , self . owner , db, & pattern_arena) ;
155+ let ty_arena = Arena :: new ( ) ;
156+ let cx = MatchCheckCtx :: new (
157+ self . owner . module ( db. upcast ( ) ) ,
158+ self . owner ,
159+ db,
160+ & pattern_arena,
161+ & ty_arena,
162+ ) ;
156163
157164 let mut m_arms = Vec :: with_capacity ( arms. len ( ) ) ;
158165 let mut has_lowering_errors = false ;
@@ -178,9 +185,10 @@ impl ExprValidator {
178185 // If we had a NotUsefulMatchArm diagnostic, we could
179186 // check the usefulness of each pattern as we added it
180187 // to the matrix here.
181- let m_arm = match_check :: MatchArm {
188+ let m_arm = pat_analysis :: MatchArm {
182189 pat : self . lower_pattern ( & cx, arm. pat , db, & body, & mut has_lowering_errors) ,
183190 has_guard : arm. guard . is_some ( ) ,
191+ arm_data : ( ) ,
184192 } ;
185193 m_arms. push ( m_arm) ;
186194 if !has_lowering_errors {
@@ -197,7 +205,15 @@ impl ExprValidator {
197205 return ;
198206 }
199207
200- let report = compute_match_usefulness ( & cx, & m_arms, scrut_ty) ;
208+ let report = match compute_match_usefulness (
209+ rustc_pattern_analysis:: MatchCtxt { tycx : & cx } ,
210+ m_arms. as_slice ( ) ,
211+ scrut_ty. clone ( ) ,
212+ ValidityConstraint :: ValidOnly ,
213+ ) {
214+ Ok ( report) => report,
215+ Err ( void) => match void { } ,
216+ } ;
201217
202218 // FIXME Report unreachable arms
203219 // https://github.com/rust-lang/rust/blob/f31622a50/compiler/rustc_mir_build/src/thir/pattern/check_match.rs#L200
@@ -213,15 +229,15 @@ impl ExprValidator {
213229
214230 fn lower_pattern < ' p > (
215231 & self ,
216- cx : & MatchCheckCtx < ' _ , ' p > ,
232+ cx : & MatchCheckCtx < ' p > ,
217233 pat : PatId ,
218234 db : & dyn HirDatabase ,
219235 body : & Body ,
220236 have_errors : & mut bool ,
221237 ) -> & ' p DeconstructedPat < ' p > {
222238 let mut patcx = match_check:: PatCtxt :: new ( db, & self . infer , body) ;
223239 let pattern = patcx. lower_pattern ( pat) ;
224- let pattern = cx. pattern_arena . alloc ( DeconstructedPat :: from_pat ( cx , & pattern) ) ;
240+ let pattern = cx. pattern_arena . alloc ( cx . lower_pat ( & pattern) ) ;
225241 if !patcx. errors . is_empty ( ) {
226242 * have_errors = true ;
227243 }
@@ -364,16 +380,16 @@ fn types_of_subpatterns_do_match(pat: PatId, body: &Body, infer: &InferenceResul
364380}
365381
366382fn missing_match_arms < ' p > (
367- cx : & MatchCheckCtx < ' _ , ' p > ,
383+ cx : & MatchCheckCtx < ' p > ,
368384 scrut_ty : & Ty ,
369- witnesses : Vec < DeconstructedPat < ' p > > ,
385+ witnesses : Vec < WitnessPat < ' p > > ,
370386 arms : & [ MatchArm ] ,
371387) -> String {
372- struct DisplayWitness < ' a , ' p > ( & ' a DeconstructedPat < ' p > , & ' a MatchCheckCtx < ' a , ' p > ) ;
388+ struct DisplayWitness < ' a , ' p > ( & ' a WitnessPat < ' p > , & ' a MatchCheckCtx < ' p > ) ;
373389 impl fmt:: Display for DisplayWitness < ' _ , ' _ > {
374390 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
375391 let DisplayWitness ( witness, cx) = * self ;
376- let pat = witness . to_pat ( cx ) ;
392+ let pat = cx . hoist_witness_pat ( witness ) ;
377393 write ! ( f, "{}" , pat. display( cx. db) )
378394 }
379395 }
0 commit comments