@@ -43,6 +43,13 @@ pub(crate) struct MatchCheckCtx<'p> {
43
43
pub ( crate ) pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
44
44
ty_arena : & ' p Arena < Ty > ,
45
45
exhaustive_patterns : bool ,
46
+ min_exhaustive_patterns : bool ,
47
+ }
48
+
49
+ #[ derive( Clone ) ]
50
+ pub ( crate ) struct PatData < ' p > {
51
+ /// Keep db around so that we can print variant names in `Debug`.
52
+ pub ( crate ) db : & ' p dyn HirDatabase ,
46
53
}
47
54
48
55
impl < ' p > MatchCheckCtx < ' p > {
@@ -55,7 +62,17 @@ impl<'p> MatchCheckCtx<'p> {
55
62
) -> Self {
56
63
let def_map = db. crate_def_map ( module. krate ( ) ) ;
57
64
let exhaustive_patterns = def_map. is_unstable_feature_enabled ( "exhaustive_patterns" ) ;
58
- Self { module, body, db, pattern_arena, exhaustive_patterns, ty_arena }
65
+ let min_exhaustive_patterns =
66
+ def_map. is_unstable_feature_enabled ( "min_exhaustive_patterns" ) ;
67
+ Self {
68
+ module,
69
+ body,
70
+ db,
71
+ pattern_arena,
72
+ exhaustive_patterns,
73
+ min_exhaustive_patterns,
74
+ ty_arena,
75
+ }
59
76
}
60
77
61
78
fn is_uninhabited ( & self , ty : & Ty ) -> bool {
@@ -238,7 +255,8 @@ impl<'p> MatchCheckCtx<'p> {
238
255
fields = self . pattern_arena . alloc_extend ( subpats) ;
239
256
}
240
257
}
241
- DeconstructedPat :: new ( ctor, fields, pat. ty . clone ( ) , ( ) )
258
+ let data = PatData { db : self . db } ;
259
+ DeconstructedPat :: new ( ctor, fields, pat. ty . clone ( ) , data)
242
260
}
243
261
244
262
pub ( crate ) fn hoist_witness_pat ( & self , pat : & WitnessPat < ' p > ) -> Pat {
@@ -304,11 +322,14 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
304
322
type VariantIdx = EnumVariantId ;
305
323
type StrLit = Void ;
306
324
type ArmData = ( ) ;
307
- type PatData = ( ) ;
325
+ type PatData = PatData < ' p > ;
308
326
309
327
fn is_exhaustive_patterns_feature_on ( & self ) -> bool {
310
328
self . exhaustive_patterns
311
329
}
330
+ fn is_min_exhaustive_patterns_feature_on ( & self ) -> bool {
331
+ self . min_exhaustive_patterns
332
+ }
312
333
313
334
fn ctor_arity (
314
335
& self ,
@@ -344,16 +365,16 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
344
365
}
345
366
}
346
367
347
- fn ctor_sub_tys (
348
- & self ,
349
- ctor : & rustc_pattern_analysis:: constructor:: Constructor < Self > ,
350
- ty : & Self :: Ty ,
351
- ) -> & [ Self :: Ty ] {
368
+ fn ctor_sub_tys < ' a > (
369
+ & ' a self ,
370
+ ctor : & ' a rustc_pattern_analysis:: constructor:: Constructor < Self > ,
371
+ ty : & ' a Self :: Ty ,
372
+ ) -> impl Iterator < Item = Self :: Ty > + ExactSizeIterator + Captures < ' a > {
352
373
use std:: iter:: once;
353
374
fn alloc < ' a > ( cx : & ' a MatchCheckCtx < ' _ > , iter : impl Iterator < Item = Ty > ) -> & ' a [ Ty ] {
354
375
cx. ty_arena . alloc_extend ( iter)
355
376
}
356
- match ctor {
377
+ let slice = match ctor {
357
378
Struct | Variant ( _) | UnionField => match ty. kind ( Interner ) {
358
379
TyKind :: Tuple ( _, substs) => {
359
380
let tys = substs. iter ( Interner ) . map ( |ty| ty. assert_ty_ref ( Interner ) ) ;
@@ -391,7 +412,8 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
391
412
never ! ( "called `Fields::wildcards` on an `Or` ctor" ) ;
392
413
& [ ]
393
414
}
394
- }
415
+ } ;
416
+ slice. into_iter ( ) . cloned ( )
395
417
}
396
418
397
419
fn ctors_for_ty (
@@ -453,11 +475,27 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
453
475
} )
454
476
}
455
477
456
- fn debug_pat (
457
- _f : & mut fmt:: Formatter < ' _ > ,
458
- _pat : & rustc_pattern_analysis:: pat:: DeconstructedPat < ' _ , Self > ,
478
+ fn write_variant_name (
479
+ f : & mut fmt:: Formatter < ' _ > ,
480
+ pat : & rustc_pattern_analysis:: pat:: DeconstructedPat < ' _ , Self > ,
459
481
) -> fmt:: Result {
460
- // FIXME: implement this, as using `unimplemented!()` causes panics in `tracing`.
482
+ let variant =
483
+ pat. ty ( ) . as_adt ( ) . and_then ( |( adt, _) | Self :: variant_id_for_adt ( pat. ctor ( ) , adt) ) ;
484
+
485
+ let db = pat. data ( ) . unwrap ( ) . db ;
486
+ if let Some ( variant) = variant {
487
+ match variant {
488
+ VariantId :: EnumVariantId ( v) => {
489
+ write ! ( f, "{}" , db. enum_variant_data( v) . name. display( db. upcast( ) ) ) ?;
490
+ }
491
+ VariantId :: StructId ( s) => {
492
+ write ! ( f, "{}" , db. struct_data( s) . name. display( db. upcast( ) ) ) ?
493
+ }
494
+ VariantId :: UnionId ( u) => {
495
+ write ! ( f, "{}" , db. union_data( u) . name. display( db. upcast( ) ) ) ?
496
+ }
497
+ }
498
+ }
461
499
Ok ( ( ) )
462
500
}
463
501
0 commit comments