Skip to content

Commit 8eca20d

Browse files
committed
transpile: In Case translation, do not skip over initial cast
1 parent ec040d3 commit 8eca20d

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

c2rust-transpile/src/cfg/mod.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,23 +1857,16 @@ impl CfgBuilder {
18571857
self.add_wip_block(wip, Jump(this_label.clone()));
18581858

18591859
// Case
1860-
let resolved = translator.ast_context.unwrap_cast_expr(case_expr);
1861-
let branch = match translator.ast_context.index(resolved).kind {
1862-
CExprKind::Literal(..) | CExprKind::ConstantExpr(_, _, Some(_)) => translator
1863-
.convert_expr(ctx.const_().pattern().used(), resolved, None)
1864-
.ok()
1865-
.and_then(WithStmts::to_pure_expr)
1866-
.and_then(|expr| expr_to_pat(*expr)),
1867-
_ => None,
1868-
};
1869-
1870-
let pat = match branch {
1871-
Some(pat) => pat,
1872-
None => match cie {
1860+
let expr = translator
1861+
.convert_expr(ctx.const_().pattern().used(), case_expr, None)
1862+
.ok()
1863+
.and_then(WithStmts::to_pure_expr);
1864+
let pat = expr
1865+
.and_then(|expr| expr_to_pat(*expr))
1866+
.unwrap_or_else(|| match cie {
18731867
ConstIntExpr::U(n) => mk().lit_pat(mk().int_unsuffixed_lit(n)),
18741868
ConstIntExpr::I(n) => mk().lit_pat(mk().int_unsuffixed_lit(n)),
1875-
},
1876-
};
1869+
});
18771870

18781871
self.switch_expr_cases
18791872
.last_mut()

c2rust-transpile/tests/snapshots/snapshots__transpile@macrocase.c.2021.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub unsafe extern "C" fn ZSTD_dParam_getBounds(mut dParam: ZSTD_dParameter) -> :
2323
bounds = 1 as ::core::ffi::c_int;
2424
return bounds;
2525
}
26-
1000 => {
26+
ZSTD_d_format => {
2727
bounds = 5 as ::core::ffi::c_int;
2828
return bounds;
2929
}

c2rust-transpile/tests/snapshots/snapshots__transpile@macrocase.c.2024.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub unsafe extern "C" fn ZSTD_dParam_getBounds(mut dParam: ZSTD_dParameter) -> :
2424
bounds = 1 as ::core::ffi::c_int;
2525
return bounds;
2626
}
27-
1000 => {
27+
ZSTD_d_format => {
2828
bounds = 5 as ::core::ffi::c_int;
2929
return bounds;
3030
}

0 commit comments

Comments
 (0)