Skip to content

Commit 8ab82ec

Browse files
committed
transpile: Return ConvertedMacro from recreate_const_macro_from_expansions
1 parent 4f73b6e commit 8ab82ec

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

c2rust-transpile/src/translator/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ impl<'c> Translation<'c> {
3030
);
3131

3232
match maybe_replacement {
33-
Ok((replacement, result_type_id)) => {
33+
Ok((replacement, converted)) => {
3434
trace!(" to {:?}", replacement);
3535

36-
let converted = ConvertedMacro { result_type_id };
36+
let result_type_rs = self.convert_type(converted.result_type_id)?;
3737
self.converted_macros
3838
.borrow_mut()
3939
.insert(decl_id, Some(converted));
40-
let result_type_rs = self.convert_type(result_type_id)?;
4140

4241
Ok(ConvertedDecl::Item(mk().span(span).pub_().const_item(
4342
name,
@@ -68,8 +67,8 @@ impl<'c> Translation<'c> {
6867
&self,
6968
ctx: ExprContext,
7069
expansions: &[CExprId],
71-
) -> TranslationResult<(Box<Expr>, CTypeId)> {
72-
let (val, ty) = expansions
70+
) -> TranslationResult<(Box<Expr>, ConvertedMacro)> {
71+
let (val, result_type_id) = expansions
7372
.iter()
7473
.try_fold::<Option<(WithStmts<Box<Expr>>, CTypeId)>, _, _>(
7574
None,
@@ -118,9 +117,10 @@ impl<'c> Translation<'c> {
118117
)?
119118
.ok_or_else(|| format_err!("Could not find a valid type for macro"))?;
120119

120+
let converted = ConvertedMacro { result_type_id };
121121
val.wrap_unsafe()
122122
.to_pure_expr()
123-
.map(|val| (val, ty))
123+
.map(|val| (val, converted))
124124
.ok_or_else(|| TranslationError::generic("Macro expansion is not a pure expression"))
125125

126126
// TODO: Validate that all replacements are equivalent and pick the most

0 commit comments

Comments
 (0)