Sort Eq candidates in the failure case too

This commit is contained in:
Nadrieril 2024-03-13 22:23:45 +01:00
parent 5ef9ad37ab
commit 75d2e67ed2
3 changed files with 44 additions and 51 deletions

View File

@ -650,12 +650,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
// FIXME(#29623): return `Some(1)` when the values are different.
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
if test_val == case_val =>
{
fully_matched = true;
Some(TestBranch::Success)
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val }) => {
if test_val == case_val {
fully_matched = true;
Some(TestBranch::Success)
} else {
fully_matched = false;
Some(TestBranch::Failure)
}
}
(

View File

@ -9,10 +9,9 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
let mut _5: bool;
let mut _6: bool;
let mut _7: bool;
let mut _8: bool;
let mut _9: &&str;
let mut _10: &bool;
let mut _11: bool;
let mut _8: &&str;
let mut _9: &bool;
let mut _10: bool;
bb0: {
StorageLive(_3);
@ -24,104 +23,96 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
StorageDead(_5);
StorageDead(_4);
PlaceMention(_3);
_8 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb13, unwind: bb21];
_7 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb11, unwind: bb19];
}
bb1: {
_7 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb11, unwind: bb21];
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb3];
}
bb2: {
_6 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb8, unwind: bb21];
_0 = const 5_u32;
goto -> bb18;
}
bb3: {
switchInt((_3.1: bool)) -> [0: bb4, otherwise: bb5];
falseEdge -> [real: bb17, imaginary: bb2];
}
bb4: {
_0 = const 5_u32;
goto -> bb20;
falseEdge -> [real: bb12, imaginary: bb9];
}
bb5: {
falseEdge -> [real: bb19, imaginary: bb4];
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb6];
}
bb6: {
switchInt((_3.1: bool)) -> [0: bb3, otherwise: bb7];
falseEdge -> [real: bb16, imaginary: bb3];
}
bb7: {
falseEdge -> [real: bb18, imaginary: bb5];
_6 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb10, unwind: bb19];
}
bb8: {
switchInt(move _6) -> [0: bb3, otherwise: bb6];
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb9];
}
bb9: {
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb10];
falseEdge -> [real: bb15, imaginary: bb6];
}
bb10: {
falseEdge -> [real: bb17, imaginary: bb7];
switchInt(move _6) -> [0: bb1, otherwise: bb8];
}
bb11: {
switchInt(move _7) -> [0: bb2, otherwise: bb9];
switchInt(move _7) -> [0: bb7, otherwise: bb4];
}
bb12: {
falseEdge -> [real: bb14, imaginary: bb10];
_8 = &fake (_3.0: &str);
_9 = &fake (_3.1: bool);
StorageLive(_10);
_10 = const true;
switchInt(move _10) -> [0: bb14, otherwise: bb13];
}
bb13: {
switchInt(move _8) -> [0: bb1, otherwise: bb12];
StorageDead(_10);
FakeRead(ForMatchGuard, _8);
FakeRead(ForMatchGuard, _9);
_0 = const 1_u32;
goto -> bb18;
}
bb14: {
_9 = &fake (_3.0: &str);
_10 = &fake (_3.1: bool);
StorageLive(_11);
_11 = const true;
switchInt(move _11) -> [0: bb16, otherwise: bb15];
StorageDead(_10);
falseEdge -> [real: bb5, imaginary: bb9];
}
bb15: {
StorageDead(_11);
FakeRead(ForMatchGuard, _9);
FakeRead(ForMatchGuard, _10);
_0 = const 1_u32;
goto -> bb20;
_0 = const 2_u32;
goto -> bb18;
}
bb16: {
StorageDead(_11);
falseEdge -> [real: bb1, imaginary: bb10];
_0 = const 3_u32;
goto -> bb18;
}
bb17: {
_0 = const 2_u32;
goto -> bb20;
_0 = const 4_u32;
goto -> bb18;
}
bb18: {
_0 = const 3_u32;
goto -> bb20;
}
bb19: {
_0 = const 4_u32;
goto -> bb20;
}
bb20: {
StorageDead(_3);
return;
}
bb21 (cleanup): {
bb19 (cleanup): {
resume;
}
}

View File

@ -4,7 +4,7 @@
// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
fn constant_eq(s: &str, b: bool) -> u32 {
// For now we test "a" twice.
// Check that we only test "a" once
match (s, b) {
("a", _) if true => 1,
("b", true) => 2,