@@ -710,24 +710,27 @@ fn switch_on_enum_discriminant<'mir, 'tcx>(
710710 block : & ' mir mir:: BasicBlockData < ' tcx > ,
711711 switch_on : mir:: Place < ' tcx > ,
712712) -> Option < ( mir:: Place < ' tcx > , & ' tcx ty:: AdtDef ) > {
713- match block. statements . last ( ) . map ( |stmt| & stmt. kind ) {
714- Some ( mir:: StatementKind :: Assign ( box ( lhs, mir:: Rvalue :: Discriminant ( discriminated) ) ) )
715- if * lhs == switch_on =>
716- {
717- match & discriminated. ty ( body, tcx) . ty . kind ( ) {
718- ty:: Adt ( def, _) => Some ( ( * discriminated, def) ) ,
719-
720- // `Rvalue::Discriminant` is also used to get the active yield point for a
721- // generator, but we do not need edge-specific effects in that case. This may
722- // change in the future.
723- ty:: Generator ( ..) => None ,
724-
725- t => bug ! ( "`discriminant` called on unexpected type {:?}" , t) ,
713+ for statement in block. statements . iter ( ) . rev ( ) {
714+ match & statement. kind {
715+ mir:: StatementKind :: Assign ( box ( lhs, mir:: Rvalue :: Discriminant ( discriminated) ) )
716+ if * lhs == switch_on =>
717+ {
718+ match & discriminated. ty ( body, tcx) . ty . kind ( ) {
719+ ty:: Adt ( def, _) => return Some ( ( * discriminated, def) ) ,
720+
721+ // `Rvalue::Discriminant` is also used to get the active yield point for a
722+ // generator, but we do not need edge-specific effects in that case. This may
723+ // change in the future.
724+ ty:: Generator ( ..) => return None ,
725+
726+ t => bug ! ( "`discriminant` called on unexpected type {:?}" , t) ,
727+ }
726728 }
729+ mir:: StatementKind :: Coverage ( _) => continue ,
730+ _ => return None ,
727731 }
728-
729- _ => None ,
730732 }
733+ None
731734}
732735
733736struct OnMutBorrow < F > ( F ) ;
0 commit comments