@@ -1171,7 +1171,6 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) {
11711171
11721172 for (const auto *field : record_decl->fields ()) {
11731173 auto field_name = GetNamedDeclAsString (field);
1174- auto field_type = field->getType ();
11751174 const clang::CXXCtorInitializer *ctor_initializer = nullptr ;
11761175 for (const auto *init : definition->inits ()) {
11771176 if (init->isMemberInitializer () && init->getMember () == field) {
@@ -1180,15 +1179,9 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) {
11801179 }
11811180 }
11821181
1183- if (ctor_initializer) {
1184- StrCat (field_name, token::kColon );
1185- ConvertVarInit (field_type, ctor_initializer->getInit ());
1186- } else if (auto *init = field->getInClassInitializer ()) {
1187- StrCat (field_name, token::kColon );
1188- ConvertVarInit (field_type, init);
1189- } else {
1190- StrCat (field_name, token::kColon , GetDefaultAsString (field_type));
1191- }
1182+ StrCat (field_name, token::kColon );
1183+ ConvertFieldInit (field, ctor_initializer ? ctor_initializer->getInit ()
1184+ : field->getInClassInitializer ());
11921185 StrCat (token::kComma );
11931186 }
11941187}
@@ -2444,7 +2437,9 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
24442437 case clang::CastKind::CK_LValueToRValue: {
24452438 PushExprKind push (*this , ExprKind::RValue);
24462439 Convert (sub_expr);
2447- SetValueFreshness (type);
2440+ if (!isFresh ()) {
2441+ SetValueFreshness (type);
2442+ }
24482443 break ;
24492444 }
24502445 case clang::CastKind::CK_ArrayToPointerDecay: {
@@ -3398,7 +3393,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
33983393 int i = 0 ;
33993394 for (const auto *field : record->fields ()) {
34003395 StrCat (GetNamedDeclAsString (field), token::kColon );
3401- ConvertVarInit (field-> getType () , expr->getInit (i++));
3396+ ConvertFieldInit (field, expr->getInit (i++));
34023397 StrCat (token::kComma );
34033398 }
34043399 } else {
@@ -4665,15 +4660,20 @@ void Converter::EmitDefaultStructLiteral(const clang::RecordDecl *decl) {
46654660 PushBrace brace (*this );
46664661 for (auto *field : decl->fields ()) {
46674662 StrCat (GetNamedDeclAsString (field), token::kColon );
4668- if (auto *init = field->getInClassInitializer ()) {
4669- ConvertVarInit (field->getType (), init);
4670- } else {
4671- StrCat (GetDefaultAsString (field->getType ()));
4672- }
4663+ ConvertFieldInit (field, field->getInClassInitializer ());
46734664 StrCat (token::kComma );
46744665 }
46754666}
46764667
4668+ void Converter::ConvertFieldInit (const clang::FieldDecl *field,
4669+ clang::Expr *init) {
4670+ if (init) {
4671+ ConvertVarInit (field->getType (), init);
4672+ } else {
4673+ StrCat (GetDefaultAsString (field->getType ()));
4674+ }
4675+ }
4676+
46774677void Converter::AddByteReprTrait (const clang::RecordDecl *decl) {}
46784678
46794679void Converter::ConvertUnsignedArithBinaryOperator (clang::BinaryOperator *op,
@@ -4838,8 +4838,16 @@ void Converter::PlaceholderCtx::dump() const {
48384838 << " , materialize_idx: " << materialize_idx << ' \n ' ;
48394839}
48404840
4841+ std::string Converter::ConvertTake (clang::Expr *arg) {
4842+ return std::format (" std::mem::take(&mut {})" , ConvertLValue (arg));
4843+ }
4844+
48414845std::string Converter::ConvertPlaceholder (clang::Expr *expr, clang::Expr *arg,
48424846 const PlaceholderCtx &ph_ctx) {
4847+ if (auto it = hoisted_exprs_.find (arg); it != hoisted_exprs_.end ()) {
4848+ return it->second ;
4849+ }
4850+
48434851 if (arg->getType ()->isFunctionPointerType ()) {
48444852 return ConvertFnPtrPlaceholder (arg);
48454853 }
@@ -4907,9 +4915,9 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
49074915 }
49084916 return ConvertFreshRValue (arg);
49094917 }
4910- auto lvalue = ConvertLValue (arg);
4918+ auto str = ConvertTake (arg);
49114919 SetFresh ();
4912- return std::format ( " std::mem::take(&mut {}) " , std::move (lvalue)) ;
4920+ return str ;
49134921 }
49144922
49154923 if (ph_ctx.access == TranslationRule::Access::kMove ) {
0 commit comments