@@ -11,15 +11,15 @@ use hir_def::{ItemContainerId, Lookup};
11
11
use hir_expand:: name;
12
12
use itertools:: Itertools ;
13
13
use rustc_hash:: FxHashSet ;
14
+ use rustc_pattern_analysis:: usefulness:: { compute_match_usefulness, ValidityConstraint } ;
14
15
use triomphe:: Arc ;
15
16
use typed_arena:: Arena ;
16
17
17
18
use crate :: {
18
19
db:: HirDatabase ,
19
20
diagnostics:: match_check:: {
20
21
self ,
21
- deconstruct_pat:: DeconstructedPat ,
22
- usefulness:: { compute_match_usefulness, MatchCheckCtx } ,
22
+ pat_analysis:: { self , DeconstructedPat , MatchCheckCtx , WitnessPat } ,
23
23
} ,
24
24
display:: HirDisplay ,
25
25
InferenceResult , Ty , TyExt ,
@@ -152,7 +152,14 @@ impl ExprValidator {
152
152
}
153
153
154
154
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
+ ) ;
156
163
157
164
let mut m_arms = Vec :: with_capacity ( arms. len ( ) ) ;
158
165
let mut has_lowering_errors = false ;
@@ -178,9 +185,10 @@ impl ExprValidator {
178
185
// If we had a NotUsefulMatchArm diagnostic, we could
179
186
// check the usefulness of each pattern as we added it
180
187
// to the matrix here.
181
- let m_arm = match_check :: MatchArm {
188
+ let m_arm = pat_analysis :: MatchArm {
182
189
pat : self . lower_pattern ( & cx, arm. pat , db, & body, & mut has_lowering_errors) ,
183
190
has_guard : arm. guard . is_some ( ) ,
191
+ arm_data : ( ) ,
184
192
} ;
185
193
m_arms. push ( m_arm) ;
186
194
if !has_lowering_errors {
@@ -197,7 +205,15 @@ impl ExprValidator {
197
205
return ;
198
206
}
199
207
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
+ } ;
201
217
202
218
// FIXME Report unreachable arms
203
219
// 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 {
213
229
214
230
fn lower_pattern < ' p > (
215
231
& self ,
216
- cx : & MatchCheckCtx < ' _ , ' p > ,
232
+ cx : & MatchCheckCtx < ' p > ,
217
233
pat : PatId ,
218
234
db : & dyn HirDatabase ,
219
235
body : & Body ,
220
236
have_errors : & mut bool ,
221
237
) -> & ' p DeconstructedPat < ' p > {
222
238
let mut patcx = match_check:: PatCtxt :: new ( db, & self . infer , body) ;
223
239
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) ) ;
225
241
if !patcx. errors . is_empty ( ) {
226
242
* have_errors = true ;
227
243
}
@@ -364,16 +380,16 @@ fn types_of_subpatterns_do_match(pat: PatId, body: &Body, infer: &InferenceResul
364
380
}
365
381
366
382
fn missing_match_arms < ' p > (
367
- cx : & MatchCheckCtx < ' _ , ' p > ,
383
+ cx : & MatchCheckCtx < ' p > ,
368
384
scrut_ty : & Ty ,
369
- witnesses : Vec < DeconstructedPat < ' p > > ,
385
+ witnesses : Vec < WitnessPat < ' p > > ,
370
386
arms : & [ MatchArm ] ,
371
387
) -> String {
372
- struct DisplayWitness < ' a , ' p > ( & ' a DeconstructedPat < ' p > , & ' a MatchCheckCtx < ' a , ' p > ) ;
388
+ struct DisplayWitness < ' a , ' p > ( & ' a WitnessPat < ' p > , & ' a MatchCheckCtx < ' p > ) ;
373
389
impl fmt:: Display for DisplayWitness < ' _ , ' _ > {
374
390
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
375
391
let DisplayWitness ( witness, cx) = * self ;
376
- let pat = witness . to_pat ( cx ) ;
392
+ let pat = cx . hoist_witness_pat ( witness ) ;
377
393
write ! ( f, "{}" , pat. display( cx. db) )
378
394
}
379
395
}
0 commit comments