Skip to content

Commit 28033ed

Browse files
committed
transpile: Remove override_ty param from convert_const_macro_expansion
1 parent d91a29e commit 28033ed

5 files changed

Lines changed: 8 additions & 13 deletions

File tree

c2rust-transpile/src/translator/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'c> Translation<'c> {
9797
if self.is_variant_of_enum(enum_id, enum_constant_id) =>
9898
{
9999
// `enum`s shouldn't need portable `override_ty`s.
100-
let expr_is_macro = self.expr_is_expanded_macro(ctx, expr, None);
100+
let expr_is_macro = self.expr_is_expanded_macro(ctx, expr);
101101

102102
// If this DeclRef expanded to a const macro, we actually need to insert a cast,
103103
// because the translation of a const macro skips implicit casts in its context.

c2rust-transpile/src/translator/macros.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ impl<'c> Translation<'c> {
149149
&self,
150150
ctx: ExprContext,
151151
expr_id: CExprId,
152-
override_ty: Option<CQualTypeId>,
153152
) -> TranslationResult<Option<WithStmts<Box<Expr>>>> {
154153
let macros = match self.ast_context.macro_invocations.get(&expr_id) {
155154
Some(macros) => macros.as_slice(),
@@ -202,6 +201,7 @@ impl<'c> Translation<'c> {
202201
// determined by the surrounding context.
203202
// Since the expansion sites are expecting a particular type, we need to cast it here
204203
// if it differs from the `const` type.
204+
let override_ty = self.expr_override_types.get(&expr_id).copied();
205205
let expr_ty = override_ty.or_else(|| self.ast_context[expr_id].kind.get_qual_type());
206206
if let Some(expr_ty) = expr_ty {
207207
self.convert_cast(
@@ -250,14 +250,9 @@ impl<'c> Translation<'c> {
250250
))))
251251
}
252252

253-
pub fn expr_is_expanded_macro(
254-
&self,
255-
ctx: ExprContext,
256-
expr_id: CExprId,
257-
override_ty: Option<CQualTypeId>,
258-
) -> bool {
253+
pub fn expr_is_expanded_macro(&self, ctx: ExprContext, expr_id: CExprId) -> bool {
259254
matches!(
260-
self.convert_const_macro_expansion(ctx, expr_id, override_ty),
255+
self.convert_const_macro_expansion(ctx, expr_id),
261256
Ok(Some(_))
262257
)
263258
}

c2rust-transpile/src/translator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ impl<'c> Translation<'c> {
22922292
}
22932293

22942294
CExprKind::Literal(_, ref literal @ CLiteral::Integer(0 | 1, _))
2295-
if !self.expr_is_expanded_macro(ctx, cond_id, None) =>
2295+
if !self.expr_is_expanded_macro(ctx, cond_id) =>
22962296
{
22972297
// If there is a literal `0` or `1` here, translate them directly rather than
22982298
// with a comparison. But not if they're inside a macro; we want to keep that.
@@ -2952,7 +2952,7 @@ impl<'c> Translation<'c> {
29522952

29532953
let override_ty = self.expr_override_types.get(&expr_id).copied();
29542954

2955-
if let Some(converted) = self.convert_const_macro_expansion(ctx, expr_id, override_ty)? {
2955+
if let Some(converted) = self.convert_const_macro_expansion(ctx, expr_id)? {
29562956
return Ok(converted);
29572957
}
29582958

c2rust-transpile/src/translator/operators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<'c> Translation<'c> {
863863
if let (&CExprKind::Literal(_, CLiteral::Integer(val, base)), false, false) = (
864864
&self.ast_context[arg_id].kind,
865865
is_unsigned_integral_type,
866-
self.expr_is_expanded_macro(ctx, arg_id, Some(expr_type_id)),
866+
self.expr_is_expanded_macro(ctx, arg_id),
867867
) {
868868
// If we are negating a literal, generate a negated literal directly.
869869
// This will create an expression like `-1 as ty` without parentheses,

c2rust-transpile/src/translator/pointers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'c> Translation<'c> {
104104
.ast_context
105105
.get_pointee_qual_type(pointer_cty.ctype)
106106
.ok_or_else(|| TranslationError::generic("Address-of should return a pointer"))?;
107-
let arg_is_macro = arg.map_or(false, |arg| self.expr_is_expanded_macro(ctx, arg, None));
107+
let arg_is_macro = arg.map_or(false, |arg| self.expr_is_expanded_macro(ctx, arg));
108108

109109
let mut needs_cast = false;
110110
let mut ref_cast_pointee_ty = None;

0 commit comments

Comments
 (0)