@@ -252,10 +252,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
252
252
253
253
hir:: PatKind :: Range ( ref lo_expr, ref hi_expr, end) => {
254
254
let ( lo_expr, hi_expr) = ( lo_expr. as_deref ( ) , hi_expr. as_deref ( ) ) ;
255
- // FIXME?: returning `_` can cause inaccurate "unreachable" warnings. This can be
256
- // fixed by returning `PatKind::Const(ConstKind::Error(...))` if #115937 gets
257
- // merged.
258
- self . lower_pattern_range ( lo_expr, hi_expr, end, ty, span) . unwrap_or ( PatKind :: Wild )
255
+ self . lower_pattern_range ( lo_expr, hi_expr, end, ty, span)
256
+ . unwrap_or_else ( PatKind :: Error )
259
257
}
260
258
261
259
hir:: PatKind :: Path ( ref qpath) => {
@@ -423,9 +421,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
423
421
if adt_def. is_enum ( ) {
424
422
let args = match ty. kind ( ) {
425
423
ty:: Adt ( _, args) | ty:: FnDef ( _, args) => args,
426
- ty:: Error ( _ ) => {
424
+ ty:: Error ( e ) => {
427
425
// Avoid ICE (#50585)
428
- return PatKind :: Wild ;
426
+ return PatKind :: Error ( * e ) ;
429
427
}
430
428
_ => bug ! ( "inappropriate type for def: {:?}" , ty) ,
431
429
} ;
@@ -452,7 +450,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
452
450
| Res :: SelfTyAlias { .. }
453
451
| Res :: SelfCtor ( ..) => PatKind :: Leaf { subpatterns } ,
454
452
_ => {
455
- match res {
453
+ let e = match res {
456
454
Res :: Def ( DefKind :: ConstParam , _) => {
457
455
self . tcx . sess . emit_err ( ConstParamInPattern { span } )
458
456
}
@@ -461,7 +459,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
461
459
}
462
460
_ => self . tcx . sess . emit_err ( NonConstPath { span } ) ,
463
461
} ;
464
- PatKind :: Wild
462
+ PatKind :: Error ( e )
465
463
}
466
464
} ;
467
465
@@ -513,14 +511,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
513
511
// It should be assoc consts if there's no error but we cannot resolve it.
514
512
debug_assert ! ( is_associated_const) ;
515
513
516
- self . tcx . sess . emit_err ( AssocConstInPattern { span } ) ;
517
-
518
- return pat_from_kind ( PatKind :: Wild ) ;
514
+ let e = self . tcx . sess . emit_err ( AssocConstInPattern { span } ) ;
515
+ return pat_from_kind ( PatKind :: Error ( e) ) ;
519
516
}
520
517
521
518
Err ( _) => {
522
- self . tcx . sess . emit_err ( CouldNotEvalConstPattern { span } ) ;
523
- return pat_from_kind ( PatKind :: Wild ) ;
519
+ let e = self . tcx . sess . emit_err ( CouldNotEvalConstPattern { span } ) ;
520
+ return pat_from_kind ( PatKind :: Error ( e ) ) ;
524
521
}
525
522
} ;
526
523
@@ -574,12 +571,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
574
571
Err ( ErrorHandled :: TooGeneric ( _) ) => {
575
572
// While `Reported | Linted` cases will have diagnostics emitted already
576
573
// it is not true for TooGeneric case, so we need to give user more information.
577
- self . tcx . sess . emit_err ( ConstPatternDependsOnGenericParameter { span } ) ;
578
- pat_from_kind ( PatKind :: Wild )
574
+ let e = self . tcx . sess . emit_err ( ConstPatternDependsOnGenericParameter { span } ) ;
575
+ pat_from_kind ( PatKind :: Error ( e ) )
579
576
}
580
577
Err ( _) => {
581
- self . tcx . sess . emit_err ( CouldNotEvalConstPattern { span } ) ;
582
- pat_from_kind ( PatKind :: Wild )
578
+ let e = self . tcx . sess . emit_err ( CouldNotEvalConstPattern { span } ) ;
579
+ pat_from_kind ( PatKind :: Error ( e ) )
583
580
}
584
581
}
585
582
}
@@ -629,7 +626,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
629
626
let uneval = mir:: UnevaluatedConst { def : def_id. to_def_id ( ) , args, promoted : None } ;
630
627
debug_assert ! ( !args. has_free_regions( ) ) ;
631
628
632
- let ct = ty:: UnevaluatedConst { def : def_id. to_def_id ( ) , args : args } ;
629
+ let ct = ty:: UnevaluatedConst { def : def_id. to_def_id ( ) , args } ;
633
630
// First try using a valtree in order to destructure the constant into a pattern.
634
631
// FIXME: replace "try to do a thing, then fall back to another thing"
635
632
// but something more principled, like a trait query checking whether this can be turned into a valtree.
@@ -649,10 +646,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
649
646
Ok ( val) => self . const_to_pat ( mir:: Const :: Val ( val, ty) , id, span, None ) . kind ,
650
647
Err ( ErrorHandled :: TooGeneric ( _) ) => {
651
648
// If we land here it means the const can't be evaluated because it's `TooGeneric`.
652
- self . tcx . sess . emit_err ( ConstPatternDependsOnGenericParameter { span } ) ;
653
- PatKind :: Wild
649
+ let e = self . tcx . sess . emit_err ( ConstPatternDependsOnGenericParameter { span } ) ;
650
+ PatKind :: Error ( e )
654
651
}
655
- Err ( ErrorHandled :: Reported ( ..) ) => PatKind :: Wild ,
652
+ Err ( ErrorHandled :: Reported ( err , ..) ) => PatKind :: Error ( err . into ( ) ) ,
656
653
}
657
654
}
658
655
}
@@ -685,7 +682,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
685
682
Ok ( constant) => {
686
683
self . const_to_pat ( Const :: Ty ( constant) , expr. hir_id , lit. span , None ) . kind
687
684
}
688
- Err ( LitToConstError :: Reported ( _ ) ) => PatKind :: Wild ,
685
+ Err ( LitToConstError :: Reported ( e ) ) => PatKind :: Error ( e ) ,
689
686
Err ( LitToConstError :: TypeError ) => bug ! ( "lower_lit: had type error" ) ,
690
687
}
691
688
}
0 commit comments