@@ -49,6 +49,7 @@ use std::{
4949
5050use hir_def:: { EnumVariantId , HasModule , LocalFieldId , VariantId } ;
5151use smallvec:: { smallvec, SmallVec } ;
52+ use stdx:: never;
5253
5354use crate :: { AdtId , Interner , Scalar , Ty , TyExt , TyKind } ;
5455
@@ -324,7 +325,10 @@ impl Constructor {
324325 PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Single ,
325326 & PatKind :: Variant { enum_variant, .. } => Variant ( enum_variant) ,
326327 & 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+ }
328332 }
329333 }
330334
@@ -371,7 +375,7 @@ impl Constructor {
371375 /// this checks for inclusion.
372376 // We inline because this has a single call site in `Matrix::specialize_constructor`.
373377 #[ 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 {
375379 // This must be kept in sync with `is_covered_by_any`.
376380 match ( self , other) {
377381 // Wildcards cover anything
@@ -396,17 +400,18 @@ impl Constructor {
396400 // Only a wildcard pattern can match the special extra constructor.
397401 ( NonExhaustive , _) => false ,
398402
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+ }
403408 }
404409 }
405410
406411 /// Faster version of `is_covered_by` when applied to many constructors. `used_ctors` is
407412 /// assumed to be built from `matrix.head_ctors()` with wildcards filtered out, and `self` is
408413 /// 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 {
410415 if used_ctors. is_empty ( ) {
411416 return false ;
412417 }
@@ -427,7 +432,8 @@ impl Constructor {
427432 // This constructor is never covered by anything else
428433 NonExhaustive => false ,
429434 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
431437 }
432438 }
433439 }
@@ -683,7 +689,8 @@ impl Fields {
683689 }
684690 }
685691 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) )
687694 }
688695 } ,
689696 Slice ( ..) => {
@@ -745,7 +752,8 @@ impl Fields {
745752 // can ignore this issue.
746753 TyKind :: Ref ( ..) => PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) } ,
747754 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
749757 }
750758 _ => PatKind :: Wild ,
751759 } ,
@@ -755,11 +763,17 @@ impl Fields {
755763 Constructor :: IntRange ( _) => UNHANDLED ,
756764 NonExhaustive => PatKind :: Wild ,
757765 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+ }
763777 } ;
764778
765779 Pat { ty : pcx. ty . clone ( ) , kind : Box :: new ( pat) }
0 commit comments