Skip to content

Commit af3fdeb

Browse files
committed
transpile: Do not unwrap Paren where it's explicitly handled
1 parent 43c1525 commit af3fdeb

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ impl TypedAstContext {
718718
pub fn unwrap_cast_expr(&self, mut expr_id: CExprId) -> CExprId {
719719
while let CExprKind::Paren(_, subexpr)
720720
| CExprKind::ImplicitCast(_, subexpr, _, _, _)
721-
| CExprKind::ExplicitCast(_, subexpr, _, _, _) =
722-
self.index_unwrap_parens(expr_id).kind
721+
| CExprKind::ExplicitCast(_, subexpr, _, _, _) = self[expr_id].kind
723722
{
724723
expr_id = subexpr;
725724
}
@@ -741,7 +740,7 @@ impl TypedAstContext {
741740
/// Resolve true expression type, iterating through any casts and variable
742741
/// references.
743742
pub fn resolve_expr_type_id(&self, expr_id: CExprId) -> Option<(CExprId, CTypeId)> {
744-
let expr = &self.index_unwrap_parens(expr_id).kind;
743+
let expr = &self[expr_id].kind;
745744
let mut ty = expr.get_type();
746745
use CExprKind::*;
747746
match expr {
@@ -885,7 +884,7 @@ impl TypedAstContext {
885884
pub fn is_expr_pure(&self, expr: CExprId) -> bool {
886885
use CExprKind::*;
887886
let pure = |expr| self.is_expr_pure(expr);
888-
match self.index_unwrap_parens(expr).kind {
887+
match self[expr].kind {
889888
BadExpr |
890889
ShuffleVector(..) |
891890
ConvertVector(..) |
@@ -957,7 +956,7 @@ impl TypedAstContext {
957956
let is_const = |expr| self.is_const_expr(expr);
958957

959958
use CExprKind::*;
960-
match self.index_unwrap_parens(expr).kind {
959+
match self[expr].kind {
961960
// A literal is always `const`.
962961
Literal(_, _) => true,
963962
// Unary ops should be `const`.
@@ -1271,7 +1270,7 @@ impl TypedAstContext {
12711270
_ => return,
12721271
};
12731272

1274-
let new_ty = match self.ast_context.c_exprs[&e].kind {
1273+
let new_ty = match self.ast_context[e].kind {
12751274
CExprKind::Conditional(_ty, _cond, lhs, rhs) => {
12761275
let lhs_type_id =
12771276
self.ast_context.c_exprs[&lhs].kind.get_qual_type().unwrap();

c2rust-transpile/src/translator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,12 +2933,12 @@ impl<'c> Translation<'c> {
29332933
let Located {
29342934
loc: src_loc,
29352935
kind: expr_kind,
2936-
} = &self.ast_context.index_unwrap_parens(expr_id);
2936+
} = &self.ast_context[expr_id];
29372937

29382938
trace!(
29392939
"Converting expr {:?}: {:?}",
29402940
expr_id,
2941-
self.ast_context.index_unwrap_parens(expr_id)
2941+
self.ast_context[expr_id]
29422942
);
29432943

29442944
if let Some(converted) = self.convert_const_macro_expansion(ctx, expr_id, override_ty)? {

0 commit comments

Comments
 (0)