@@ -7,7 +7,6 @@ use std::path::{self, PathBuf};
77use std:: result:: Result ; // To override syn::Result from glob import
88
99use dtoa;
10-
1110use failure:: { err_msg, format_err, Fail } ;
1211use indexmap:: indexmap;
1312use indexmap:: { IndexMap , IndexSet } ;
@@ -258,6 +257,15 @@ pub struct Translation<'c> {
258257 potential_flexible_array_members : RefCell < IndexSet < CDeclId > > ,
259258 macro_expansions : RefCell < IndexMap < CDeclId , Option < MacroExpansion > > > ,
260259
260+ /// For every call to [`Self::convert_expr`],
261+ /// we record the `override_ty` that is used for that expression.
262+ ///
263+ /// This is needed [`Self::recreate_const_macro_from_expansions`]
264+ /// when we call [`Self::convert_expr`] for each of the macro expansions,
265+ /// as unlike normal [`Self::convert_expr`]s, there is no surrounding context
266+ /// higher in the call stack calculating the `override_ty`.
267+ expr_override_tys : RefCell < HashMap < CExprId , CQualTypeId > > ,
268+
261269 // Comment support
262270 pub comment_context : CommentContext , // Incoming comments
263271 pub comment_store : RefCell < CommentStore > , // Outgoing comments
@@ -1209,6 +1217,7 @@ impl<'c> Translation<'c> {
12091217 function_context : RefCell :: new ( FuncContext :: new ( ) ) ,
12101218 potential_flexible_array_members : RefCell :: new ( IndexSet :: new ( ) ) ,
12111219 macro_expansions : RefCell :: new ( IndexMap :: new ( ) ) ,
1220+ expr_override_tys : Default :: default ( ) ,
12121221 comment_context,
12131222 comment_store : RefCell :: new ( CommentStore :: new ( ) ) ,
12141223 spans : HashMap :: new ( ) ,
@@ -2195,7 +2204,11 @@ impl<'c> Translation<'c> {
21952204 . ast_context
21962205 . resolve_expr_type_id ( id)
21972206 . unwrap_or ( ( id, ty) ) ;
2198- let expr = self . convert_expr ( ctx, expr_id, None ) ?;
2207+
2208+ let override_ty = self . expr_override_tys . borrow ( ) . get ( & expr_id) . copied ( ) ;
2209+ let expr = self . convert_expr ( ctx, expr_id, override_ty) ?;
2210+
2211+ let ty = override_ty. map ( |ty| ty. ctype ) . unwrap_or ( ty) ;
21992212
22002213 // Join ty and cur_ty to the smaller of the two types. If the
22012214 // types are not cast-compatible, abort the fold.
@@ -3247,6 +3260,12 @@ impl<'c> Translation<'c> {
32473260 expr_id : CExprId ,
32483261 override_ty : Option < CQualTypeId > ,
32493262 ) -> TranslationResult < WithStmts < Box < Expr > > > {
3263+ if let Some ( override_ty) = override_ty {
3264+ self . expr_override_tys
3265+ . borrow_mut ( )
3266+ . insert ( expr_id, override_ty) ;
3267+ }
3268+
32503269 let Located {
32513270 loc : src_loc,
32523271 kind : expr_kind,
0 commit comments