Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in the MIR lowering of or-patterns #127028

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
break;
}
}
if expand_until != 0 {
expand_until = i + 1;
}
Comment on lines +1414 to +1416
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was "include as many candidates until we find a candidate where we should stop" but I forgot to keep incrementing the index so I cut off candidates I should have included. As you can see in the test file, this created unnecessary extra SwitchInts.

}
let (candidates_to_expand, remaining_candidates) = candidates.split_at_mut(expand_until);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// MIR for `match_enum` after built

fn match_enum(_1: E1) -> bool {
debug x => _1;
let mut _0: bool;
let mut _2: isize;

bb0: {
PlaceMention(_1);
_2 = discriminant(_1);
switchInt(move _2) -> [0: bb3, 1: bb5, 2: bb7, otherwise: bb2];
}

bb1: {
FakeRead(ForMatchedPlace(None), _1);
unreachable;
}

bb2: {
goto -> bb1;
}

bb3: {
goto -> bb9;
}

bb4: {
goto -> bb2;
}

bb5: {
goto -> bb9;
}

bb6: {
goto -> bb2;
}

bb7: {
_0 = const false;
goto -> bb11;
}

bb8: {
goto -> bb2;
}

bb9: {
falseEdge -> [real: bb10, imaginary: bb7];
}

bb10: {
_0 = const true;
goto -> bb11;
}

bb11: {
return;
}
}
14 changes: 14 additions & 0 deletions tests/mir-opt/building/match/simple_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ fn match_bool(x: bool) -> usize {
}
}

pub enum E1 {
V1,
V2,
V3,
}

// EMIT_MIR simple_match.match_enum.built.after.mir
pub fn match_enum(x: E1) -> bool {
match x {
E1::V1 | E1::V2 => true,
E1::V3 => false,
}
}

fn main() {}
Loading