@@ -191,8 +191,15 @@ 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:: 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 } ) ;
196
203
}
197
204
} else if !self . saw_const_match_lint . get ( ) {
198
205
if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
@@ -327,15 +334,15 @@ impl<'tcx> ConstToPat<'tcx> {
327
334
}
328
335
ty:: FnDef ( ..) => {
329
336
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 ) ) }
332
339
}
333
340
ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
334
341
debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
335
342
self . saw_const_match_error . set ( true ) ;
336
343
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 ) ) }
339
346
}
340
347
ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
341
348
let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -406,12 +413,18 @@ impl<'tcx> ConstToPat<'tcx> {
406
413
}
407
414
return Err ( FallbackToConstRef ) ;
408
415
} 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 {
410
421
self . saw_const_match_error . set ( true ) ;
411
422
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
+ }
413
427
}
414
- PatKind :: Wild
415
428
}
416
429
}
417
430
// All other references are converted into deref patterns and then recursively
@@ -420,10 +433,10 @@ impl<'tcx> ConstToPat<'tcx> {
420
433
_ => {
421
434
if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
422
435
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
+ }
427
440
} else {
428
441
let old = self . behind_reference . replace ( true ) ;
429
442
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -452,8 +465,8 @@ impl<'tcx> ConstToPat<'tcx> {
452
465
_ => {
453
466
self . saw_const_match_error . set ( true ) ;
454
467
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 ) ) }
457
470
}
458
471
} ;
459
472
0 commit comments