@@ -191,8 +191,11 @@ impl<'tcx> ConstToPat<'tcx> {
191191 }
192192 } else {
193193 let err = InvalidPattern { span : self . span , non_sm_ty } ;
194- self . tcx ( ) . sess . emit_err ( err) ;
195- return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
194+ let e = self . tcx ( ) . sess . emit_err ( err) ;
195+ let kind = PatKind :: Constant {
196+ value : mir:: Const :: Ty ( ty:: Const :: new_error ( self . tcx ( ) , e, cv. ty ( ) ) ) ,
197+ } ;
198+ return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind } ) ;
196199 }
197200 } else if !self . saw_const_match_lint . get ( ) {
198201 if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
@@ -327,15 +330,15 @@ impl<'tcx> ConstToPat<'tcx> {
327330 }
328331 ty:: FnDef ( ..) => {
329332 self . saw_const_match_error . set ( true ) ;
330- tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
331- PatKind :: Wild
333+ let e = tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
334+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
332335 }
333336 ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
334337 debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
335338 self . saw_const_match_error . set ( true ) ;
336339 let err = TypeNotStructural { span, non_sm_ty : ty } ;
337- tcx. sess . emit_err ( err) ;
338- PatKind :: Wild
340+ let e = tcx. sess . emit_err ( err) ;
341+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
339342 }
340343 ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
341344 let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -406,12 +409,18 @@ impl<'tcx> ConstToPat<'tcx> {
406409 }
407410 return Err ( FallbackToConstRef ) ;
408411 } else {
409- if !self . saw_const_match_error . get ( ) {
412+ if self . saw_const_match_error . get ( ) {
413+ PatKind :: Constant {
414+ value : mir:: Const :: Ty ( ty:: Const :: new_misc_error ( tcx, ty) ) ,
415+ }
416+ } else {
410417 self . saw_const_match_error . set ( true ) ;
411418 let err = TypeNotStructural { span, non_sm_ty : * pointee_ty } ;
412- tcx. sess . emit_err ( err) ;
419+ let e = tcx. sess . emit_err ( err) ;
420+ PatKind :: Constant {
421+ value : mir:: Const :: Ty ( ty:: Const :: new_error ( tcx, e, ty) ) ,
422+ }
413423 }
414- PatKind :: Wild
415424 }
416425 }
417426 // All other references are converted into deref patterns and then recursively
@@ -420,10 +429,10 @@ impl<'tcx> ConstToPat<'tcx> {
420429 _ => {
421430 if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
422431 let err = UnsizedPattern { span, non_sm_ty : * pointee_ty } ;
423- tcx. sess . emit_err ( err) ;
424-
425- // FIXME: introduce PatKind::Error to silence follow up diagnostics due to unreachable patterns.
426- PatKind :: Wild
432+ let e = tcx. sess . emit_err ( err) ;
433+ PatKind :: Constant {
434+ value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) ,
435+ }
427436 } else {
428437 let old = self . behind_reference . replace ( true ) ;
429438 // `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -452,8 +461,8 @@ impl<'tcx> ConstToPat<'tcx> {
452461 _ => {
453462 self . saw_const_match_error . set ( true ) ;
454463 let err = InvalidPattern { span, non_sm_ty : ty } ;
455- tcx. sess . emit_err ( err) ;
456- PatKind :: Wild
464+ let e = tcx. sess . emit_err ( err) ;
465+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
457466 }
458467 } ;
459468
0 commit comments