From 8492b53e499feb854cff99f3c27b0b646a3792a2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 26 Jul 2026 20:45:44 +0100 Subject: [PATCH 1/2] Remove clones on fresh values --- cpp2rust/converter/converter.cpp | 16 ++++++++++++++ .../converter/models/converter_refcount.cpp | 18 +++++++++++++++ tests/unit/out/refcount/bool_condition_ptr.rs | 4 ++-- .../unit/out/refcount/bool_condition_ptr_c.rs | 4 ++-- tests/unit/out/refcount/expr_as_bool_c.rs | 9 ++++---- tests/unit/out/refcount/expr_as_bool_cpp.rs | 8 +++---- tests/unit/out/refcount/huffman.rs | 2 +- .../refcount/tag_vs_identifier_collision.rs | 3 +-- .../out/refcount/union_tagged_many_arms.rs | 2 +- tests/unit/out/refcount/va_arg_chain.rs | 2 +- tests/unit/out/refcount/va_arg_concat.rs | 2 +- tests/unit/out/refcount/va_arg_conditional.rs | 2 +- tests/unit/out/refcount/va_arg_copy.rs | 4 ++-- tests/unit/out/refcount/va_arg_fn_ptr.rs | 4 ++-- tests/unit/out/refcount/va_arg_forward.rs | 2 +- .../unit/out/refcount/va_arg_mixed_int_ptr.rs | 7 +++--- tests/unit/out/refcount/va_arg_mixed_types.rs | 8 +++---- .../out/refcount/va_arg_non_primitive_ptrs.rs | 22 ++++++++----------- .../unit/out/refcount/va_arg_null_int_ptr.rs | 3 +-- tests/unit/out/refcount/va_arg_printf.rs | 6 ++--- tests/unit/out/refcount/va_arg_promotion.rs | 6 ++--- tests/unit/out/refcount/va_arg_snprintf.rs | 2 +- tests/unit/out/refcount/va_arg_struct_ctx.rs | 2 +- tests/unit/out/refcount/va_arg_two_passes.rs | 4 ++-- tests/unit/out/refcount/va_arg_void_ptr.rs | 4 ++-- tests/unit/out/unsafe/anonymous_enum.rs | 4 ++-- tests/unit/out/unsafe/anonymous_enum_c.rs | 4 ++-- .../out/unsafe/va_arg_non_primitive_ptrs.rs | 2 +- tests/unit/out/unsafe/va_arg_struct_ctx.rs | 2 +- tests/unit/out/unsafe/va_arg_void_ptr.rs | 2 +- 30 files changed, 93 insertions(+), 67 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index c62ed111..46e47101 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2005,6 +2005,7 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) { uint64_t arr_size = arr_ty->getSize().getZExtValue(); if (expr->getString().empty()) { StrCat(std::format("[0 as libc::c_char; {}]", arr_size)); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } uint64_t pad = arr_size > expr->getString().size() @@ -2012,10 +2013,12 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) { : 0; StrCat(std::format("std::mem::transmute(*b{})", GetEscapedStringLiteral(expr, pad))); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } StrCat(std::format("std::mem::transmute(*b{})", GetEscapedStringLiteral(expr, 1))); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } if (expr->getString().contains('\0')) { @@ -2025,9 +2028,11 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) { } out += getTypedLiteral("0", CharRustType()) + "])"; StrCat(out); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } StrCat(std::format("c{}", GetEscapedStringLiteral(expr, 0))); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } @@ -2349,6 +2354,9 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { ConvertUnsignedArithOperand(lhs, type); } ConvertUnsignedArithBinaryOperator(expr, rhs); + if (!expr->isCompoundAssignmentOp()) { + computed_expr_type_ = ComputedExprType::FreshValue; + } } else if (expr->isAssignmentOp()) { if (expr->isCompoundAssignmentOp() && expr->getLHS()->getType()->isPointerType() && @@ -2408,6 +2416,7 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { PushParen paren(*this); ConvertCondition(expr->getRHS()); } + computed_expr_type_ = ComputedExprType::FreshValue; } else { ConvertGenericBinaryOperator(expr); } @@ -2429,6 +2438,7 @@ void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) { PushParen rhs_paren(*this); Convert(rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)); } + computed_expr_type_ = ComputedExprType::FreshValue; } bool Converter::IsReferenceType(const clang::Expr *expr) const { @@ -2991,12 +3001,14 @@ bool Converter::VisitVAArgExpr(clang::VAArgExpr *expr) { Convert(va_list_expr); } StrCat(".arg::<*mut ::libc::c_void>()"); + SetFreshType(expr->getType()); return false; } Convert(va_list_expr); StrCat(".arg::<"); Convert(expr->getType()); StrCat(">()"); + SetFreshType(expr->getType()); return false; } @@ -3246,6 +3258,7 @@ void Converter::AddIncDecImpls(clang::EnumDecl *decl) { bool Converter::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr) { if (expr->getType()->isPointerType()) { StrCat(token::kDefault); + computed_expr_type_ = ComputedExprType::FreshPointer; } return false; } @@ -3278,11 +3291,13 @@ bool Converter::VisitImplicitValueInitExpr(clang::ImplicitValueInitExpr *expr) { auto elem_ty = const_arr_ty->getElementType(); if (elem_ty->isIntegerType() && !elem_ty->isEnumeralType()) { StrCat(std::format("[0; {}]", const_arr_ty->getSize().getZExtValue())); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } StrCat( std::format("std::array::from_fn::<_, {}, _>(|_| Default::default())", const_arr_ty->getSize().getZExtValue())); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } } @@ -3681,6 +3696,7 @@ void Converter::ConvertEqualsNullPtr(clang::Expr *expr) { } else { StrCat(").is_null()"); } + computed_expr_type_ = ComputedExprType::FreshValue; } void Converter::ConvertPointerSubscript(clang::ArraySubscriptExpr *expr) { diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 15a10b5a..d0be5057 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -402,6 +402,7 @@ bool ConverterRefCount::VisitArraySubscriptExpr( StrCat(GetPointerDerefPrefix(expr->getType())); ConvertArraySubscript(base, expr->getIdx(), expr->getType()); StrCat(GetPointerDerefSuffix(expr->getType())); + SetValueFreshness(expr->getType()); } else { ConvertArraySubscript(base, expr->getIdx(), expr->getType()); } @@ -788,6 +789,7 @@ bool ConverterRefCount::ConvertIncAndDec(clang::UnaryOperator *expr) { } else { StrCat(str, '.', method, "()"); } + SetFreshType(expr->getType()); return true; } @@ -1133,6 +1135,7 @@ bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) { uint64_t arr_size = arr_ty->getSize().getZExtValue(); if (expr->getString().empty()) { StrCat(std::format("vec![0u8; {}].into_boxed_slice()", arr_size)); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } pad = arr_size > expr->getString().size() @@ -1140,9 +1143,11 @@ bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) { : 0; } StrCat(std::format("Box::from(*b{})", GetEscapedStringLiteral(expr, pad))); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } StrCat(std::format("b{}", GetEscapedStringLiteral(expr, 0))); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } @@ -1270,6 +1275,7 @@ void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) { StrCat('('); Convert(expr); StrCat(").is_null()"); + computed_expr_type_ = ComputedExprType::FreshValue; } bool ConverterRefCount::VisitFunctionPointerCast( @@ -1421,6 +1427,7 @@ void ConverterRefCount::EmitStmtExprTail(clang::Expr *tail) { Convert(tail); StrCat(token::kSemiColon); StrCat("__result"); + SetFreshType(tail->getType()); } void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { @@ -1483,6 +1490,8 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { if (expr->isCompoundAssignmentOp()) { StrCat(token::kSemiColon); EmitSetOrAssign(lhs, "rhs_0"); + } else { + computed_expr_type_ = ComputedExprType::FreshValue; } return; } @@ -1608,6 +1617,7 @@ void ConverterRefCount::ConvertUnionMemberAccessor(clang::MemberExpr *expr) { return; } StrCat(DerefPtrExpr(str, member->getType())); + SetValueFreshness(member->getType()); } bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { @@ -1882,6 +1892,7 @@ bool ConverterRefCount::VisitImplicitValueInitExpr( StrCat("Box::new("); Converter::VisitImplicitValueInitExpr(expr); StrCat(')'); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } } @@ -1909,6 +1920,7 @@ bool ConverterRefCount::VisitVAArgExpr(clang::VAArgExpr *expr) { StrCat(ToString(expr->getType())); } StrCat(">()"); + SetFreshType(expr->getType()); return false; } @@ -1936,10 +1948,12 @@ ConverterRefCount::GetArrayDefaultAsString(clang::QualType qual_type) { std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) { if (IsVaListType(qual_type)) { + computed_expr_type_ = ComputedExprType::FreshValue; return BoxValue("VaList::default()"); } if (auto arr = GetArrayDefaultAsString(qual_type); !arr.empty()) { + computed_expr_type_ = ComputedExprType::FreshValue; return BoxValue(std::move(arr)); } @@ -1964,6 +1978,7 @@ std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) { } else { return Converter::GetDefaultAsString(qual_type); } + computed_expr_type_ = ComputedExprType::FreshPointer; return BoxValue(std::move(ret)); } @@ -2103,6 +2118,7 @@ void ConverterRefCount::ConvertGenericBinaryOperator( opcode, ConvertFreshRValue( rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)))); + computed_expr_type_ = ComputedExprType::FreshValue; return; } @@ -2110,6 +2126,7 @@ void ConverterRefCount::ConvertGenericBinaryOperator( Convert(lhs, GetOperandImplicitConversionTarget(expr, lhs, rhs)); StrCat(opcode); Convert(rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)); + computed_expr_type_ = ComputedExprType::FreshValue; } void ConverterRefCount::ConvertUniquePtrDeref( @@ -2394,6 +2411,7 @@ void ConverterRefCount::ConvertArrow(clang::Expr *expr) { if (!is_overloaded_arrow) { auto ptr = ToString(expr); StrCat(DerefPtrExpr(ptr, expr->getType()->getPointeeType())); + SetValueFreshness(expr->getType()->getPointeeType()); return; } diff --git a/tests/unit/out/refcount/bool_condition_ptr.rs b/tests/unit/out/refcount/bool_condition_ptr.rs index 11703cb8..6fc34386 100644 --- a/tests/unit/out/refcount/bool_condition_ptr.rs +++ b/tests/unit/out/refcount/bool_condition_ptr.rs @@ -40,8 +40,8 @@ fn main_0() -> i32 { assert!(((*t5.borrow()) == 0)); let t6: Value = Rc::new(RefCell::new((!!(*np.borrow()).is_null() as i32))); assert!(((*t6.borrow()) == 1)); - let b2: Value = Rc::new(RefCell::new((!(*p.borrow()).is_null()).clone())); - let b3: Value = Rc::new(RefCell::new((!(*np.borrow()).is_null()).clone())); + let b2: Value = Rc::new(RefCell::new(!(*p.borrow()).is_null())); + let b3: Value = Rc::new(RefCell::new(!(*np.borrow()).is_null())); assert!((*b2.borrow())); assert!(!(*b3.borrow())); return 0; diff --git a/tests/unit/out/refcount/bool_condition_ptr_c.rs b/tests/unit/out/refcount/bool_condition_ptr_c.rs index 95cfedf4..e9bd4bfa 100644 --- a/tests/unit/out/refcount/bool_condition_ptr_c.rs +++ b/tests/unit/out/refcount/bool_condition_ptr_c.rs @@ -40,8 +40,8 @@ fn main_0() -> i32 { assert!(((((*t5.borrow()) == 0) as i32) != 0)); let t6: Value = Rc::new(RefCell::new((!!(*np.borrow()).is_null() as i32))); assert!(((((*t6.borrow()) == 1) as i32) != 0)); - let b2: Value = Rc::new(RefCell::new((!(*p.borrow()).is_null()).clone())); - let b3: Value = Rc::new(RefCell::new((!(*np.borrow()).is_null()).clone())); + let b2: Value = Rc::new(RefCell::new(!(*p.borrow()).is_null())); + let b3: Value = Rc::new(RefCell::new(!(*np.borrow()).is_null())); assert!((*b2.borrow())); assert!(((!(*b3.borrow()) as i32) != 0)); return 0; diff --git a/tests/unit/out/refcount/expr_as_bool_c.rs b/tests/unit/out/refcount/expr_as_bool_c.rs index 5d08cf57..62d58559 100644 --- a/tests/unit/out/refcount/expr_as_bool_c.rs +++ b/tests/unit/out/refcount/expr_as_bool_c.rs @@ -13,14 +13,13 @@ pub fn cmp_eq_0(rc: i32) -> i32 { pub fn cmp_or_ptr_1(p: Ptr, q: Ptr) -> i32 { let p: Value> = Rc::new(RefCell::new(p)); let q: Value> = Rc::new(RefCell::new(q)); - return (((!(*p.borrow()).is_null()) || (!(*q.borrow()).is_null())) as i32).clone(); + return (((!(*p.borrow()).is_null()) || (!(*q.borrow()).is_null())) as i32); } pub fn both_null_2(s1: Ptr, s2: Ptr) -> i32 { let s1: Value> = Rc::new(RefCell::new(s1)); let s2: Value> = Rc::new(RefCell::new(s2)); return ((((((*s1.borrow()).is_null()) as i32) != 0) - && ((((*s2.borrow()).is_null()) as i32) != 0)) as i32) - .clone(); + && ((((*s2.borrow()).is_null()) as i32) != 0)) as i32); } pub fn main() { std::process::exit(main_0()); @@ -74,10 +73,10 @@ fn main_0() -> i32 { let p1: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); let p2: Value> = Rc::new(RefCell::new(Ptr::::null())); let either: Value = Rc::new(RefCell::new( - (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32).clone(), + (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32), )); let both: Value = Rc::new(RefCell::new( - (((!(*p1.borrow()).is_null()) && (!(*p2.borrow()).is_null())) as i32).clone(), + (((!(*p1.borrow()).is_null()) && (!(*p2.borrow()).is_null())) as i32), )); assert!(((((*either.borrow()) == 1) as i32) != 0)); assert!(((((*both.borrow()) == 0) as i32) != 0)); diff --git a/tests/unit/out/refcount/expr_as_bool_cpp.rs b/tests/unit/out/refcount/expr_as_bool_cpp.rs index fa3f0949..17a64cba 100644 --- a/tests/unit/out/refcount/expr_as_bool_cpp.rs +++ b/tests/unit/out/refcount/expr_as_bool_cpp.rs @@ -13,12 +13,12 @@ pub fn cmp_eq_0(rc: i32) -> i32 { pub fn cmp_or_ptr_1(p: Ptr, q: Ptr) -> i32 { let p: Value> = Rc::new(RefCell::new(p)); let q: Value> = Rc::new(RefCell::new(q)); - return (((!(*p.borrow()).is_null()) || (!(*q.borrow()).is_null())) as i32).clone(); + return (((!(*p.borrow()).is_null()) || (!(*q.borrow()).is_null())) as i32); } pub fn both_null_2(s1: Ptr, s2: Ptr) -> i32 { let s1: Value> = Rc::new(RefCell::new(s1)); let s2: Value> = Rc::new(RefCell::new(s2)); - return ((((*s1.borrow()).is_null()) && ((*s2.borrow()).is_null())) as i32).clone(); + return ((((*s1.borrow()).is_null()) && ((*s2.borrow()).is_null())) as i32); } pub fn main() { std::process::exit(main_0()); @@ -69,10 +69,10 @@ fn main_0() -> i32 { let p1: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); let p2: Value> = Rc::new(RefCell::new(Ptr::::null())); let either: Value = Rc::new(RefCell::new( - (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32).clone(), + (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32), )); let both: Value = Rc::new(RefCell::new( - (((!(*p1.borrow()).is_null()) && (!(*p2.borrow()).is_null())) as i32).clone(), + (((!(*p1.borrow()).is_null()) && (!(*p2.borrow()).is_null())) as i32), )); assert!(((*either.borrow()) == 1)); assert!(((*both.borrow()) == 0)); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 36031f52..f023a545 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -15,7 +15,7 @@ pub struct MinHeapNode { } impl MinHeapNode { pub fn IsLeaf(&self) -> bool { - return (((*self.left.borrow()).is_null()) && ((*self.right.borrow()).is_null())).clone(); + return ((*self.left.borrow()).is_null()) && ((*self.right.borrow()).is_null()); } } impl Clone for MinHeapNode { diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index 07e5a40e..83c876c3 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -263,8 +263,7 @@ impl ByteRepr for Inner_struct { pub fn is_active_0(w: Ptr) -> i32 { let w: Value> = Rc::new(RefCell::new(w)); return ((((*(*(*w.borrow()).upgrade().deref()).mode.borrow()) as u32) - == ((widget_enum::MODE_ACTIVE as i32) as u32)) as i32) - .clone(); + == ((widget_enum::MODE_ACTIVE as i32) as u32)) as i32); } pub fn main() { std::process::exit(main_0()); diff --git a/tests/unit/out/refcount/union_tagged_many_arms.rs b/tests/unit/out/refcount/union_tagged_many_arms.rs index 471c32f7..f4fc605f 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -135,7 +135,7 @@ fn main_0() -> i32 { (*(*c.borrow()).tag.borrow_mut()) = Tag_enum::T_TEXT; (*(*c.borrow()).payload.borrow_mut()) .text() - .write((Ptr::from_string_literal(b"hello")).clone()); + .write(Ptr::from_string_literal(b"hello")); assert!( (((((((*(*c.borrow()).payload.borrow()).text().read()) .offset((0) as isize) diff --git a/tests/unit/out/refcount/va_arg_chain.rs b/tests/unit/out/refcount/va_arg_chain.rs index 56e01c1e..bd4afad0 100644 --- a/tests/unit/out/refcount/va_arg_chain.rs +++ b/tests/unit/out/refcount/va_arg_chain.rs @@ -14,7 +14,7 @@ pub fn extract_nth_0(n: i32, ap: VaList) -> i32 { (*ap.borrow_mut()).arg::(); (*i.borrow_mut()).postfix_inc(); } - return ((*ap.borrow_mut()).arg::()).clone(); + return (*ap.borrow_mut()).arg::(); } pub fn middle_layer_1(n: i32, ap: VaList) -> i32 { let n: Value = Rc::new(RefCell::new(n)); diff --git a/tests/unit/out/refcount/va_arg_concat.rs b/tests/unit/out/refcount/va_arg_concat.rs index 0e86d494..e736569c 100644 --- a/tests/unit/out/refcount/va_arg_concat.rs +++ b/tests/unit/out/refcount/va_arg_concat.rs @@ -13,7 +13,7 @@ pub fn sum_ints_0(first: i32, __args: &[VaArg]) -> i32 { (*args.borrow_mut()) = VaList::new(__args); let val: Value = >::default(); 'loop_: while (((({ - (*val.borrow_mut()) = ((*args.borrow_mut()).arg::()).clone(); + (*val.borrow_mut()) = (*args.borrow_mut()).arg::(); (*val.borrow()) }) != 0) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_conditional.rs b/tests/unit/out/refcount/va_arg_conditional.rs index a226eb39..0c71e8fd 100644 --- a/tests/unit/out/refcount/va_arg_conditional.rs +++ b/tests/unit/out/refcount/va_arg_conditional.rs @@ -12,7 +12,7 @@ pub fn conditional_log_0(verbose: i32, fmt: Ptr, __args: &[VaArg]) -> i32 { if ((*verbose.borrow()) != 0) { let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); - let result: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let result: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); return (*result.borrow()); } return -1_i32; diff --git a/tests/unit/out/refcount/va_arg_copy.rs b/tests/unit/out/refcount/va_arg_copy.rs index f34cac3a..e58de7db 100644 --- a/tests/unit/out/refcount/va_arg_copy.rs +++ b/tests/unit/out/refcount/va_arg_copy.rs @@ -15,13 +15,13 @@ pub fn sum_with_copy_0(count: i32, __args: &[VaArg]) -> i32 { let sum1: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - (*sum1.borrow_mut()) += ((*ap.borrow_mut()).arg::()).clone(); + (*sum1.borrow_mut()) += (*ap.borrow_mut()).arg::(); (*i.borrow_mut()).postfix_inc(); } let sum2: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - (*sum2.borrow_mut()) += ((*aq.borrow_mut()).arg::()).clone(); + (*sum2.borrow_mut()) += (*aq.borrow_mut()).arg::(); (*i.borrow_mut()).postfix_inc(); } assert!(((((*sum1.borrow()) == (*sum2.borrow())) as i32) != 0)); diff --git a/tests/unit/out/refcount/va_arg_fn_ptr.rs b/tests/unit/out/refcount/va_arg_fn_ptr.rs index bca43c74..df50e0ad 100644 --- a/tests/unit/out/refcount/va_arg_fn_ptr.rs +++ b/tests/unit/out/refcount/va_arg_fn_ptr.rs @@ -24,7 +24,7 @@ pub fn apply_unary_3(x: i32, __args: &[VaArg]) -> i32 { let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); let fn_: Value i32>> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg:: i32>>()).clone(), + (*ap.borrow_mut()).arg:: i32>>(), )); let result: Value = Rc::new(RefCell::new(({ (*(*fn_.borrow()))((*x.borrow())) }))); return (*result.borrow()); @@ -35,7 +35,7 @@ pub fn apply_binary_4(a: i32, b: i32, __args: &[VaArg]) -> i32 { let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); let fn_: Value i32>> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg:: i32>>()).clone(), + (*ap.borrow_mut()).arg:: i32>>(), )); let result: Value = Rc::new(RefCell::new( ({ (*(*fn_.borrow()))((*a.borrow()), (*b.borrow())) }), diff --git a/tests/unit/out/refcount/va_arg_forward.rs b/tests/unit/out/refcount/va_arg_forward.rs index 57f05ea2..1fc4b38e 100644 --- a/tests/unit/out/refcount/va_arg_forward.rs +++ b/tests/unit/out/refcount/va_arg_forward.rs @@ -12,7 +12,7 @@ pub fn inner_0(count: i32, ap: VaList) -> i32 { let total: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - (*total.borrow_mut()) += ((*ap.borrow_mut()).arg::()).clone(); + (*total.borrow_mut()) += (*ap.borrow_mut()).arg::(); (*i.borrow_mut()).postfix_inc(); } return (*total.borrow()); diff --git a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs index 2731c07f..7d48118b 100644 --- a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs @@ -13,12 +13,11 @@ pub fn mixed_args_0(count: i32, __args: &[VaArg]) -> i32 { let total: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - let tag: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let tag: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); if ((((*tag.borrow()) == 0) as i32) != 0) { - (*total.borrow_mut()) += ((*ap.borrow_mut()).arg::()).clone(); + (*total.borrow_mut()) += (*ap.borrow_mut()).arg::(); } else { - let ptr: Value> = - Rc::new(RefCell::new(((*ap.borrow_mut()).arg::>()).clone())); + let ptr: Value> = Rc::new(RefCell::new((*ap.borrow_mut()).arg::>())); let __rhs = ((*ptr.borrow()).read()); (*total.borrow_mut()) += __rhs; } diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 023a0f91..d9426ab9 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -13,13 +13,13 @@ pub fn sum_mixed_0(count: i32, __args: &[VaArg]) -> i32 { let total: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - let tag: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let tag: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); if ((((*tag.borrow()) == 0) as i32) != 0) { - (*total.borrow_mut()) += ((*ap.borrow_mut()).arg::()).clone(); + (*total.borrow_mut()) += (*ap.borrow_mut()).arg::(); } else if ((((*tag.borrow()) == 1) as i32) != 0) { - (*total.borrow_mut()) += ((*ap.borrow_mut()).arg::() as i32).clone(); + (*total.borrow_mut()) += ((*ap.borrow_mut()).arg::() as i32); } else { - let val: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let val: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); (*total.borrow_mut()) += ((*val.borrow()) as i32); } (*i.borrow_mut()).postfix_inc(); diff --git a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs index beb9a941..d19ca63d 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -71,31 +71,27 @@ pub fn dispatch_0(option: i32, __args: &[VaArg]) -> i32 { let __match_cond = (*option.borrow()); match __match_cond { __v if __v == (opt::OPT_STRING_OUT as i32) => { - let out: Value>> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg::>>()).clone(), - )); + let out: Value>> = + Rc::new(RefCell::new((*ap.borrow_mut()).arg::>>())); (*out.borrow()).write(Ptr::from_string_literal(b"hello")); (*result.borrow_mut()) = 1; break 'switch; } __v if __v == (opt::OPT_FILE as i32) => { - let f: Value> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg::>()).clone(), - )); - (*result.borrow_mut()) = ((!((*f.borrow()).is_null())) as i32).clone(); + let f: Value> = + Rc::new(RefCell::new((*ap.borrow_mut()).arg::>())); + (*result.borrow_mut()) = ((!((*f.borrow()).is_null())) as i32); break 'switch; } __v if __v == (opt::OPT_NODE as i32) => { - let n: Value> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg::>()).clone(), - )); + let n: Value> = + Rc::new(RefCell::new((*ap.borrow_mut()).arg::>())); (*result.borrow_mut()) = (*(*(*n.borrow()).upgrade().deref()).data.borrow()); break 'switch; } __v if __v == (opt::OPT_NODE_OUT as i32) => { - let out: Value>> = Rc::new(RefCell::new( - ((*ap.borrow_mut()).arg::>>()).clone(), - )); + let out: Value>> = + Rc::new(RefCell::new((*ap.borrow_mut()).arg::>>())); (*out.borrow()).write(Ptr::::null()); (*result.borrow_mut()) = 2; break 'switch; diff --git a/tests/unit/out/refcount/va_arg_null_int_ptr.rs b/tests/unit/out/refcount/va_arg_null_int_ptr.rs index d8e665c7..272eadb4 100644 --- a/tests/unit/out/refcount/va_arg_null_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_null_int_ptr.rs @@ -13,8 +13,7 @@ pub fn first_nonnull_0(count: i32, __args: &[VaArg]) -> i32 { let result: Value = Rc::new(RefCell::new(-1_i32)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) { - let p: Value> = - Rc::new(RefCell::new(((*ap.borrow_mut()).arg::>()).clone())); + let p: Value> = Rc::new(RefCell::new((*ap.borrow_mut()).arg::>())); if (((!((*p.borrow()).is_null())) as i32) != 0) { let __rhs = ((*p.borrow()).read()); (*result.borrow_mut()) = __rhs; diff --git a/tests/unit/out/refcount/va_arg_printf.rs b/tests/unit/out/refcount/va_arg_printf.rs index d9af9044..943a8ea1 100644 --- a/tests/unit/out/refcount/va_arg_printf.rs +++ b/tests/unit/out/refcount/va_arg_printf.rs @@ -11,8 +11,8 @@ pub fn logf_impl_0(fmt: Ptr, ap: VaList) -> i32 { let ap: Value = Rc::new(RefCell::new(ap)); (*fmt.borrow()).clone(); return { - let _lhs = ((*ap.borrow_mut()).arg::()).clone(); - _lhs + ((*ap.borrow_mut()).arg::()).clone() + let _lhs = (*ap.borrow_mut()).arg::(); + _lhs + (*ap.borrow_mut()).arg::() }; } pub fn logf_1(fmt: Ptr, __args: &[VaArg]) -> i32 { @@ -28,7 +28,7 @@ pub fn lenf_2(fmt: Ptr, __args: &[VaArg]) -> i32 { let fmt: Value> = Rc::new(RefCell::new(fmt)); let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); - let s: Value> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::>()).clone())); + let s: Value> = Rc::new(RefCell::new((*ap.borrow_mut()).arg::>())); let result: Value = Rc::new(RefCell::new( ((*s.borrow()).to_c_string_iterator().count() as i32), )); diff --git a/tests/unit/out/refcount/va_arg_promotion.rs b/tests/unit/out/refcount/va_arg_promotion.rs index e6946aec..08a30ddc 100644 --- a/tests/unit/out/refcount/va_arg_promotion.rs +++ b/tests/unit/out/refcount/va_arg_promotion.rs @@ -10,9 +10,9 @@ pub fn test_promotions_0(count: i32, __args: &[VaArg]) -> i32 { let count: Value = Rc::new(RefCell::new(count)); let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); - let a: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); - let b: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); - let c: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let a: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); + let b: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); + let c: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); assert!(((((*a.borrow()) == 65) as i32) != 0)); assert!(((((*b.borrow()) == 10) as i32) != 0)); assert!(((((*c.borrow()) == 3.0E+0) as i32) != 0)); diff --git a/tests/unit/out/refcount/va_arg_snprintf.rs b/tests/unit/out/refcount/va_arg_snprintf.rs index 278df007..3b74afc0 100644 --- a/tests/unit/out/refcount/va_arg_snprintf.rs +++ b/tests/unit/out/refcount/va_arg_snprintf.rs @@ -12,7 +12,7 @@ pub fn extract_first_0(buf: Ptr, size: i32, fmt: Ptr, __args: &[VaArg]) let fmt: Value> = Rc::new(RefCell::new(fmt)); let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); - let n: Value = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::()).clone())); + let n: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); let __rhs = ((*n.borrow()) as u8); (*buf.borrow()).offset((0) as isize).write(__rhs); return (*n.borrow()); diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index 936e749f..56fd66a5 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -41,7 +41,7 @@ pub fn set_error_0(ctx: Ptr, fmt: Ptr, __args: &[VaArg]) { let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); (*(*(*ctx.borrow()).upgrade().deref()).last_error.borrow_mut()) = - ((*ap.borrow_mut()).arg::()).clone(); + (*ap.borrow_mut()).arg::(); } } pub fn main() { diff --git a/tests/unit/out/refcount/va_arg_two_passes.rs b/tests/unit/out/refcount/va_arg_two_passes.rs index 95e1bd89..0483bb39 100644 --- a/tests/unit/out/refcount/va_arg_two_passes.rs +++ b/tests/unit/out/refcount/va_arg_two_passes.rs @@ -14,7 +14,7 @@ pub fn sum_then_product_0(first: i32, __args: &[VaArg]) -> i32 { (*ap.borrow_mut()) = VaList::new(__args); let val: Value = >::default(); 'loop_: while (((({ - (*val.borrow_mut()) = ((*ap.borrow_mut()).arg::()).clone(); + (*val.borrow_mut()) = (*ap.borrow_mut()).arg::(); (*val.borrow()) }) != 0) as i32) != 0) @@ -23,7 +23,7 @@ pub fn sum_then_product_0(first: i32, __args: &[VaArg]) -> i32 { } (*ap.borrow_mut()) = VaList::new(__args); 'loop_: while (((({ - (*val.borrow_mut()) = ((*ap.borrow_mut()).arg::()).clone(); + (*val.borrow_mut()) = (*ap.borrow_mut()).arg::(); (*val.borrow()) }) != 0) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index 23b8ef71..a738cc15 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -69,12 +69,12 @@ pub fn registry_update_0(r: Ptr, field: field, __args: &[VaArg]) -> i3 match __match_cond { __v if __v == ((field::FIELD_SLOT as i32) as u32) => { (*(*(*r.borrow()).upgrade().deref()).slot.borrow_mut()) = - ((*ap.borrow_mut()).arg::()).clone(); + (*ap.borrow_mut()).arg::(); break 'switch; } __v if __v == ((field::FIELD_LEVEL as i32) as u32) => { (*(*(*r.borrow()).upgrade().deref()).level.borrow_mut()) = - ((*ap.borrow_mut()).arg::()).clone(); + (*ap.borrow_mut()).arg::(); break 'switch; } _ => { diff --git a/tests/unit/out/unsafe/anonymous_enum.rs b/tests/unit/out/unsafe/anonymous_enum.rs index ce23505f..27f254ce 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/anonymous_enum.rs @@ -108,12 +108,12 @@ unsafe fn main_0() -> i32 { assert!(((anon_3::THIRD_A as i32) != (anon_3::THIRD_B as i32))); let mut td: TdEnum = TdEnum::TD_A; assert!(((td as i32) == (TdEnum::TD_A as i32))); - td = (TdEnum::TD_B).clone(); + td = TdEnum::TD_B; assert!(((td as i32) == (TdEnum::TD_B as i32))); let mut w: WithAnonField = ::default(); w.field = anon_2::FIELD_A; assert!(((w.field as i32) == (anon_2::FIELD_A as i32))); - w.field = (anon_2::FIELD_B).clone(); + w.field = anon_2::FIELD_B; assert!(((w.field as i32) == (anon_2::FIELD_B as i32))); return 0; } diff --git a/tests/unit/out/unsafe/anonymous_enum_c.rs b/tests/unit/out/unsafe/anonymous_enum_c.rs index 8bdf3f73..7c5974e6 100644 --- a/tests/unit/out/unsafe/anonymous_enum_c.rs +++ b/tests/unit/out/unsafe/anonymous_enum_c.rs @@ -108,12 +108,12 @@ unsafe fn main_0() -> i32 { assert!(((((anon_3::THIRD_A as i32) != (anon_3::THIRD_B as i32)) as i32) != 0)); let mut td: TdEnum_enum = TdEnum_enum::TD_A; assert!(((((td as u32) == ((TdEnum_enum::TD_A as i32) as u32)) as i32) != 0)); - td = (TdEnum_enum::TD_B).clone(); + td = TdEnum_enum::TD_B; assert!(((((td as u32) == ((TdEnum_enum::TD_B as i32) as u32)) as i32) != 0)); let mut w: WithAnonField = ::default(); w.field = anon_2::FIELD_A; assert!(((((w.field as u32) == ((anon_2::FIELD_A as i32) as u32)) as i32) != 0)); - w.field = (anon_2::FIELD_B).clone(); + w.field = anon_2::FIELD_B; assert!(((((w.field as u32) == ((anon_2::FIELD_B as i32) as u32)) as i32) != 0)); return 0; } diff --git a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs index a51a1ff6..dde663eb 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -47,7 +47,7 @@ pub unsafe fn dispatch_0(mut option: i32, __args: &[VaArg]) -> i32 { } __v if __v == (opt::OPT_FILE as i32) => { let mut f: *mut ::libc::FILE = ap.arg::<*mut ::libc::FILE>(); - result = ((!((f).is_null())) as i32).clone(); + result = ((!((f).is_null())) as i32); break 'switch; } __v if __v == (opt::OPT_NODE as i32) => { diff --git a/tests/unit/out/unsafe/va_arg_struct_ctx.rs b/tests/unit/out/unsafe/va_arg_struct_ctx.rs index c70acdfb..176dc352 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -16,7 +16,7 @@ pub unsafe fn set_error_0(mut ctx: *mut context, mut fmt: *const libc::c_char, _ if ((*ctx).verbose != 0) { let mut ap: VaList = VaList::default(); ap = VaList::new(__args); - (*ctx).last_error = (ap.arg::()).clone(); + (*ctx).last_error = ap.arg::(); } } pub fn main() { diff --git a/tests/unit/out/unsafe/va_arg_void_ptr.rs b/tests/unit/out/unsafe/va_arg_void_ptr.rs index 35bce556..342bf5bb 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -40,7 +40,7 @@ pub unsafe fn registry_update_0(mut r: *mut registry, mut field: field, __args: break 'switch; } __v if __v == ((field::FIELD_LEVEL as i32) as u32) => { - (*r).level = (ap.arg::()).clone(); + (*r).level = ap.arg::(); break 'switch; } _ => { From 1f2294434fd012e567fa24d30c1d723850aaf2db Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 26 Jul 2026 21:12:34 +0100 Subject: [PATCH 2/2] Remove more clones --- cpp2rust/converter/converter.cpp | 11 ++--------- cpp2rust/converter/converter.h | 10 ++++++++-- cpp2rust/converter/models/converter_refcount.cpp | 2 +- .../out/refcount/cross_tu_tag_collision.rs | 2 +- tests/unit/out/refcount/anonymous_enum.rs | 2 +- tests/unit/out/refcount/bool_condition_enum.rs | 2 +- tests/unit/out/refcount/bool_condition_enum_c.rs | 2 +- tests/unit/out/refcount/enum_int_interop.rs | 14 +++++++------- tests/unit/out/refcount/enum_int_interop_c.rs | 10 +++++----- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 46e47101..59410ced 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -669,7 +669,7 @@ bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { return true; } -bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) { +bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) const { auto *derives = Mapper::MappedDerives(ctx_.getCanonicalTagType(decl)); return derives && std::find(derives->begin(), derives->end(), "Copy") != derives->end(); @@ -4394,15 +4394,8 @@ void Converter::SetFresh() { } } -static bool hasCopyTrait(clang::QualType type) { - if (type->isBuiltinType()) - return true; - - return false; -} - void Converter::SetValueFreshness(clang::QualType type) { - if (hasCopyTrait(type)) { + if (TypeIsCopyable(type)) { computed_expr_type_ = ComputedExprType::FreshValue; } else if (type->isPointerType() || type->isReferenceType()) { computed_expr_type_ = ComputedExprType::Pointer; diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index d15f19c9..8a55ef2b 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -279,7 +279,13 @@ class Converter : public clang::RecursiveASTVisitor { if (ty->isFunctionPointerType() || ty->isFunctionType()) { return FunctionPointerImplementsCopy(); } - return ty->isIntegerType(); + if (ty->isBuiltinType() || ty->isEnumeralType()) { + return true; + } + if (auto *record = ty->getAsRecordDecl()) { + return RecordDerivesCopy(record); + } + return false; } virtual void ConvertPrintf(clang::CallExpr *expr); @@ -602,7 +608,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool RecordDerivesDefault(const clang::RecordDecl *decl); - bool RecordDerivesCopy(const clang::RecordDecl *decl); + bool RecordDerivesCopy(const clang::RecordDecl *decl) const; bool RecordHasCopyableFields(const clang::RecordDecl *decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index d0be5057..2e33e5f5 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2391,7 +2391,7 @@ void ConverterRefCount::ConvertDeref(clang::Expr *expr) { Convert(expr); if (deref) { StrCat(GetPointerDerefSuffix(pointee_type)); - SetValueFreshness(expr->getType()); + SetValueFreshness(pointee_type); } } diff --git a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs index f4846e89..3493dcce 100644 --- a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs +++ b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs @@ -71,5 +71,5 @@ impl ByteRepr for widget_enum { } pub fn b_value_1() -> i32 { let w: Value = Rc::new(RefCell::new(widget_enum::WIDGET_C)); - return ((*w.borrow()) as i32).clone(); + return ((*w.borrow()) as i32); } diff --git a/tests/unit/out/refcount/anonymous_enum.rs b/tests/unit/out/refcount/anonymous_enum.rs index 47298b56..780a7f05 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -136,7 +136,7 @@ impl Clone for WithAnonField { fn clone(&self) -> Self { let mut this = Self { a: Rc::new(RefCell::new((*self.a.borrow()))), - field: Rc::new(RefCell::new((*self.field.borrow()).clone())), + field: Rc::new(RefCell::new((*self.field.borrow()))), }; this } diff --git a/tests/unit/out/refcount/bool_condition_enum.rs b/tests/unit/out/refcount/bool_condition_enum.rs index 228c2f70..540855e4 100644 --- a/tests/unit/out/refcount/bool_condition_enum.rs +++ b/tests/unit/out/refcount/bool_condition_enum.rs @@ -52,7 +52,7 @@ fn main_0() -> i32 { } let t9: Value = Rc::new(RefCell::new((!((*code.borrow()) != Code::from(0)) as i32))); assert!(((*t9.borrow()) == 1)); - let b4: Value = Rc::new(RefCell::new(((*code.borrow()) != Code::from(0)).clone())); + let b4: Value = Rc::new(RefCell::new(((*code.borrow()) != Code::from(0)))); assert!(!(*b4.borrow())); return 0; } diff --git a/tests/unit/out/refcount/bool_condition_enum_c.rs b/tests/unit/out/refcount/bool_condition_enum_c.rs index c22850e6..f8ed68b4 100644 --- a/tests/unit/out/refcount/bool_condition_enum_c.rs +++ b/tests/unit/out/refcount/bool_condition_enum_c.rs @@ -52,7 +52,7 @@ fn main_0() -> i32 { } let t9: Value = Rc::new(RefCell::new((!((*code.borrow()) != Code::from(0)) as i32))); assert!(((((*t9.borrow()) == 1) as i32) != 0)); - let b4: Value = Rc::new(RefCell::new(((*code.borrow()) != Code::from(0)).clone())); + let b4: Value = Rc::new(RefCell::new(((*code.borrow()) != Code::from(0)))); assert!(((!(*b4.borrow()) as i32) != 0)); return 0; } diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index e8c088e5..99a43eef 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -96,8 +96,8 @@ impl Clone for Entry { fn clone(&self) -> Self { let mut this = Self { name: Rc::new(RefCell::new((*self.name.borrow()).clone())), - color: Rc::new(RefCell::new((*self.color.borrow()).clone())), - opt: Rc::new(RefCell::new((*self.opt.borrow()).clone())), + color: Rc::new(RefCell::new((*self.color.borrow()))), + opt: Rc::new(RefCell::new((*self.opt.borrow()))), }; this } @@ -149,7 +149,7 @@ thread_local!( ); pub fn as_int_4(c: Color) -> i32 { let c: Value = Rc::new(RefCell::new(c)); - return ((*c.borrow()) as i32).clone(); + return ((*c.borrow()) as i32); } pub fn classify_option_5(option: i32) -> i32 { let option: Value = Rc::new(RefCell::new(option)); @@ -207,7 +207,7 @@ fn main_0() -> i32 { } } }; - let x: Value = Rc::new(RefCell::new(((*c.borrow()) as i32).clone())); + let x: Value = Rc::new(RefCell::new(((*c.borrow()) as i32))); assert!(((*x.borrow()) == 0)); let y: Value = Rc::new(RefCell::new((((*c.borrow()) as i32) + 1))); assert!(((*y.borrow()) == 1)); @@ -221,12 +221,12 @@ fn main_0() -> i32 { let o: Value