@@ -11,7 +11,7 @@ pub(crate) mod deconstruct_pat;
11
11
pub ( crate ) mod usefulness;
12
12
13
13
use hir_def:: { body:: Body , expr:: PatId , EnumVariantId , LocalFieldId , VariantId } ;
14
- use stdx:: never;
14
+ use stdx:: { always , never} ;
15
15
16
16
use crate :: {
17
17
db:: HirDatabase , infer:: BindingMode , InferenceResult , Interner , Substitution , Ty , TyKind ,
@@ -127,7 +127,11 @@ impl<'a> PatCtxt<'a> {
127
127
hir_def:: expr:: Pat :: Tuple { ref args, ellipsis } => {
128
128
let arity = match * ty. kind ( Interner ) {
129
129
TyKind :: Tuple ( arity, _) => arity,
130
- _ => panic ! ( "unexpected type for tuple pattern: {:?}" , ty) ,
130
+ _ => {
131
+ never ! ( "unexpected type for tuple pattern: {:?}" , ty) ;
132
+ self . errors . push ( PatternError :: UnexpectedType ) ;
133
+ return Pat { ty : ty. clone ( ) , kind : PatKind :: Wild . into ( ) } ;
134
+ }
131
135
} ;
132
136
let subpatterns = self . lower_tuple_subpats ( args, arity, ellipsis) ;
133
137
PatKind :: Leaf { subpatterns }
@@ -227,11 +231,16 @@ impl<'a> PatCtxt<'a> {
227
231
Some ( variant_id) => {
228
232
if let VariantId :: EnumVariantId ( enum_variant) = variant_id {
229
233
let substs = match ty. kind ( Interner ) {
230
- TyKind :: Adt ( _, substs) | TyKind :: FnDef ( _, substs) => substs. clone ( ) ,
231
- TyKind :: Error => {
234
+ TyKind :: Adt ( _, substs) => substs. clone ( ) ,
235
+ kind => {
236
+ always ! (
237
+ matches!( kind, TyKind :: FnDef ( ..) | TyKind :: Error ) ,
238
+ "inappropriate type for def: {:?}" ,
239
+ ty
240
+ ) ;
241
+ self . errors . push ( PatternError :: UnexpectedType ) ;
232
242
return PatKind :: Wild ;
233
243
}
234
- _ => panic ! ( "inappropriate type for def: {:?}" , ty) ,
235
244
} ;
236
245
PatKind :: Variant { substs, enum_variant, subpatterns }
237
246
} else {
0 commit comments