@@ -49,6 +49,7 @@ use std::{
49
49
50
50
use hir_def:: { EnumVariantId , HasModule , LocalFieldId , VariantId } ;
51
51
use smallvec:: { smallvec, SmallVec } ;
52
+ use stdx:: never;
52
53
53
54
use crate :: { AdtId , Interner , Scalar , Ty , TyExt , TyKind } ;
54
55
@@ -324,7 +325,10 @@ impl Constructor {
324
325
PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Single ,
325
326
& PatKind :: Variant { enum_variant, .. } => Variant ( enum_variant) ,
326
327
& PatKind :: LiteralBool { value } => IntRange ( IntRange :: from_bool ( value) ) ,
327
- PatKind :: Or { .. } => cx. bug ( "Or-pattern should have been expanded earlier on." ) ,
328
+ PatKind :: Or { .. } => {
329
+ never ! ( "Or-pattern should have been expanded earlier on." ) ;
330
+ Wildcard
331
+ }
328
332
}
329
333
}
330
334
@@ -371,7 +375,7 @@ impl Constructor {
371
375
/// this checks for inclusion.
372
376
// We inline because this has a single call site in `Matrix::specialize_constructor`.
373
377
#[ inline]
374
- pub ( super ) fn is_covered_by ( & self , pcx : PatCtxt < ' _ > , other : & Self ) -> bool {
378
+ pub ( super ) fn is_covered_by ( & self , _pcx : PatCtxt < ' _ > , other : & Self ) -> bool {
375
379
// This must be kept in sync with `is_covered_by_any`.
376
380
match ( self , other) {
377
381
// Wildcards cover anything
@@ -396,17 +400,18 @@ impl Constructor {
396
400
// Only a wildcard pattern can match the special extra constructor.
397
401
( NonExhaustive , _) => false ,
398
402
399
- _ => pcx. cx . bug ( & format ! (
400
- "trying to compare incompatible constructors {:?} and {:?}" ,
401
- self , other
402
- ) ) ,
403
+ _ => {
404
+ never ! ( "trying to compare incompatible constructors {:?} and {:?}" , self , other) ;
405
+ // Continue with 'whatever is covered' supposed to result in false no-error diagnostic.
406
+ true
407
+ }
403
408
}
404
409
}
405
410
406
411
/// Faster version of `is_covered_by` when applied to many constructors. `used_ctors` is
407
412
/// assumed to be built from `matrix.head_ctors()` with wildcards filtered out, and `self` is
408
413
/// assumed to have been split from a wildcard.
409
- fn is_covered_by_any ( & self , pcx : PatCtxt < ' _ > , used_ctors : & [ Constructor ] ) -> bool {
414
+ fn is_covered_by_any ( & self , _pcx : PatCtxt < ' _ > , used_ctors : & [ Constructor ] ) -> bool {
410
415
if used_ctors. is_empty ( ) {
411
416
return false ;
412
417
}
@@ -427,7 +432,8 @@ impl Constructor {
427
432
// This constructor is never covered by anything else
428
433
NonExhaustive => false ,
429
434
Str ( ..) | FloatRange ( ..) | Opaque | Missing | Wildcard => {
430
- pcx. cx . bug ( & format ! ( "found unexpected ctor in all_ctors: {:?}" , self ) )
435
+ never ! ( "found unexpected ctor in all_ctors: {:?}" , self ) ;
436
+ true
431
437
}
432
438
}
433
439
}
@@ -683,7 +689,8 @@ impl Fields {
683
689
}
684
690
}
685
691
ty_kind => {
686
- cx. bug ( & format ! ( "Unexpected type for `Single` constructor: {:?}" , ty_kind) )
692
+ never ! ( "Unexpected type for `Single` constructor: {:?}" , ty_kind) ;
693
+ Fields :: from_single_pattern ( wildcard_from_ty ( ty) )
687
694
}
688
695
} ,
689
696
Slice ( ..) => {
@@ -745,7 +752,8 @@ impl Fields {
745
752
// can ignore this issue.
746
753
TyKind :: Ref ( ..) => PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) } ,
747
754
TyKind :: Slice ( ..) | TyKind :: Array ( ..) => {
748
- pcx. cx . bug ( & format ! ( "bad slice pattern {:?} {:?}" , ctor, pcx. ty) )
755
+ never ! ( "bad slice pattern {:?} {:?}" , ctor, pcx. ty) ;
756
+ PatKind :: Wild
749
757
}
750
758
_ => PatKind :: Wild ,
751
759
} ,
@@ -755,11 +763,17 @@ impl Fields {
755
763
Constructor :: IntRange ( _) => UNHANDLED ,
756
764
NonExhaustive => PatKind :: Wild ,
757
765
Wildcard => return Pat :: wildcard_from_ty ( pcx. ty . clone ( ) ) ,
758
- Opaque => pcx. cx . bug ( "we should not try to apply an opaque constructor" ) ,
759
- Missing => pcx. cx . bug (
760
- "trying to apply the `Missing` constructor;\
761
- this should have been done in `apply_constructors`",
762
- ) ,
766
+ Opaque => {
767
+ never ! ( "we should not try to apply an opaque constructor" ) ;
768
+ PatKind :: Wild
769
+ }
770
+ Missing => {
771
+ never ! (
772
+ "trying to apply the `Missing` constructor; \
773
+ this should have been done in `apply_constructors`",
774
+ ) ;
775
+ PatKind :: Wild
776
+ }
763
777
} ;
764
778
765
779
Pat { ty : pcx. ty . clone ( ) , kind : Box :: new ( pat) }
0 commit comments