@@ -348,7 +348,7 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) {
348348 return false ;
349349 }
350350 decl->dump (log ());
351- curr_function_ = decl;
351+ PushCurrFunction push_fn (* this , decl) ;
352352 std::string function_name;
353353 if (decl->isMain ()) {
354354 function_name = " main_0" ;
@@ -677,6 +677,10 @@ bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) const {
677677}
678678
679679bool Converter::RecordHasCopyableFields (const clang::RecordDecl *decl) {
680+ if (auto *cxx = clang::dyn_cast<clang::CXXRecordDecl>(decl);
681+ cxx && !cxx->hasTrivialDestructor ()) {
682+ return false ;
683+ }
680684 for (auto f : decl->fields ()) {
681685 // Records that contain std::vector, std::array, std::string or anything
682686 // that is translated to Vec<>, do not derive Copy
@@ -931,7 +935,7 @@ bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) {
931935 if (!decl_ids_.insert (GetMethodID (decl)).second ) {
932936 return false ;
933937 }
934- curr_function_ = decl;
938+ PushCurrFunction push_fn (* this , decl) ;
935939
936940 if (decl->isOutOfLine () && !decl->overridden_methods ().empty ()) {
937941 return false ;
@@ -991,7 +995,7 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) {
991995 if (decl->isOutOfLine () || decl->isImplicit ()) {
992996 return false ;
993997 }
994- curr_function_ = decl;
998+ PushCurrFunction push_fn (* this , decl) ;
995999
9961000 if (decl->isCopyOrMoveConstructor ()) {
9971001 // FIXME: improve error handling
@@ -3279,11 +3283,9 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) {
32793283 }
32803284 StrCat (" | {" );
32813285 EmitFunctionPreamble (expr->getLambdaClass ()->getLambdaCallOperator ());
3282- // TODO: replace with a stack
3283- auto old_function = curr_function_;
3284- curr_function_ = expr->getLambdaClass ()->getLambdaCallOperator ();
3286+ PushCurrFunction push_fn (*this ,
3287+ expr->getLambdaClass ()->getLambdaCallOperator ());
32853288 ConvertFunctionBody (curr_function_);
3286- curr_function_ = old_function;
32873289 StrCat (' }' );
32883290 return false ;
32893291}
@@ -3969,7 +3971,20 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) {
39693971
39703972void Converter::AddCloneTrait (const clang::RecordDecl *decl) {}
39713973
3972- void Converter::AddDropTrait (const clang::CXXRecordDecl *decl) {}
3974+ void Converter::AddDropTrait (const clang::CXXRecordDecl *decl) {
3975+ auto *dtor = GetTranslatableDestructor (decl);
3976+ if (!dtor) {
3977+ return ;
3978+ }
3979+ PushCurrFunction push_fn (*this , dtor);
3980+ StrCat (keyword::kImpl , " Drop for" , GetRecordName (decl));
3981+ PushBrace impl_brace (*this );
3982+ StrCat (" fn drop(&mut self)" );
3983+ PushBrace fn_brace (*this );
3984+ StrCat (keyword_unsafe_);
3985+ PushBrace unsafe_brace (*this );
3986+ ConvertBodyStmts (dtor->getDefinition ()->getBody ());
3987+ }
39733988
39743989void Converter::AddDefaultTraitForUnion (const clang::RecordDecl *decl) {
39753990 StrCat (std::format (" impl Default for {}" , GetRecordName (decl)));
0 commit comments