diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-03-13 22:23:45 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-03-30 17:37:15 +0100 |
| commit | 75d2e67ed240731c15b697424bbd671464c4bde6 (patch) | |
| tree | 858d59d0e34f1c099d91d9a28fa47a402c3b3946 | |
| parent | 5ef9ad37abf51d7346f7ac68b910f1a18d86f65b (diff) | |
| download | rust-75d2e67ed240731c15b697424bbd671464c4bde6.tar.gz rust-75d2e67ed240731c15b697424bbd671464c4bde6.zip | |
Sort `Eq` candidates in the failure case too
3 files changed, 44 insertions, 51 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index b66dd83b7ec..690879b9488 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -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) + } } ( diff --git a/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir index d515a676bb0..e95a97b5b87 100644 --- a/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir @@ -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]; - } - - bb14: { - _9 = &fake (_3.0: &str); - _10 = &fake (_3.1: bool); - StorageLive(_11); - _11 = const true; - switchInt(move _11) -> [0: bb16, otherwise: bb15]; - } - - bb15: { - StorageDead(_11); + StorageDead(_10); + FakeRead(ForMatchGuard, _8); FakeRead(ForMatchGuard, _9); - FakeRead(ForMatchGuard, _10); _0 = const 1_u32; - goto -> bb20; + goto -> bb18; } - bb16: { - StorageDead(_11); - falseEdge -> [real: bb1, imaginary: bb10]; + bb14: { + StorageDead(_10); + falseEdge -> [real: bb5, imaginary: bb9]; } - bb17: { + bb15: { _0 = const 2_u32; - goto -> bb20; + goto -> bb18; } - bb18: { + bb16: { _0 = const 3_u32; - goto -> bb20; + goto -> bb18; } - bb19: { + bb17: { _0 = const 4_u32; - goto -> bb20; + goto -> bb18; } - bb20: { + bb18: { StorageDead(_3); return; } - bb21 (cleanup): { + bb19 (cleanup): { resume; } } diff --git a/tests/mir-opt/building/match/sort_candidates.rs b/tests/mir-opt/building/match/sort_candidates.rs index ead8e62db52..2f93cd767bd 100644 --- a/tests/mir-opt/building/match/sort_candidates.rs +++ b/tests/mir-opt/building/match/sort_candidates.rs @@ -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, |
