@@ -180,23 +180,26 @@ impl<'tcx> ConstToPat<'tcx> {
180
180
181
181
if let Some ( non_sm_ty) = structural {
182
182
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 ( ) {
184
184
if def. is_union ( ) {
185
185
let err = UnionPattern { span : self . span } ;
186
- self . tcx ( ) . sess . emit_err ( err) ;
186
+ self . tcx ( ) . sess . emit_err ( err)
187
187
} else {
188
188
// fatal avoids ICE from resolution of nonexistent method (rare case).
189
189
self . tcx ( )
190
190
. sess
191
- . emit_fatal ( TypeNotStructural { span : self . span , non_sm_ty } ) ;
191
+ . emit_fatal ( TypeNotStructural { span : self . span , non_sm_ty } )
192
192
}
193
193
} else {
194
194
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
+ } ;
197
197
// All branches above emitted an error. Don't print any more lints.
198
198
// 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 } ) ;
200
203
} else if !self . saw_const_match_lint . get ( ) {
201
204
if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
202
205
match non_sm_ty. kind ( ) {
@@ -346,15 +349,15 @@ impl<'tcx> ConstToPat<'tcx> {
346
349
}
347
350
ty:: FnDef ( ..) => {
348
351
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 ) ) }
351
354
}
352
355
ty:: Adt ( adt_def, _) if !self . type_marked_structural ( ty) => {
353
356
debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
354
357
self . saw_const_match_error . set ( true ) ;
355
358
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 ) ) }
358
361
}
359
362
ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) => {
360
363
let ( & variant_index, fields) = cv. unwrap_branch ( ) . split_first ( ) . unwrap ( ) ;
@@ -425,12 +428,18 @@ impl<'tcx> ConstToPat<'tcx> {
425
428
}
426
429
return Err ( FallbackToConstRef ) ;
427
430
} 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 {
429
436
self . saw_const_match_error . set ( true ) ;
430
437
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
+ }
432
442
}
433
- PatKind :: Wild
434
443
}
435
444
}
436
445
// All other references are converted into deref patterns and then recursively
@@ -439,10 +448,10 @@ impl<'tcx> ConstToPat<'tcx> {
439
448
_ => {
440
449
if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
441
450
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
+ }
446
455
} else {
447
456
let old = self . behind_reference . replace ( true ) ;
448
457
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -471,8 +480,8 @@ impl<'tcx> ConstToPat<'tcx> {
471
480
_ => {
472
481
self . saw_const_match_error . set ( true ) ;
473
482
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 ) ) }
476
485
}
477
486
} ;
478
487
0 commit comments