@@ -191,8 +191,15 @@ 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:: ConstantKind :: Ty ( ty:: Const :: new_error (
197+ self . tcx ( ) ,
198+ e,
199+ cv. ty ( ) ,
200+ ) ) ,
201+ } ;
202+ return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind } ) ;
196203 }
197204 } else if !self . saw_const_match_lint . get ( ) {
198205 if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
@@ -327,15 +334,15 @@ impl<'tcx> ConstToPat<'tcx> {
327334 }
328335 ty:: FnDef ( ..) => {
329336 self . saw_const_match_error . set ( true ) ;
330- tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
331- PatKind :: Wild
337+ let e = tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
338+ PatKind :: Constant { value : mir :: ConstantKind :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
332339 }
333340 ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
334341 debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
335342 self . saw_const_match_error . set ( true ) ;
336343 let err = TypeNotStructural { span, non_sm_ty : ty } ;
337- tcx. sess . emit_err ( err) ;
338- PatKind :: Wild
344+ let e = tcx. sess . emit_err ( err) ;
345+ PatKind :: Constant { value : mir :: ConstantKind :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
339346 }
340347 ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
341348 let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -406,12 +413,18 @@ impl<'tcx> ConstToPat<'tcx> {
406413 }
407414 return Err ( FallbackToConstRef ) ;
408415 } else {
409- if !self . saw_const_match_error . get ( ) {
416+ if self . saw_const_match_error . get ( ) {
417+ PatKind :: Constant {
418+ value : mir:: ConstantKind :: Ty ( ty:: Const :: new_misc_error ( tcx, ty) ) ,
419+ }
420+ } else {
410421 self . saw_const_match_error . set ( true ) ;
411422 let err = TypeNotStructural { span, non_sm_ty : * pointee_ty } ;
412- tcx. sess . emit_err ( err) ;
423+ let e = tcx. sess . emit_err ( err) ;
424+ PatKind :: Constant {
425+ value : mir:: ConstantKind :: Ty ( ty:: Const :: new_error ( tcx, e, ty) ) ,
426+ }
413427 }
414- PatKind :: Wild
415428 }
416429 }
417430 // All other references are converted into deref patterns and then recursively
@@ -420,10 +433,10 @@ impl<'tcx> ConstToPat<'tcx> {
420433 _ => {
421434 if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
422435 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
436+ let e = tcx. sess . emit_err ( err) ;
437+ PatKind :: Constant {
438+ value : mir :: ConstantKind :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) ,
439+ }
427440 } else {
428441 let old = self . behind_reference . replace ( true ) ;
429442 // `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -452,8 +465,8 @@ impl<'tcx> ConstToPat<'tcx> {
452465 _ => {
453466 self . saw_const_match_error . set ( true ) ;
454467 let err = InvalidPattern { span, non_sm_ty : ty } ;
455- tcx. sess . emit_err ( err) ;
456- PatKind :: Wild
468+ let e = tcx. sess . emit_err ( err) ;
469+ PatKind :: Constant { value : mir :: ConstantKind :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
457470 }
458471 } ;
459472
0 commit comments