Skip to content

Commit

Permalink
add otherwise into targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Nov 27, 2023
1 parent de27790 commit 15f9bab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,10 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
mir::TerminatorKind::SwitchInt { discr, targets } => TerminatorKind::SwitchInt {
discr: discr.stable(tables),
targets: {
let (value_vec, target_vec) =
let (value_vec, mut target_vec): (Vec<_>, Vec<_>) =
targets.iter().map(|(value, target)| (value, target.as_usize())).unzip();
// We need to push otherwise as last element to ensure it's same as in MIR.
target_vec.push(targets.otherwise().as_usize());
stable_mir::mir::SwitchTargets { value: value_vec, targets: target_vec }
},
otherwise: targets.otherwise().as_usize(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/stable_mir/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn pretty_terminator<W: io::Write>(terminator: &TerminatorKind, w: &mut W) -
if i > 0 {
write!(w, ", ")?;
}
write!(w, "{}: {:?}", labels[i], target)?;
write!(w, "{}: bb{:?}", labels[i], target)?;
}
if show_unwind {
write!(w, ", ")?;
Expand All @@ -126,7 +126,7 @@ pub fn pretty_terminator_head(terminator: &TerminatorKind) -> String {
match terminator {
Goto { .. } => format!(" goto"),
SwitchInt { discr, .. } => {
format!(" switch({})", pretty_operand(discr))
format!(" switchInt(_{})", pretty_operand(discr))
}
Resume => format!(" resume"),
Abort => format!(" abort"),
Expand Down

0 comments on commit 15f9bab

Please sign in to comment.