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