Skip to content

Commit fdf3e04

Browse files
Ruaahomescu
authored andcommitted
transpile: Remove ternary_needs_parens
1 parent e3b4853 commit fdf3e04

2 files changed

Lines changed: 1 addition & 17 deletions

File tree

c2rust-transpile/src/translator/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ pub struct ExprContext {
147147
/// address in function pointer literals.
148148
needs_address: bool,
149149

150-
ternary_needs_parens: bool,
151150
expanding_macro: Option<CDeclId>,
152151
}
153152

@@ -884,7 +883,6 @@ pub fn translate(
884883
decay_ref: DecayRef::Default,
885884
is_bitfield_write: false,
886885
needs_address: false,
887-
ternary_needs_parens: false,
888886
expanding_macro: None,
889887
};
890888

@@ -3576,15 +3574,7 @@ impl<'c> Translation<'c> {
35763574
let then = lhs.to_block();
35773575
let else_ = rhs.to_expr();
35783576

3579-
Ok(cond.map(|c| {
3580-
let ifte_expr = mk().ifte_expr(c, then, Some(else_));
3581-
3582-
if ctx.ternary_needs_parens {
3583-
mk().paren_expr(ifte_expr)
3584-
} else {
3585-
ifte_expr
3586-
}
3587-
}))
3577+
Ok(cond.map(|c| mk().ifte_expr(c, then, Some(else_))))
35883578
}
35893579
}
35903580

c2rust-transpile/src/translator/operators.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ impl<'c> Translation<'c> {
1616
) -> TranslationResult<WithStmts<Box<Expr>>> {
1717
let expr_type_id = expected_type_id.unwrap_or(result_type_id);
1818

19-
// If we're not making an assignment, a binop will require parens
20-
// applied to ternary conditionals
21-
if !op.is_assignment() {
22-
ctx.ternary_needs_parens = true;
23-
}
24-
2519
let lhs_loc = &self.ast_context.index_unwrap_parens(lhs).loc;
2620
let rhs_loc = &self.ast_context.index_unwrap_parens(rhs).loc;
2721
use CBinOp::*;

0 commit comments

Comments
 (0)