diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-26 00:49:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-26 00:49:21 +0100 |
| commit | 0da6dd3e97b720129100ec943bb993eab77c2c11 (patch) | |
| tree | df95f6ad99dd5d6269b4ca7bbde6fbfad3fc7bcc /compiler/rustc_mir_dataflow/src/impls/mod.rs | |
| parent | 3b276cbe044a528e5966a4dc729fdfd662724f8c (diff) | |
| parent | 63bf601537588858a65565b0463d66814b3401c0 (diff) | |
| download | rust-0da6dd3e97b720129100ec943bb993eab77c2c11.tar.gz rust-0da6dd3e97b720129100ec943bb993eab77c2c11.zip | |
Rollup merge of #93870 - tmiasko:const-precise-live-drops-with-coverage, r=ecstatic-morse
Fix switch on discriminant detection in a presence of coverage counters Fixes #93848. r? ``@ecstatic-morse``
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/impls/mod.rs')
| -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 9502c5d57d6..7d6a08d47da 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -706,24 +706,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); |
