File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -688,6 +688,7 @@ void Converter::EmitRustStructOrUnion(clang::RecordDecl *decl) {
688688 }
689689 AddDefaultTrait (decl);
690690 AddByteReprTrait (decl);
691+ AddSyncTrait (decl);
691692}
692693
693694bool Converter::VisitCXXRecordDecl (clang::CXXRecordDecl *decl) {
@@ -3457,6 +3458,26 @@ void Converter::AddDefaultTrait(const clang::RecordDecl *decl) {
34573458
34583459void Converter::AddByteReprTrait (const clang::RecordDecl *decl) {}
34593460
3461+ static bool recordImplementsSync (const clang::RecordDecl *decl) {
3462+ for (auto field : decl->fields ()) {
3463+ if (field->getType ()->isPointerType ()) {
3464+ return true ;
3465+ }
3466+ }
3467+ return false ;
3468+ }
3469+
3470+ void Converter::AddSyncTrait (const clang::RecordDecl *decl) {
3471+ if (!recordImplementsSync (decl)) {
3472+ return ;
3473+ }
3474+
3475+ StrCat (" \n // SAFETY: preserves unsafe C semantics; thread-safety is the "
3476+ " programmer's responsibility\n " );
3477+ StrCat (" unsafe impl Sync for" , GetRecordName (decl));
3478+ PushBrace brace (*this );
3479+ }
3480+
34603481void Converter::ConvertUnsignedArithBinaryOperator (clang::BinaryOperator *op,
34613482 clang::Expr *expr) {
34623483 StrCat (token::kDot );
Original file line number Diff line number Diff line change @@ -466,6 +466,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
466466
467467 virtual void AddByteReprTrait (const clang::RecordDecl *decl);
468468
469+ virtual void AddSyncTrait (const clang::RecordDecl *decl);
470+
469471 virtual void
470472 ConvertUnsignedArithBinaryOperator (clang::BinaryOperator *binary_operator,
471473 clang::Expr *expr);
Original file line number Diff line number Diff line change @@ -503,6 +503,8 @@ void ConverterRefCount::AddByteReprTrait(const clang::RecordDecl *decl) {
503503 PushBrace brace (*this );
504504}
505505
506+ void ConverterRefCount::AddSyncTrait (const clang::RecordDecl *decl) {}
507+
506508std::string
507509ConverterRefCount::GetSelfMaybeWithMut (const clang::CXXMethodDecl *decl) {
508510 return " &self" ;
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ class ConverterRefCount final : public Converter {
3939
4040 void AddByteReprTrait (const clang::RecordDecl *decl) override ;
4141
42+ void AddSyncTrait (const clang::RecordDecl *decl) override ;
43+
4244 void AddDefaultTrait (const clang::RecordDecl *decl) override ;
4345
4446 void AddDefaultTraitForUnion (const clang::RecordDecl *decl) override ;
You can’t perform that action at this time.
0 commit comments