Skip to content

Commit dd4f7ce

Browse files
committed
transpile: Remove override_ty param from convert_const_macro_expansion
1 parent a779717 commit dd4f7ce

4 files changed

Lines changed: 7 additions & 12 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
@@ -148,7 +148,6 @@ impl<'c> Translation<'c> {
148148
&self,
149149
ctx: ExprContext,
150150
expr_id: CExprId,
151-
override_ty: Option<CQualTypeId>,
152151
) -> TranslationResult<Option<WithStmts<Box<Expr>>>> {
153152
let macros = match self.ast_context.macro_invocations.get(&expr_id) {
154153
Some(macros) => macros.as_slice(),
@@ -201,6 +200,7 @@ impl<'c> Translation<'c> {
201200
// determined by the surrounding context.
202201
// Since the expansion sites are expecting a particular type, we need to cast it here
203202
// if it differs from the `const` type.
203+
let override_ty = self.expr_override_types.get(&expr_id).copied();
204204
let expr_ty = override_ty.or_else(|| self.ast_context[expr_id].kind.get_qual_type());
205205
if let Some(expr_ty) = expr_ty {
206206
self.convert_cast(
@@ -249,14 +249,9 @@ impl<'c> Translation<'c> {
249249
))))
250250
}
251251

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

c2rust-transpile/src/translator/mod.rs

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

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

37543754
let override_ty = self.expr_override_types.get(&expr_id).copied();
37553755

3756-
if let Some(converted) = self.convert_const_macro_expansion(ctx, expr_id, override_ty)? {
3756+
if let Some(converted) = self.convert_const_macro_expansion(ctx, expr_id)? {
37573757
return Ok(converted);
37583758
}
37593759

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)