1
Fork 0

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

View file

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