Skip to content

Commit e6eea54

Browse files
committed
Translate accessor of array member as Ptr<T> instead of Ptr<Box<[T]>>
1 parent aa251f6 commit e6eea54

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ bool ConverterRefCount::VisitArraySubscriptExpr(
379379
clang::ArraySubscriptExpr *expr) {
380380
auto *base = expr->getBase();
381381
if (base->IgnoreCasts()->getType()->isPointerType() ||
382-
(isLValue() && IsUnionArrayMember(base))) {
382+
IsUnionArrayMember(base)) {
383383
ConvertPointerSubscript(expr);
384384
} else {
385385
if (!base->IgnoreCasts()->getType()->isArrayType()) {
@@ -505,13 +505,16 @@ void ConverterRefCount::EmitRustUnion(clang::RecordDecl *decl) {
505505
{
506506
PushBrace impl_brace(*this);
507507
for (auto *field : decl->fields()) {
508-
PushConversionKind push(*this, ConversionKind::FullRefCount);
509-
std::string storage_ty = ToString(field->getType());
510-
Unwrap(storage_ty, "Value<", ">");
508+
PushConversionKind push(*this, ConversionKind::Unboxed);
509+
auto ty =
510+
field->getType()->isArrayType()
511+
? ToString(
512+
field->getType()->getAsArrayTypeUnsafe()->getElementType())
513+
: ToString(field->getType());
511514
StrCat(std::format(
512515
"pub fn {}(&self) -> Ptr<{}> {{ (self.__bytes.as_pointer() "
513516
"as Ptr<u8>).reinterpret_cast() }}",
514-
GetNamedDeclAsString(field), storage_ty));
517+
GetNamedDeclAsString(field), ty));
515518
}
516519
}
517520

0 commit comments

Comments
 (0)