Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
StrCat(GetUnsafeTypeAsString(qual_type), token::kOpenCurlyBracket);
int i = 0;
for (const auto *field : record->fields()) {
StrCat(field->getName(), token::kColon);
StrCat(GetNamedDeclAsString(field), token::kColon);
ConvertVarInit(field->getType(), expr->getInit(i++));
StrCat(token::kComma);
}
Expand Down
46 changes: 44 additions & 2 deletions cpp2rust/converter/converter_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,50 @@
#include "converter/lex.h"
#include "converter/mapper.h"

static std::array<const char *, 5> rust_keywords = {
"fn", "in", "mut", "vec", "ref",
// https://doc.rust-lang.org/reference/keywords.html
static const char *rust_keywords[] = {
// Strict keywords
"as",
"async",
"await",
"crate",
"dyn",
"fn",
"impl",
"in",
"let",
"loop",
"match",
"mod",
"move",
"mut",
"pub",
"ref",
"self",
"Self",
"super",
"trait",
"type",
"unsafe",
"use",
"where",
// Reserved keywords
"abstract",
"become",
"box",
"final",
"gen",
"macro",
"override",
"priv",
"unsized",
"yield",
// Weak keywords
"macro_rules",
"raw",
"safe",
// Standard library keywords
"vec",
};

namespace cpp2rust {
Expand Down
2 changes: 1 addition & 1 deletion cpp2rust/converter/models/converter_refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ bool ConverterRefCount::VisitInitListExpr(clang::InitListExpr *expr) {
int i = 0;
PushConversionKind push(*this, ConversionKind::FullRefCount);
for (const auto *field : record->fields()) {
StrCat(field->getName(), token::kColon);
StrCat(GetNamedDeclAsString(field), token::kColon);
ConvertVarInit(field->getType(), expr->getInit(i++));
StrCat(token::kComma);
}
Expand Down
Loading