@@ -519,9 +519,11 @@ bool IsPointerType(clang::QualType qual_type) {
519519 ->getCanonicalTypeInternal ()));
520520}
521521
522- bool Converter::RecordDerivesDefault (const clang::CXXRecordDecl *decl) {
523- if (GetUserDefinedDefaultConstructor (decl)) {
524- return false ;
522+ bool Converter::RecordDerivesDefault (const clang::RecordDecl *decl) {
523+ if (auto cxx_decl = clang::dyn_cast<clang::CXXRecordDecl>(decl)) {
524+ if (GetUserDefinedDefaultConstructor (cxx_decl)) {
525+ return false ;
526+ }
525527 }
526528
527529 for (auto f : decl->fields ()) {
@@ -546,7 +548,7 @@ bool Converter::RecordDerivesDefault(const clang::CXXRecordDecl *decl) {
546548 return true ;
547549}
548550
549- static bool recordDerivesCopy (const clang::CXXRecordDecl *decl) {
551+ static bool recordDerivesCopy (const clang::RecordDecl *decl) {
550552 for (auto f : decl->fields ()) {
551553 // Records that contain std::vector, std::array, std::string or anything
552554 // that is translated to Vec<>, do not derive Copy
@@ -569,8 +571,8 @@ static bool recordDerivesCopy(const clang::CXXRecordDecl *decl) {
569571 }
570572 }
571573
572- // Look recursively into fields that are CXXRecordDecl
573- if (auto field_record = f->getType ()->getAsCXXRecordDecl ()) {
574+ // Look recursively into fields that are RecordDecl
575+ if (auto field_record = f->getType ()->getAsRecordDecl ()) {
574576 if (!recordDerivesCopy (field_record)) {
575577 return false ;
576578 }
@@ -629,12 +631,8 @@ void Converter::EmitRustStruct(clang::RecordDecl *decl) {
629631
630632 // Derived traits
631633 StrCat (" #[derive(" );
632- if (auto *cxx = clang::dyn_cast<clang::CXXRecordDecl>(decl)) {
633- for (auto *attr : GetStructAttributes (cxx)) {
634- StrCat (attr, " ," );
635- }
636- } else {
637- StrCat (" Clone, Default" );
634+ for (auto *attr : GetStructAttributes (decl)) {
635+ StrCat (attr, " ," );
638636 }
639637 StrCat (" )]" );
640638
@@ -2837,14 +2835,18 @@ std::string Converter::GetRecordName(const clang::NamedDecl *decl) const {
28372835}
28382836
28392837std::vector<const char *>
2840- Converter::GetStructAttributes (const clang::CXXRecordDecl *decl) {
2838+ Converter::GetStructAttributes (const clang::RecordDecl *decl) {
28412839 std::vector<const char *> struct_attrs = {};
28422840
28432841 if (recordDerivesCopy (decl)) {
28442842 struct_attrs.emplace_back (" Copy" );
28452843 }
28462844
2847- if (!decl->defaultedCopyConstructorIsDeleted ()) {
2845+ if (auto cxx_decl = clang::dyn_cast<clang::CXXRecordDecl>(decl)) {
2846+ if (!cxx_decl->defaultedCopyConstructorIsDeleted ()) {
2847+ struct_attrs.emplace_back (" Clone" );
2848+ }
2849+ } else /* RecordDecl */ {
28482850 struct_attrs.emplace_back (" Clone" );
28492851 }
28502852
0 commit comments