@@ -180,23 +180,26 @@ impl<'tcx> ConstToPat<'tcx> {
180180
181181 if let Some ( non_sm_ty) = structural {
182182 if !self . type_has_partial_eq_impl ( cv. ty ( ) ) {
183- if let ty:: Adt ( def, ..) = non_sm_ty. kind ( ) {
183+ let e = if let ty:: Adt ( def, ..) = non_sm_ty. kind ( ) {
184184 if def. is_union ( ) {
185185 let err = UnionPattern { span : self . span } ;
186- self . tcx ( ) . sess . emit_err ( err) ;
186+ self . tcx ( ) . sess . emit_err ( err)
187187 } else {
188188 // fatal avoids ICE from resolution of nonexistent method (rare case).
189189 self . tcx ( )
190190 . sess
191- . emit_fatal ( TypeNotStructural { span : self . span , non_sm_ty } ) ;
191+ . emit_fatal ( TypeNotStructural { span : self . span , non_sm_ty } )
192192 }
193193 } else {
194194 let err = InvalidPattern { span : self . span , non_sm_ty } ;
195- self . tcx ( ) . sess . emit_err ( err) ;
196- }
195+ self . tcx ( ) . sess . emit_err ( err)
196+ } ;
197197 // All branches above emitted an error. Don't print any more lints.
198198 // The pattern we return is irrelevant since we errored.
199- return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
199+ let kind = PatKind :: Constant {
200+ value : mir:: Const :: Ty ( ty:: Const :: new_error ( self . tcx ( ) , e, cv. ty ( ) ) ) ,
201+ } ;
202+ return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind } ) ;
200203 } else if !self . saw_const_match_lint . get ( ) {
201204 if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
202205 match non_sm_ty. kind ( ) {
@@ -346,15 +349,15 @@ impl<'tcx> ConstToPat<'tcx> {
346349 }
347350 ty:: FnDef ( ..) => {
348351 self . saw_const_match_error . set ( true ) ;
349- tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
350- PatKind :: Wild
352+ let e = tcx. sess . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
353+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
351354 }
352355 ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
353356 debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
354357 self . saw_const_match_error . set ( true ) ;
355358 let err = TypeNotStructural { span, non_sm_ty : ty } ;
356- tcx. sess . emit_err ( err) ;
357- PatKind :: Wild
359+ let e = tcx. sess . emit_err ( err) ;
360+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
358361 }
359362 ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
360363 let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -425,12 +428,18 @@ impl<'tcx> ConstToPat<'tcx> {
425428 }
426429 return Err ( FallbackToConstRef ) ;
427430 } else {
428- if !self . saw_const_match_error . get ( ) {
431+ if self . saw_const_match_error . get ( ) {
432+ PatKind :: Constant {
433+ value : mir:: Const :: Ty ( ty:: Const :: new_misc_error ( tcx, ty) ) ,
434+ }
435+ } else {
429436 self . saw_const_match_error . set ( true ) ;
430437 let err = TypeNotStructural { span, non_sm_ty : * pointee_ty } ;
431- tcx. sess . emit_err ( err) ;
438+ let e = tcx. sess . emit_err ( err) ;
439+ PatKind :: Constant {
440+ value : mir:: Const :: Ty ( ty:: Const :: new_error ( tcx, e, ty) ) ,
441+ }
432442 }
433- PatKind :: Wild
434443 }
435444 }
436445 // All other references are converted into deref patterns and then recursively
@@ -439,10 +448,10 @@ impl<'tcx> ConstToPat<'tcx> {
439448 _ => {
440449 if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
441450 let err = UnsizedPattern { span, non_sm_ty : * pointee_ty } ;
442- tcx. sess . emit_err ( err) ;
443-
444- // FIXME: introduce PatKind::Error to silence follow up diagnostics due to unreachable patterns.
445- PatKind :: Wild
451+ let e = tcx. sess . emit_err ( err) ;
452+ PatKind :: Constant {
453+ value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) ,
454+ }
446455 } else {
447456 let old = self . behind_reference . replace ( true ) ;
448457 // `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -471,8 +480,8 @@ impl<'tcx> ConstToPat<'tcx> {
471480 _ => {
472481 self . saw_const_match_error . set ( true ) ;
473482 let err = InvalidPattern { span, non_sm_ty : ty } ;
474- tcx. sess . emit_err ( err) ;
475- PatKind :: Wild
483+ let e = tcx. sess . emit_err ( err) ;
484+ PatKind :: Constant { value : mir :: Const :: Ty ( ty :: Const :: new_error ( tcx , e , ty ) ) }
476485 }
477486 } ;
478487
0 commit comments