@@ -191,8 +191,11 @@ impl<'tcx> ConstToPat<'tcx> {
191
191
}
192
192
} else {
193
193
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 } ) ;
196
199
}
197
200
} else if !self . saw_const_match_lint . get ( ) {
198
201
if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
@@ -327,15 +330,15 @@ impl<'tcx> ConstToPat<'tcx> {
327
330
}
328
331
ty:: FnDef ( ..) => {
329
332
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 ) ) }
332
335
}
333
336
ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
334
337
debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
335
338
self . saw_const_match_error . set ( true ) ;
336
339
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 ) ) }
339
342
}
340
343
ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
341
344
let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -406,12 +409,18 @@ impl<'tcx> ConstToPat<'tcx> {
406
409
}
407
410
return Err ( FallbackToConstRef ) ;
408
411
} 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 {
410
417
self . saw_const_match_error . set ( true ) ;
411
418
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
+ }
413
423
}
414
- PatKind :: Wild
415
424
}
416
425
}
417
426
// All other references are converted into deref patterns and then recursively
@@ -420,10 +429,10 @@ impl<'tcx> ConstToPat<'tcx> {
420
429
_ => {
421
430
if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
422
431
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
+ }
427
436
} else {
428
437
let old = self . behind_reference . replace ( true ) ;
429
438
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -452,8 +461,8 @@ impl<'tcx> ConstToPat<'tcx> {
452
461
_ => {
453
462
self . saw_const_match_error . set ( true ) ;
454
463
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 ) ) }
457
466
}
458
467
} ;
459
468
0 commit comments