@@ -490,17 +490,29 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
490
490
// convert the dereferenced constant to a pattern that is the sub-pattern of the
491
491
// deref pattern.
492
492
_ => {
493
- let old = self . behind_reference . replace ( true ) ;
494
- // In case there are structural-match violations somewhere in this subpattern,
495
- // we fall back to a const pattern. If we do not do this, we may end up with
496
- // a !structural-match constant that is not of reference type, which makes it
497
- // very hard to invoke `PartialEq::eq` on it as a fallback.
498
- let val = match self . recur ( tcx. deref_const ( self . param_env . and ( cv) ) , false ) {
499
- Ok ( subpattern) => PatKind :: Deref { subpattern } ,
500
- Err ( _) => PatKind :: Constant { value : cv } ,
501
- } ;
502
- self . behind_reference . set ( old) ;
503
- val
493
+ if !pointee_ty. is_sized ( tcx. at ( span) , param_env) {
494
+ // `tcx.deref_const()` below will ICE with an unsized type
495
+ // (except slices, which are handled in a separate arm above).
496
+ let msg = format ! ( "cannot use unsized non-slice type `{}` in constant patterns" , pointee_ty) ;
497
+ if self . include_lint_checks {
498
+ tcx. sess . span_err ( span, & msg) ;
499
+ } else {
500
+ tcx. sess . delay_span_bug ( span, & msg) ;
501
+ }
502
+ PatKind :: Wild
503
+ } else {
504
+ let old = self . behind_reference . replace ( true ) ;
505
+ // In case there are structural-match violations somewhere in this subpattern,
506
+ // we fall back to a const pattern. If we do not do this, we may end up with
507
+ // a !structural-match constant that is not of reference type, which makes it
508
+ // very hard to invoke `PartialEq::eq` on it as a fallback.
509
+ let val = match self . recur ( tcx. deref_const ( self . param_env . and ( cv) ) , false ) {
510
+ Ok ( subpattern) => PatKind :: Deref { subpattern } ,
511
+ Err ( _) => PatKind :: Constant { value : cv } ,
512
+ } ;
513
+ self . behind_reference . set ( old) ;
514
+ val
515
+ }
504
516
}
505
517
} ,
506
518
ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: FnDef ( ..) => {
0 commit comments