Skip to content

Commit 0da6dd3

Browse files
authored
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``
2 parents 3b276cb + 63bf601 commit 0da6dd3

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

compiler/rustc_mir_dataflow/src/impls/mod.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -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

729732
struct OnMutBorrow<F>(F);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Checks that code coverage doesn't interfere with const_precise_live_drops.
2+
// Regression test for issue #93848.
3+
//
4+
// check-pass
5+
// compile-flags: --crate-type=lib -Cinstrument-coverage -Zno-profiler-runtime
6+
7+
#![feature(const_precise_live_drops)]
8+
9+
#[inline]
10+
pub const fn transpose<T, E>(this: Option<Result<T, E>>) -> Result<Option<T>, E> {
11+
match this {
12+
Some(Ok(x)) => Ok(Some(x)),
13+
Some(Err(e)) => Err(e),
14+
None => Ok(None),
15+
}
16+
}

0 commit comments

Comments
 (0)