diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-02-10 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-02-10 19:43:24 +0100 |
| commit | 63bf601537588858a65565b0463d66814b3401c0 (patch) | |
| tree | e866c5b7a6bf8e2774d5ffd9d27d193eb05075b7 /compiler/rustc_mir_dataflow/src | |
| parent | 502d6aa47b4118fea1e326529e71b25a99b0d6c5 (diff) | |
| download | rust-63bf601537588858a65565b0463d66814b3401c0.tar.gz rust-63bf601537588858a65565b0463d66814b3401c0.zip | |
Fix switch on discriminant detection in a presence of coverage counters
Diffstat (limited to 'compiler/rustc_mir_dataflow/src')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/impls/mod.rs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index 5dc8a003b47..d74ecb3eb1a 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -710,24 +710,27 @@ fn switch_on_enum_discriminant<'mir, 'tcx>( block: &'mir mir::BasicBlockData<'tcx>, switch_on: mir::Place<'tcx>, ) -> Option<(mir::Place<'tcx>, &'tcx ty::AdtDef)> { - match block.statements.last().map(|stmt| &stmt.kind) { - Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated)))) - if *lhs == switch_on => - { - match &discriminated.ty(body, tcx).ty.kind() { - ty::Adt(def, _) => Some((*discriminated, def)), - - // `Rvalue::Discriminant` is also used to get the active yield point for a - // generator, but we do not need edge-specific effects in that case. This may - // change in the future. - ty::Generator(..) => None, - - t => bug!("`discriminant` called on unexpected type {:?}", t), + for statement in block.statements.iter().rev() { + match &statement.kind { + mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))) + if *lhs == switch_on => + { + match &discriminated.ty(body, tcx).ty.kind() { + ty::Adt(def, _) => return Some((*discriminated, def)), + + // `Rvalue::Discriminant` is also used to get the active yield point for a + // generator, but we do not need edge-specific effects in that case. This may + // change in the future. + ty::Generator(..) => return None, + + t => bug!("`discriminant` called on unexpected type {:?}", t), + } } + mir::StatementKind::Coverage(_) => continue, + _ => return None, } - - _ => None, } + None } struct OnMutBorrow<F>(F); |
