diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 81a94fda1..031f6e83e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -681,6 +681,13 @@ bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { return true; } +bool Converter::IsPassThroughRule(clang::Expr *expr) const { + const auto *rule = Mapper::GetExprRule(GetCalleeOrExpr(expr)); + return rule && rule->body.size() == 1 && + std::holds_alternative( + rule->body[0]); +} + bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) const { auto *derives = Mapper::MappedDerives(ctx_.getCanonicalTagType(decl)); return derives && @@ -1491,7 +1498,12 @@ bool Converter::Convert(clang::Expr *expr, NeedsImplicitScalarCast(expr->IgnoreImplicit()->getType(), *implicit_convert_to); PushParen paren(*this, needs_conversion); + computed_expr_type_ = ComputedExprType::Unknown; bool result = TraverseStmt(expr); + if (expr && computed_expr_type_ == ComputedExprType::Unknown) { + expr->dump(); + assert(false && "computed_expr_type_ not set"); + } if (needs_conversion) { ConvertCast(*implicit_convert_to); computed_expr_type_ = ComputedExprType::FreshValue; @@ -1721,17 +1733,20 @@ void Converter::ConvertVAArgCall(clang::CallExpr *expr) { bool Converter::VisitCallExpr(clang::CallExpr *expr) { if (IsBuiltinVaStart(expr) || IsBuiltinVaEnd(expr) || IsBuiltinVaCopy(expr)) { ConvertVAArgCall(expr); + SetFreshType(expr->getType()); return false; } // p->~T() on a scalar is a no-op if (clang::isa( expr->getCallee()->IgnoreParenImpCasts())) { + SetFreshType(expr->getType()); return false; } if (auto plugin_str = TryPluginConvert(expr)) { StrCat(*plugin_str); + SetFreshType(expr->getType()); return false; } @@ -1750,9 +1765,10 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) { str = GetMappedAsString(expr, args, num_args, &ctx); }; - if ((IsReferenceType(expr) || - GetReturnTypeOfFunction(expr)->isReferenceType()) && - !isAddrOf() && !isVoid()) { + bool deref_ref = (IsReferenceType(expr) || + GetReturnTypeOfFunction(expr)->isReferenceType()) && + !isAddrOf() && !isVoid(); + if (deref_ref) { str = "( * " + std::move(str) + " )"; } @@ -1761,6 +1777,11 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) { } StrCat(str); + if (deref_ref) { + SetValueFreshness(expr->getType()); + } else if (!IsPassThroughRule(expr)) { + SetFreshType(expr->getType()); + } return false; } @@ -1795,6 +1816,7 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) { } StrCat(str); + SetFreshType(expr->getType()); return false; } @@ -1809,6 +1831,7 @@ void Converter::EmitFnPtrCall(clang::Expr *callee) { void Converter::ConvertFunctionToFunctionPointer( const clang::FunctionDecl *fn_decl) { StrCat(std::format("Some({})", Mapper::MapFunctionName(fn_decl))); + computed_expr_type_ = ComputedExprType::FreshPointer; } Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) { @@ -2256,6 +2279,7 @@ void Converter::ConvertIntegerToEnumeralCast(clang::Expr *to, auto dst_enum = to->getType()->getAs(); if (src_enum && dst_enum && dst_enum->getDecl() == src_enum) { StrCat(EnumeratorName(ec)); + computed_expr_type_ = ComputedExprType::FreshValue; return; } } @@ -2266,6 +2290,7 @@ void Converter::ConvertIntegerToEnumeralCast(clang::Expr *to, Convert(from); } StrCat(keyword::kAs, GetUnsafeTypeAsString(to->getType())); + computed_expr_type_ = ComputedExprType::FreshValue; } void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) { @@ -2285,6 +2310,7 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) { Convert(sub_expr); StrCat(token::kDiff); StrCat(token::kZero); + computed_expr_type_ = ComputedExprType::FreshValue; } bool Converter::IsCastRedundantInRust(clang::Expr *expr, @@ -2323,6 +2349,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { } else { StrCat(dest_pointee_const ? ".as_ptr()" : ".as_mut_ptr()"); } + computed_expr_type_ = ComputedExprType::FreshPointer; break; } case clang::CastKind::CK_BitCast: { @@ -2334,6 +2361,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { StrCat(ConvertPointeeType(sub_expr->getType())); } ConvertCast(type); + SetFreshType(type); break; } case clang::CastKind::CK_NoOp: { @@ -2358,6 +2386,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { PushParen paren(*this); Convert(sub_expr); ConvertCast(type); + SetFreshType(type); } else { { PushParen paren(*this, suffix); @@ -2365,6 +2394,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { } if (suffix) { StrCat(suffix); + SetFreshType(type); } } break; @@ -2424,6 +2454,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { ConvertCast(type); } } + SetFreshType(type); } return false; } @@ -2714,6 +2745,7 @@ bool Converter::ConvertIncAndDec(clang::UnaryOperator *expr) { bool Converter::VisitUnaryOperator(clang::UnaryOperator *expr) { if (auto str = GetMappedAsString(expr); !str.empty()) { StrCat(str); + SetFreshType(expr->getType()); return false; } @@ -2770,6 +2802,7 @@ bool Converter::VisitUnaryOperator(clang::UnaryOperator *expr) { default: StrCat(expr->getOpcodeStr(opcode)); Convert(sub_expr); + SetFreshType(expr->getType()); } return false; } @@ -2882,6 +2915,9 @@ bool Converter::VisitDeclRefExpr(clang::DeclRefExpr *expr) { ConvertFunctionToFunctionPointer(fn_decl); return false; } + StrCat(str); + SetFreshType(expr->getType()); + return false; } if (auto var_decl = clang::dyn_cast(decl)) { @@ -2891,6 +2927,7 @@ bool Converter::VisitDeclRefExpr(clang::DeclRefExpr *expr) { init->IgnoreUnlessSpelledInSource())) { PushParen paren(*this); VisitLambdaExpr(lambda); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } } @@ -2900,10 +2937,16 @@ bool Converter::VisitDeclRefExpr(clang::DeclRefExpr *expr) { if (!decl->getType()->getAs() && isAddrOf()) { StrCat(token::kRef, decl->getType().isConstQualified() ? "" : keyword_mut_, str); + computed_expr_type_ = ComputedExprType::FreshPointer; return false; } StrCat(str); + if (clang::isa(decl)) { + computed_expr_type_ = ComputedExprType::FreshValue; + return false; + } + SetValueFreshness(expr->getType()); return false; } @@ -2996,6 +3039,7 @@ bool Converter::VisitMemberExpr(clang::MemberExpr *expr) { SetUFCSReceiver(expr->getBase(), expr->isArrow(), method); StrCat(GetRecordName(method->getParent()), token::kDoubleColon, GetMethodName(method)); + SetFreshType(expr->getType()); return false; } std::string str; @@ -3029,10 +3073,16 @@ bool Converter::VisitMemberExpr(clang::MemberExpr *expr) { if (!isAddrOf() && member->getType()->isFunctionPointerType()) { PushParen paren(*this); StrCat(str); + SetValueFreshness(expr->getType()); return false; } StrCat(str); + if (clang::isa(member)) { + SetFreshType(expr->getType()); + } else { + SetValueFreshness(expr->getType()); + } return false; } @@ -3144,6 +3194,7 @@ bool Converter::VisitCXXThisExpr(clang::CXXThisExpr *expr) { PushParen paren(*this); StrCat(keyword::kSelfValue, keyword::kAs, ToString(expr->getType())); } + computed_expr_type_ = ComputedExprType::FreshPointer; return false; } @@ -3169,6 +3220,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) { } else { StrCat(GetArrayDefaultAsString(qual_type)); } + SetFreshType(qual_type); return false; } @@ -3204,6 +3256,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) { } } } + SetFreshType(qual_type); return false; } @@ -3407,6 +3460,9 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { if (auto str = GetMappedAsString(expr, expr->getArgs(), expr->getNumArgs()); !str.empty()) { StrCat(str); + if (!IsPassThroughRule(expr)) { + SetFreshType(expr->getType()); + } return false; } @@ -3428,6 +3484,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { if ((ctor->isCopyConstructor() || IsDefaultedMoveConstructor(ctor)) && !suppress && !TypeIsCopyable(expr->getType())) { StrCat(".clone()"); + SetFreshType(expr->getType()); } return false; } @@ -3435,6 +3492,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { if (ctor->isDefaultConstructor() && !ctor->isUserProvided()) { auto ty = expr->getType(); StrCat(GetDefaultAsString(ty)); + SetFreshType(expr->getType()); return false; } @@ -3444,6 +3502,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { } else { ConvertCXXConstructExprArgs(expr); } + SetFreshType(expr->getType()); return false; } @@ -3541,6 +3600,12 @@ bool Converter::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr) { return false; } +bool Converter::VisitConstantExpr(clang::ConstantExpr *expr) { + Convert(expr->getSubExpr()); + SetFreshType(expr->getType()); + return false; +} + bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) { if (isAddrOf() && expr->capture_size() == 0) { StrCat("Some"); @@ -4477,6 +4542,7 @@ void Converter::ConvertAddrOf(clang::Expr *expr, clang::QualType pointer_type) { : keyword_mut_); Convert(expr); ConvertCast(pointer_type); + computed_expr_type_ = ComputedExprType::FreshPointer; } else { StrCat(token::kRef); if (!pointer_type->getPointeeType().isConstQualified()) { @@ -4484,6 +4550,7 @@ void Converter::ConvertAddrOf(clang::Expr *expr, clang::QualType pointer_type) { } Convert(expr); ConvertCast(pointer_type); + computed_expr_type_ = ComputedExprType::FreshPointer; } } @@ -4495,6 +4562,7 @@ void Converter::EmitDeref(std::string inner, clang::QualType pointee_type) { } PushParen paren(*this); StrCat(GetPointerDerefPrefix(pointee_type), std::move(inner)); + SetValueFreshness(pointee_type); } void Converter::ConvertDeref(clang::Expr *expr) { @@ -4555,8 +4623,8 @@ void Converter::PlaceholderCtx::dump() const { << ", is_cpp_ptr: " << is_cpp_ptr << ", maps_to_rust_ptr: " << maps_to_rust_ptr << ", declared_in_rule_as_rust_ptr: " - << declared_in_rule_as_rust_ptr << ", access: " - << (access == TranslationRule::Access::kRead ? "read" : "write") + << declared_in_rule_as_rust_ptr + << ", access: " << static_cast(access) << ", param_type: " << param_type << ", materialize_idx: " << materialize_idx << '\n'; } @@ -4594,10 +4662,10 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg, if (ph_ctx.needs_object_receiver()) { Buffer buf(*this); PushExplicitAutoref autoref( - *this, - ph_ctx.is_index_base - ? std::optional(ph_ctx.access == TranslationRule::Access::kWrite) - : std::nullopt); + *this, ph_ctx.is_index_base + ? std::optional(ph_ctx.access == + TranslationRule::Access::kBorrowMut) + : std::nullopt); PushExprKind push(*this, ExprKind::RValue); ConvertDeref(arg); return std::move(buf).str(); @@ -4611,13 +4679,17 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg, return ConvertLValue(arg); } - if (ph_ctx.access == TranslationRule::Access::kMove) { + if (ph_ctx.access == TranslationRule::Access::kTake) { if (clang::isa(arg)) { return ConvertRValue(arg); } return std::format("std::mem::take(&mut {})", ConvertLValue(arg)); } + if (ph_ctx.access == TranslationRule::Access::kMove) { + return ConvertFreshRValue(arg, ph_ctx.implicit_convert_to); + } + return ConvertRValue(arg, ph_ctx.implicit_convert_to); } @@ -4774,6 +4846,12 @@ void Converter::SetFresh() { case ComputedExprType::FreshValue: case ComputedExprType::FreshPointer: break; + case ComputedExprType::Unknown: + assert(0 && "Unreachable ComputedExprType::Unknown"); + break; + case ComputedExprType::Pending: + assert(0 && "Unreachable ComputedExprType::Pending"); + break; } } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index a5117fc7b..c4bab0e4e 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -251,7 +251,7 @@ class Converter : public clang::RecursiveASTVisitor { } bool needs_lvalue() const { - return access == TranslationRule::Access::kWrite; + return access == TranslationRule::Access::kBorrowMut; } void dump() const; @@ -416,6 +416,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string EnumeratorName(const clang::EnumConstantDecl *decl) const; virtual bool VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr); + virtual bool VisitConstantExpr(clang::ConstantExpr *expr); virtual bool VisitLambdaExpr(clang::LambdaExpr *expr); @@ -652,6 +653,8 @@ class Converter : public clang::RecursiveASTVisitor { bool RecordDerivesCopy(const clang::RecordDecl *decl) const; + bool IsPassThroughRule(clang::Expr *expr) const; + bool RecordHasCopyableFields(const clang::RecordDecl *decl); bool ShouldReplaceWithMappedBody(clang::DeclRefExpr *expr) const; @@ -951,10 +954,14 @@ class Converter : public clang::RecursiveASTVisitor { FreshValue, Pointer, FreshPointer, + Unknown, + Pending, }; - ComputedExprType computed_expr_type_ = ComputedExprType::FreshValue; + ComputedExprType computed_expr_type_ = ComputedExprType::Unknown; bool isFresh() const { + assert(computed_expr_type_ != ComputedExprType::Unknown); + assert(computed_expr_type_ != ComputedExprType::Pending); return computed_expr_type_ == ComputedExprType::FreshValue || computed_expr_type_ == ComputedExprType::FreshPointer; } diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 4c10e3750..8b6b7a196 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -72,15 +72,18 @@ bool ConverterRefCount::PendingDeref::compute_inner_boxed(clang::Expr *expr) { return false; } -void ConverterRefCount::PendingDeref::set(std::string str, clang::Expr *expr) { +void ConverterRefCount::PendingDeref::set(std::string str, bool fresh, + clang::Expr *expr) { assert_consumed(); - set_unchecked(std::move(str), expr); + set_unchecked(std::move(str), fresh, expr); } -void ConverterRefCount::PendingDeref::set_unchecked(std::string str, +void ConverterRefCount::PendingDeref::set_unchecked(std::string str, bool fresh, clang::Expr *expr) { value = std::move(str); pointee_is_boxed = compute_inner_boxed(expr); + ptr_is_fresh = fresh; + type = ComputedExprType::Pending; } std::string ConverterRefCount::GetInnerType(clang::QualType type) { @@ -409,7 +412,7 @@ bool ConverterRefCount::VisitArraySubscriptExpr( pending_deref_.assert_consumed(); Buffer buf(*this); ConvertArraySubscript(base, expr->getIdx(), expr->getType()); - pending_deref_.set_unchecked(std::move(buf).str(), expr); + pending_deref_.set_unchecked(std::move(buf).str(), isFresh(), expr); return false; } PushParen paren(*this); @@ -808,6 +811,7 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) { clang::Expr *addrof_op = ToAddrOf(ctx_, expr); if (auto str = GetMappedAsString(addrof_op); !str.empty()) { StrCat(str); + SetFreshType(expr->getType()); return false; } } @@ -815,6 +819,7 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) { if (ShouldReplaceWithMappedBody(expr)) { if (auto str = GetMappedAsString(expr); !str.empty()) { StrCat(str); + SetFreshType(expr->getType()); return false; } } @@ -827,12 +832,14 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) { ConvertFunctionToFunctionPointer(fn_decl); } else { StrCat(str); + SetFreshType(expr->getType()); } return false; } if (clang::isa(decl)) { StrCat(str); + computed_expr_type_ = ComputedExprType::FreshValue; return false; } @@ -845,6 +852,7 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) { if (auto *ref = decl_t->getAs()) { if (map_iter_decls_.contains(clang::dyn_cast(decl))) { StrCat(str); + SetValueFreshness(expr->getType()); return false; } @@ -868,7 +876,7 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) { StrCat(str); } else { if (isLValue()) { - pending_deref_.set(str); + pending_deref_.set(str, /*fresh=*/false); return false; } StrCat(DerefPtrExpr(str, ref->getPointeeType())); @@ -1089,7 +1097,7 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { if (ctx && !ctx->temporary_bindings.empty()) { str = std::format("{{ {} {} }}", ctx->temporary_bindings, str); } - pending_deref_.set(str); + pending_deref_.set(str, /*fresh=*/true); return false; } // Apply deref before block wrapping so temporaries are still alive. @@ -1117,6 +1125,9 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { str = std::format("({{ {} {} }})", ctx->temporary_bindings, str); } StrCat(str); + if (IsPassThroughRule(expr)) { + return false; + } if (IsPointerType(ty) || ty->isReferenceType()) { computed_expr_type_ = ComputedExprType::FreshPointer; } else { @@ -1221,6 +1232,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { if (IsStringLiteralExpr(sub_expr)) { StrCat(std::format("Ptr::from_string_literal({})", ToString(sub_expr->IgnoreParens()))); + computed_expr_type_ = ComputedExprType::FreshPointer; return false; } else { // we need to write (var.as_pointer as Ptr) because Rust isn't @@ -1230,6 +1242,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { StrCat(IsReferenceType(sub_expr) ? ConvertObject(sub_expr) : ConvertPointer(sub_expr), keyword::kAs, ToString(expr->getType())); + computed_expr_type_ = ComputedExprType::FreshPointer; return false; } } @@ -1630,7 +1643,7 @@ void ConverterRefCount::ConvertUnionMemberAccessor(clang::MemberExpr *expr) { } if (isLValue()) { - pending_deref_.set(str); + pending_deref_.set(str, /*fresh=*/true); return; } StrCat(DerefPtrExpr(str, member->getType())); @@ -1647,6 +1660,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { SetUFCSReceiver(expr->getBase(), expr->isArrow(), method); StrCat(TraitName(method->getParent()), token::kDoubleColon, GetMethodName(method)); + SetFreshType(expr->getType()); return false; } // User-defined types have Value fields; the struct itself is read-only @@ -1659,6 +1673,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { bool needs_mut = NeedsMutAccess(method, base_type); PushExprKind push(*this, needs_mut ? ExprKind::LValue : ExprKind::RValue); Converter::ConvertMemberExpr(expr); + SetFreshType(expr->getType()); return false; } @@ -1692,7 +1707,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { if (member->getType()->isReferenceType()) { if (isLValue()) { - pending_deref_.set(str); + pending_deref_.set(str, /*fresh=*/false); return false; } StrCat(DerefPtrExpr(str, member->getType().getNonReferenceType())); @@ -1820,10 +1835,11 @@ bool ConverterRefCount::VisitCXXForRangeStmtVector( } StrCat(token::kSemiColon); } else { - EmitByValueShadow(loop_var_name, loop_var->getType(), - loop_var_name + - GetPointerDerefSuffix(loop_var->getType()) + - ".clone()"); + auto type = loop_var->getType(); + bool copy = type.isPODType(ctx_) && !type->isRecordType(); + EmitByValueShadow(loop_var_name, type, + loop_var_name + GetPointerDerefSuffix(type) + + (copy ? "" : ".clone()")); } ConvertForRangeBody(stmt); @@ -1880,7 +1896,9 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { computed_expr_type_ = ComputedExprType::FreshPointer; } else { StrCat(str); - computed_expr_type_ = ComputedExprType::FreshValue; + if (!IsPassThroughRule(expr)) { + computed_expr_type_ = ComputedExprType::FreshValue; + } } return false; } @@ -2110,6 +2128,7 @@ void ConverterRefCount::EmitSetOrAssign(clang::Expr *lhs, } else { StrCat(lhs_str, token::kAssign, rhs); } + computed_expr_type_ = ComputedExprType::FreshValue; } void ConverterRefCount::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, @@ -2129,17 +2148,19 @@ void ConverterRefCount::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, } else { auto lhs_str = ConvertLValue(lhs); if (!pending_deref_.empty()) { + bool fresh = pending_deref_.is_fresh(); auto ptr = pending_deref_.take(); auto op = assign_operator; op.remove_suffix(1); // remove '=' { PushBrace brace(*this); - StrCat(std::format("let _ptr = {}.clone();", ptr)); + StrCat(std::format("let _ptr = {}{};", ptr, fresh ? "" : ".clone()")); StrCat(std::format("_ptr.write(_ptr.read() {} {})", op, rhs_as_string)); } } else { StrCat(lhs_str, assign_operator, rhs_as_string); } + computed_expr_type_ = ComputedExprType::FreshValue; } if (isRValue()) { @@ -2220,7 +2241,8 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr( } if (isLValue()) { - pending_deref_.set(ToString(expr->getArg(0))); + auto ptr = ToString(expr->getArg(0)); + pending_deref_.set(std::move(ptr), isFresh()); break; } @@ -2273,7 +2295,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr( ConvertObject(expr->getArg(0)), ConvertPtrType(expr->getArg(0)->getType()), ConvertSubscriptIndex(expr->getArg(1))), - expr); + /*fresh=*/true, expr); break; } @@ -2394,7 +2416,7 @@ void ConverterRefCount::ConvertPointerSubscript( pending_deref_.assert_consumed(); Buffer buf(*this); ConvertPointerOffset(base, idx); - pending_deref_.set_unchecked(std::move(buf).str(), expr); + pending_deref_.set_unchecked(std::move(buf).str(), isFresh(), expr); return; } @@ -2442,7 +2464,8 @@ void ConverterRefCount::ConvertDeref(clang::Expr *expr) { auto pointee_type = expr->getType()->getPointeeType(); if (isLValue()) { - pending_deref_.set(ToString(expr)); + auto ptr = ToString(expr); + pending_deref_.set(std::move(ptr), isFresh()); return; } @@ -2566,7 +2589,8 @@ std::string ConverterRefCount::ConvertMappedMethodCall( clang::Expr *expr, const TranslationRule::MethodCallFragment &mc, clang::Expr **args, unsigned num_args, TempMaterializationCtx *ctx) { auto receiver_ph = mc.getReceiverPlaceholder(); - if (!receiver_ph || receiver_ph->access == TranslationRule::Access::kRead) { + if (!receiver_ph || receiver_ph->access == TranslationRule::Access::kBorrow || + receiver_ph->access == TranslationRule::Access::kMove) { return Converter::ConvertMappedMethodCall(expr, mc, args, num_args, ctx); } @@ -2595,6 +2619,7 @@ std::string ConverterRefCount::ConvertMappedMethodCall( bool is_boxed = pending_deref_.is_boxed(); auto ptr = pending_deref_.take(); auto body = ConvertIRFragment(mc.body, expr, args, num_args, ctx); + SetFreshType(expr->getType()); if (is_boxed) { return std::format( diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 818e06c94..f588f6d11 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -177,7 +177,11 @@ class ConverterRefCount final : public Converter { bool Convert(clang::Expr *expr, std::optional implicit_convert_to = {}) override { - return Converter::Convert(expr, implicit_convert_to); + auto result = Converter::Convert(expr, implicit_convert_to); + if (computed_expr_type_ == ComputedExprType::Pending) { + assert(!pending_deref_.empty() && "pending_deref_ taken without type"); + } + return result; } bool Convert(clang::Stmt *stmt) override { auto result = Converter::Convert(stmt); @@ -353,24 +357,30 @@ class ConverterRefCount final : public Converter { // emit ptr.write(rhs), or by ConvertMappedMethodCall to emit // ptr.with_mut(...). struct PendingDeref { - void set(std::string str, clang::Expr *expr = nullptr); - void set_unchecked(std::string str, clang::Expr *expr = nullptr); + explicit PendingDeref(ComputedExprType &type) : type(type) {} + void set(std::string str, bool fresh, clang::Expr *expr = nullptr); + void set_unchecked(std::string str, bool fresh, + clang::Expr *expr = nullptr); std::string take() { auto result = std::move(value); value.clear(); pointee_is_boxed = false; + ptr_is_fresh = false; return result; } bool empty() const { return value.empty(); } bool is_boxed() const { return pointee_is_boxed; } + bool is_fresh() const { return ptr_is_fresh; } void assert_consumed() const { assert(value.empty() && "pending_deref_ not consumed"); } private: static bool compute_inner_boxed(clang::Expr *expr); + ComputedExprType &type; std::string value; bool pointee_is_boxed = false; - } pending_deref_; + bool ptr_is_fresh = false; + } pending_deref_{computed_expr_type_}; }; } // namespace cpp2rust diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 4536dee27..8746c60cd 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -35,16 +35,18 @@ TypeInfo ParseTypeInfoJSON(const llvm::json::Object &obj) { } Access ParseAccessJSON(llvm::StringRef value) { - if (value == "read") { - return Access::kRead; - } else if (value == "write") { - return Access::kWrite; + if (value == "borrow") { + return Access::kBorrow; + } else if (value == "borrow_mut") { + return Access::kBorrowMut; } else if (value == "move") { return Access::kMove; + } else if (value == "take") { + return Access::kTake; } else { llvm::errs() << "Invalid access value: " << value << '\n'; assert(0); - return Access::kRead; + return Access::kBorrow; } } @@ -247,15 +249,18 @@ void VaArgsFragment::dump() const { log() << " va_args\n"; } void PlaceholderFragment::dump() const { log() << " placeholder: " << n; switch (access) { - case Access::kRead: - log() << " (read)\n"; + case Access::kBorrow: + log() << " (borrow)\n"; break; - case Access::kWrite: - log() << " (write)\n"; + case Access::kBorrowMut: + log() << " (borrow_mut)\n"; break; case Access::kMove: log() << " (move)\n"; break; + case Access::kTake: + log() << " (take)\n"; + break; } } diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index dc07c4ef1..ad9d7450d 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -23,7 +23,7 @@ struct TextFragment { void dump() const; }; -enum class Access : int8_t { kRead, kWrite, kMove }; +enum class Access : int8_t { kBorrow, kBorrowMut, kMove, kTake }; struct PlaceholderFragment { unsigned n; // "a0", "a1", ... diff --git a/rule-preprocessor/src/ir.rs b/rule-preprocessor/src/ir.rs index e9b353c3b..279a22aa5 100644 --- a/rule-preprocessor/src/ir.rs +++ b/rule-preprocessor/src/ir.rs @@ -143,11 +143,12 @@ pub enum BodyFragment { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "snake_case")] pub enum Access { - Read, - Write, + Borrow, + BorrowMut, Move, + Take, Unknown, } diff --git a/rule-preprocessor/src/semantic.rs b/rule-preprocessor/src/semantic.rs index 4e8b2dd80..3ab2d4d59 100644 --- a/rule-preprocessor/src/semantic.rs +++ b/rule-preprocessor/src/semantic.rs @@ -193,7 +193,21 @@ impl<'tcx> FnDecl<'tcx> { fn_ir, visited: HashMap::new(), }; - visitor.visit_expr(self.body.value, Access::Read); + if let rustc_hir::ExprKind::Block(block, _) = &self.body.value.kind + && block.stmts.is_empty() + && let Some(e) = block.expr + && let Some(param) = visitor.expr_as_decl_ref(e) + { + visitor + .fn_ir + .resolve_next_param(¶m, &mut visitor.visited, |p| { + if p.access == Access::Unknown { + p.access = Access::Borrow; + } + }); + return; + } + visitor.visit_expr(self.body.value, Access::Borrow); } } @@ -290,6 +304,21 @@ fn decl_source_file( ) } +fn is_copy<'tcx>(tcx: rustc_middle::ty::TyCtxt<'tcx>, ty: rustc_middle::ty::Ty<'tcx>) -> bool { + use rustc_infer::infer::TyCtxtInferExt; + use rustc_trait_selection::infer::InferCtxtExt; + + let Some(copy_trait) = tcx.lang_items().copy_trait() else { + return false; + }; + let infcx = tcx + .infer_ctxt() + .build(rustc_middle::ty::TypingMode::non_body_analysis()); + infcx + .type_implements_trait(copy_trait, [ty], rustc_middle::ty::ParamEnv::empty()) + .must_apply_modulo_regions() +} + fn type_derives<'tcx>( tcx: rustc_middle::ty::TyCtxt<'tcx>, ty: rustc_middle::ty::Ty<'tcx>, @@ -353,10 +382,15 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>, context: Access) { // Reached an argument used inside the rule body if let Some(param) = self.expr_as_decl_ref(expr) { + let access = if context == Access::Borrow && self.is_moved(expr) { + Access::Move + } else { + context + }; self.fn_ir .resolve_next_param(¶m, &mut self.visited, |p| { if p.access == Access::Unknown { - p.access = context; + p.access = access; } }); return; @@ -370,18 +404,18 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { param_access.first().copied().unwrap_or(Access::Unknown), ); for (i, arg) in args.iter().enumerate() { - let access = param_access.get(i + 1).copied().unwrap_or(Access::Read); + let access = param_access.get(i + 1).copied().unwrap_or(Access::Borrow); self.visit_expr(arg, access); } } rustc_hir::ExprKind::Call(callee, args) => { if self.is_std_mem_take(expr) && args.len() == 1 { - self.visit_expr(&args[0], Access::Move); + self.visit_expr(&args[0], Access::Take); } else { self.visit_expr(callee, context); let param_access = self.resolve_callee_param_access(expr); for (i, arg) in args.iter().enumerate() { - let access = param_access.get(i).copied().unwrap_or(Access::Read); + let access = param_access.get(i).copied().unwrap_or(Access::Borrow); self.visit_expr(arg, access); } } @@ -389,22 +423,31 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { rustc_hir::ExprKind::Assign(lhs, rhs, _) | rustc_hir::ExprKind::AssignOp(_, lhs, rhs) => { - self.visit_expr(lhs, Access::Write); - self.visit_expr(rhs, Access::Read); + self.visit_expr(lhs, Access::BorrowMut); + self.visit_expr(rhs, Access::Borrow); } rustc_hir::ExprKind::AddrOf(_, rustc_hir::Mutability::Mut, inner) => { self.visit_expr( inner, - if context == Access::Move { - Access::Move + if context == Access::Take { + Access::Take } else { - Access::Write + Access::BorrowMut }, ); } rustc_hir::ExprKind::AddrOf(_, rustc_hir::Mutability::Not, inner) => { - self.visit_expr(inner, Access::Read); + if let Some(param) = self.expr_as_decl_ref(inner) { + self.fn_ir + .resolve_next_param(¶m, &mut self.visited, |p| { + if p.access == Access::Unknown { + p.access = Access::Borrow; + } + }); + return; + } + self.visit_expr(inner, Access::Borrow); } rustc_hir::ExprKind::Block(block, _) | rustc_hir::ExprKind::Loop(block, _, _, _) => { @@ -412,11 +455,11 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { match &stmt.kind { rustc_hir::StmtKind::Let(local) => { if let Some(init) = local.init { - self.visit_expr(init, Access::Read); + self.visit_expr(init, Access::Borrow); } } rustc_hir::StmtKind::Expr(e) | rustc_hir::StmtKind::Semi(e) => { - self.visit_expr(e, Access::Read); + self.visit_expr(e, Access::Borrow); } _ => {} } @@ -427,22 +470,36 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { } rustc_hir::ExprKind::If(cond, then_branch, else_branch) => { - self.visit_expr(cond, Access::Read); + self.visit_expr(cond, Access::Borrow); self.visit_expr(then_branch, context); if let Some(e) = else_branch { self.visit_expr(e, context); } } rustc_hir::ExprKind::Match(scrutinee, arms, _) => { - self.visit_expr(scrutinee, Access::Read); + self.visit_expr(scrutinee, Access::Borrow); for arm in arms.iter() { + if let Some(guard) = arm.guard { + self.visit_expr(guard, Access::Borrow); + } self.visit_expr(arm.body, context); } } + rustc_hir::ExprKind::Field(base, _) => { + if let Some(param) = self.expr_as_decl_ref(base) { + self.fn_ir + .resolve_next_param(¶m, &mut self.visited, |p| { + if p.access == Access::Unknown { + p.access = context; + } + }); + return; + } + self.visit_expr(base, context); + } rustc_hir::ExprKind::Unary(_, e) | rustc_hir::ExprKind::Cast(e, _) - | rustc_hir::ExprKind::Field(e, _) | rustc_hir::ExprKind::DropTemps(e) | rustc_hir::ExprKind::Repeat(e, _) => { self.visit_expr(e, context); @@ -480,7 +537,7 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { | rustc_hir::ExprKind::Continue(_) => {} rustc_hir::ExprKind::Ret(Some(e)) | rustc_hir::ExprKind::Break(_, Some(e)) => { - self.visit_expr(e, Access::Read); + self.visit_expr(e, Access::Borrow); } other => { @@ -494,6 +551,15 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { } } + fn is_moved(&self, expr: &rustc_hir::Expr<'tcx>) -> bool { + let results = self.tcx.typeck(expr.hir_id.owner); + let borrowed = results + .expr_adjustments(expr) + .iter() + .any(|adj| matches!(adj.kind, rustc_middle::ty::adjustment::Adjust::Borrow(_))); + !borrowed && !is_copy(self.tcx, results.expr_ty(expr)) + } + fn expr_as_decl_ref(&self, expr: &rustc_hir::Expr<'_>) -> Option { if let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = &expr.kind && let Some(seg) = path.segments.last() @@ -548,11 +614,19 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { fn access_for_type(ty: &rustc_middle::ty::Ty<'_>) -> Access { match ty.kind() { - rustc_middle::ty::TyKind::Ref(_, _, rustc_middle::ty::Mutability::Mut) => Access::Write, - rustc_middle::ty::TyKind::Ref(_, _, rustc_middle::ty::Mutability::Not) => Access::Read, - rustc_middle::ty::TyKind::RawPtr(_, rustc_middle::ty::Mutability::Mut) => Access::Write, - rustc_middle::ty::TyKind::RawPtr(_, rustc_middle::ty::Mutability::Not) => Access::Read, - _ => Access::Read, + rustc_middle::ty::TyKind::Ref(_, _, rustc_middle::ty::Mutability::Mut) => { + Access::BorrowMut + } + rustc_middle::ty::TyKind::Ref(_, _, rustc_middle::ty::Mutability::Not) => { + Access::Borrow + } + rustc_middle::ty::TyKind::RawPtr(_, rustc_middle::ty::Mutability::Mut) => { + Access::BorrowMut + } + rustc_middle::ty::TyKind::RawPtr(_, rustc_middle::ty::Mutability::Not) => { + Access::Borrow + } + _ => Access::Borrow, } } } diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 266613a0c..79b3796ea 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -405,15 +405,15 @@ impl<'a> FnIrBuilder<'a> { && lhs.syntax().text_range().end() == name_ref.syntax().text_range().end() { - return Some(Access::Write); + return Some(Access::BorrowMut); } - Some(Access::Read) + Some(Access::Unknown) }, ast::RefExpr(ref_expr) => { if ref_expr.mut_token().is_some() { - Some(Access::Write) + Some(Access::BorrowMut) } else { - Some(Access::Read) + Some(Access::Borrow) } }, ast::MethodCallExpr(call) => { @@ -435,16 +435,16 @@ impl<'a> FnIrBuilder<'a> { && sl.tail_expr().is_some_and(|tail| tail.syntax().text_range() == name_ref.syntax().text_range()) { - Some(Access::Write) + Some(Access::BorrowMut) } else { - Some(Access::Read) + Some(Access::Unknown) } }, _ => None, } } }) - .unwrap_or(Access::Read) + .unwrap_or(Access::Unknown) } fn is_extern(&self) -> bool { diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 92150fa67..74866b396 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -16,7 +16,7 @@ fn f2 + ByteRepr>( a2: Ptr, ) -> Ptr { let count = a1.get_offset() - a0.get_offset(); - let mut outptr = a2.clone(); + let mut outptr = a2; for value in PtrValueIter::new(&a0, count) { outptr.write(value.into()); outptr += 1; @@ -75,8 +75,8 @@ fn f10(a0: Ptr, a1: Ptr) -> Ptr { if count <= 1 { a1 } else { - let mut write_ptr = a0.clone(); let mut iter = PtrValueIter::new(&a0, count); + let mut write_ptr = a0; let mut last_unique = iter.next().unwrap(); // the first unique value is already in place @@ -94,7 +94,7 @@ fn f10(a0: Ptr, a1: Ptr) -> Ptr { } fn f12(a0: Ptr, a1: Ptr, a2: T1) { - let mut __a0 = a0.clone(); + let mut __a0 = a0; while __a0 != a1 { let v = a2.clone(); __a0.write(v); diff --git a/rules/arpa_inet/tgt_refcount.rs b/rules/arpa_inet/tgt_refcount.rs index 90a0e52e5..a024f3493 100644 --- a/rules/arpa_inet/tgt_refcount.rs +++ b/rules/arpa_inet/tgt_refcount.rs @@ -49,7 +49,7 @@ fn f6(a0: i32, a1: AnyPtr, a2: Ptr, a3: u32) -> Ptr { __sl[..__n].copy_from_slice(__s.as_bytes()); __sl[__n] = 0; }); - a2.clone() + a2 } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index 7b1fd4963..90b46c20f 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -18,5 +18,5 @@ fn f5(a0: Ptr>, a1: &mut Vec) { } fn f7(a0: Ptr>, a1: Vec) { - a0.write(a1.clone()) + a0.write(a1) } diff --git a/rules/builtin/tgt_refcount.rs b/rules/builtin/tgt_refcount.rs index d1dd3570a..d455c11e6 100644 --- a/rules/builtin/tgt_refcount.rs +++ b/rules/builtin/tgt_refcount.rs @@ -26,5 +26,5 @@ fn f13(a0: i64, a1: i64, a2: Ptr) -> bool { fn f14(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr { a0.memcpy(&a1, a2 as usize); - a0.clone() + a0 } diff --git a/rules/cstdlib/tgt_refcount.rs b/rules/cstdlib/tgt_refcount.rs index a965f5b03..534d44721 100644 --- a/rules/cstdlib/tgt_refcount.rs +++ b/rules/cstdlib/tgt_refcount.rs @@ -31,7 +31,7 @@ fn f6(a0: Ptr) -> Ptr { } fn f10(a0: Ptr, a1: Ptr) -> Ptr { - let __resolved = a1.clone(); + let __resolved = a1; match ::std::fs::canonicalize(a0.to_rust_string()) { Ok(__p) => { let mut __bytes = __p.into_os_string().into_encoded_bytes(); diff --git a/rules/cstring/tgt_refcount.rs b/rules/cstring/tgt_refcount.rs index f8974181d..46e2b60ef 100644 --- a/rules/cstring/tgt_refcount.rs +++ b/rules/cstring/tgt_refcount.rs @@ -5,12 +5,12 @@ use libcc2rs::*; fn f1(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr { a0.memcpy(&a1, a2 as usize); - a0.clone() + a0 } fn f2(a0: AnyPtr, a1: u8, a2: usize) -> AnyPtr { a0.memset((a1) as u8, a2 as usize); - a0.clone() + a0 } fn f3(a0: AnyPtr, a1: AnyPtr, a2: usize) -> i32 { @@ -19,11 +19,11 @@ fn f3(a0: AnyPtr, a1: AnyPtr, a2: usize) -> i32 { fn f4(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr { a0.memcpy(&a1, a2 as usize); - a0.clone() + a0 } fn f5(a0: Ptr, a1: i32) -> Ptr { - let __s = a0.clone(); + let __s = a0; let __t = a1 as u8; match __s.to_c_string_iterator().position(|__c| __c == __t) { Some(__i) => __s.offset(__i), @@ -88,7 +88,7 @@ fn f10(a0: AnyPtr, a1: i32, a2: usize) -> AnyPtr { } fn f11(a0: Ptr, a1: i32) -> Ptr { - let __s = a0.clone(); + let __s = a0; let __t = a1 as u8; match __s .to_c_string_iterator() @@ -108,26 +108,26 @@ fn f11(a0: Ptr, a1: i32) -> Ptr { } fn f15(a0: Ptr) -> Ptr { - libcc2rs::strdup_refcount(a0.clone()) + libcc2rs::strdup_refcount(a0) } fn f16(a0: Ptr, a1: Ptr) -> usize { - let __set = a1.clone(); + let __set = a1; a0.to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } fn f17(a0: Ptr, a1: Ptr) -> usize { - let __set = a1.clone(); + let __set = a1; a0.to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } fn f18(a0: Ptr, a1: Ptr) -> Ptr { - let __needle = a1.clone(); - let mut __p = a0.clone(); + let __needle = a1; + let mut __p = a0; loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -144,8 +144,8 @@ fn f18(a0: Ptr, a1: Ptr) -> Ptr { } fn f21(a0: Ptr, a1: Ptr) -> Ptr { - let __s = a0.clone(); - let __set = a1.clone(); + let __s = a0; + let __set = a1; match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -221,7 +221,7 @@ fn f28(a0: i32, a1: Ptr, a2: usize) -> i32 { } fn f6(a0: Ptr, a1: i32) -> Ptr { - let __s = a0.clone(); + let __s = a0; let __t = a1 as u8; match __s.to_c_string_iterator().position(|__c| __c == __t) { Some(__i) => __s.offset(__i), @@ -251,7 +251,7 @@ fn f12(a0: AnyPtr, a1: i32, a2: usize) -> AnyPtr { } fn f13(a0: Ptr, a1: i32) -> Ptr { - let __s = a0.clone(); + let __s = a0; let __t = a1 as u8; match __s .to_c_string_iterator() @@ -271,7 +271,7 @@ fn f13(a0: Ptr, a1: i32) -> Ptr { } fn f14(a0: Ptr, a1: i32) -> Ptr { - let __s = a0.clone(); + let __s = a0; let __t = a1 as u8; match __s .to_c_string_iterator() @@ -291,8 +291,8 @@ fn f14(a0: Ptr, a1: i32) -> Ptr { } fn f19(a0: Ptr, a1: Ptr) -> Ptr { - let __needle = a1.clone(); - let mut __p = a0.clone(); + let __needle = a1; + let mut __p = a0; loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -309,8 +309,8 @@ fn f19(a0: Ptr, a1: Ptr) -> Ptr { } fn f20(a0: Ptr, a1: Ptr) -> Ptr { - let __needle = a1.clone(); - let mut __p = a0.clone(); + let __needle = a1; + let mut __p = a0; loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -327,8 +327,8 @@ fn f20(a0: Ptr, a1: Ptr) -> Ptr { } fn f22(a0: Ptr, a1: Ptr) -> Ptr { - let __s = a0.clone(); - let __set = a1.clone(); + let __s = a0; + let __set = a1; match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -339,8 +339,8 @@ fn f22(a0: Ptr, a1: Ptr) -> Ptr { } fn f23(a0: Ptr, a1: Ptr) -> Ptr { - let __s = a0.clone(); - let __set = a1.clone(); + let __s = a0; + let __set = a1; match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) diff --git a/rules/deque/tgt_refcount.rs b/rules/deque/tgt_refcount.rs index d3915854c..8e698e53e 100644 --- a/rules/deque/tgt_refcount.rs +++ b/rules/deque/tgt_refcount.rs @@ -18,7 +18,7 @@ fn f7(a0: Ptr>>>, a1: Value>) { } fn f10(a0: Ptr>, a1: Vec) { - a0.write(a1.clone()) + a0.write(a1) } fn f11(a0: Ptr>, a1: &mut Vec) { diff --git a/rules/functional/tgt_refcount.rs b/rules/functional/tgt_refcount.rs index 49193bcf0..9e8095831 100644 --- a/rules/functional/tgt_refcount.rs +++ b/rules/functional/tgt_refcount.rs @@ -12,9 +12,9 @@ fn f1(a0: Ptr) -> Ptr { } fn f2(a0: Ptr) -> Ptr { - a0.clone() + a0 } fn f3(a0: Ptr) -> Ptr { - a0.clone() + a0 } diff --git a/rules/ifaddrs/tgt_refcount.rs b/rules/ifaddrs/tgt_refcount.rs index 90ddb02ac..4d47c6279 100644 --- a/rules/ifaddrs/tgt_refcount.rs +++ b/rules/ifaddrs/tgt_refcount.rs @@ -8,7 +8,7 @@ fn t1() -> libcc2rs::Ifaddrs { } fn f1(a0: Ptr>) -> i32 { - let __out = a0.clone(); + let __out = a0; match nix::ifaddrs::getifaddrs() { Ok(__ifas) => { let __list: Vec = __ifas.collect(); @@ -29,7 +29,7 @@ fn f1(a0: Ptr>) -> i32 { } fn f2(a0: Ptr) { - let mut __cur = a0.clone(); + let mut __cur = a0; while !__cur.is_null() { let __next = __cur.with(|__i| { let __name = __i.ifa_name.borrow(); diff --git a/rules/map/tgt_refcount.rs b/rules/map/tgt_refcount.rs index c0fba36ab..eae9d3d75 100644 --- a/rules/map/tgt_refcount.rs +++ b/rules/map/tgt_refcount.rs @@ -23,7 +23,7 @@ fn f1( a1: T1, ) -> Ptr { a0.with_mut(|__v: &mut BTreeMap>| { - __v.entry(a1.clone()) + __v.entry(a1) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -59,7 +59,7 @@ fn f8( a1: T1, ) -> Ptr { a0.with_mut(|__v: &mut BTreeMap>| { - __v.entry(a1.clone()) + __v.entry(a1) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -123,7 +123,7 @@ fn f17( } fn f19(a0: RefcountMapIter) -> RefcountMapIter { - a0.clone() + a0 } fn f20(a0: RefcountMapIter) -> Value { diff --git a/rules/netdb/tgt_refcount.rs b/rules/netdb/tgt_refcount.rs index 23e3d541f..488137fbf 100644 --- a/rules/netdb/tgt_refcount.rs +++ b/rules/netdb/tgt_refcount.rs @@ -8,10 +8,10 @@ fn t1() -> libcc2rs::Addrinfo { } fn f1(a0: Ptr, a1: Ptr, a2: Ptr, a3: Ptr>) -> i32 { - let __node = a0.clone(); - let __service = a1.clone(); - let __hints = a2.clone(); - let __out = a3.clone(); + let __node = a0; + let __service = a1; + let __hints = a2; + let __out = a3; let __family = if __hints.is_null() { ::libc::AF_UNSPEC } else { @@ -98,7 +98,7 @@ fn f1(a0: Ptr, a1: Ptr, a2: Ptr, a3: Ptr>) -> i3 } fn f2(a0: Ptr) { - let mut __cur = a0.clone(); + let mut __cur = a0; while !__cur.is_null() { let __next = __cur.with(|__ai| { let __addr = __ai.ai_addr.borrow(); diff --git a/rules/poll/tgt_refcount.rs b/rules/poll/tgt_refcount.rs index f8b37af69..9c47e3739 100644 --- a/rules/poll/tgt_refcount.rs +++ b/rules/poll/tgt_refcount.rs @@ -8,7 +8,7 @@ fn t1() -> libcc2rs::Pollfd { } fn f1(a0: Ptr, a1: u64, a2: i32) -> i32 { - let __p = a0.clone(); + let __p = a0; let __timeout = match nix::poll::PollTimeout::try_from(a2) { Ok(__t) => __t, Err(_) => panic!("poll: unsupported timeout {}", a2), diff --git a/rules/pwd/tgt_refcount.rs b/rules/pwd/tgt_refcount.rs index 6f7dde524..ab0700be9 100644 --- a/rules/pwd/tgt_refcount.rs +++ b/rules/pwd/tgt_refcount.rs @@ -8,10 +8,10 @@ fn t1() -> libcc2rs::Passwd { } fn f2(a0: u32, a1: Ptr, a2: Ptr, a3: usize, a4: Ptr>) -> i32 { - let __pwbuf = a1.clone(); - let __buf = a2.clone(); + let __pwbuf = a1; + let __buf = a2; let __buflen = a3; - let __out = a4.clone(); + let __out = a4; match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw(a0)) { Ok(Some(__u)) => { let __strs: [Vec; 5] = [ diff --git a/rules/select/tgt_refcount.rs b/rules/select/tgt_refcount.rs index 00317292c..2e5c273f5 100644 --- a/rules/select/tgt_refcount.rs +++ b/rules/select/tgt_refcount.rs @@ -24,10 +24,10 @@ fn f5(a0: Ptr) { } fn f1(a0: i32, a1: Ptr, a2: Ptr, a3: Ptr, a4: Ptr) -> i32 { - let __rp = a1.clone(); - let __wp = a2.clone(); - let __ep = a3.clone(); - let __tp = a4.clone(); + let __rp = a1; + let __wp = a2; + let __ep = a3; + let __tp = a4; let __r_fds: Vec = match __rp.is_null() { true => Vec::new(), false => __rp.with(|__s| (0..a0).filter(|&__fd| __s.isset(__fd)).collect()), diff --git a/rules/socket/tgt_refcount.rs b/rules/socket/tgt_refcount.rs index b1d1722c3..29580032b 100644 --- a/rules/socket/tgt_refcount.rs +++ b/rules/socket/tgt_refcount.rs @@ -191,7 +191,7 @@ fn f11(a0: i32, a1: i32, a2: i32, a3: Ptr) -> i32 { }; match nix::sys::socket::socketpair(__family, __ty, __proto, __flags) { Ok((__a, __b)) => { - let __sv = a3.clone(); + let __sv = a3; __sv.write(FdRegistry::register(__a)); __sv.offset(1).write(FdRegistry::register(__b)); 0 diff --git a/rules/stdio/tgt_refcount.rs b/rules/stdio/tgt_refcount.rs index e275508d7..57c8a5a86 100644 --- a/rules/stdio/tgt_refcount.rs +++ b/rules/stdio/tgt_refcount.rs @@ -35,7 +35,7 @@ fn f5(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr) -> usize { let __a0 = a0; let __a1 = a1; let __a2 = a2; - let __a3 = a3.clone(); + let __a3 = a3; libcc2rs::fread_refcount(__a0, __a1, __a2, __a3) } @@ -43,7 +43,7 @@ fn f6(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr) -> usize { let __a0 = a0; let __a1 = a1; let __a2 = a2; - let __a3 = a3.clone(); + let __a3 = a3; libcc2rs::fwrite_refcount(__a0, __a1, __a2, __a3) } @@ -101,7 +101,7 @@ fn f16(a0: Ptr) -> i32 { } fn f17(a0: Ptr, a1: i32, a2: Ptr) -> Ptr { - let __buf = a0.clone(); + let __buf = a0; let __n = a1; if __n <= 0 { Ptr::null() @@ -134,7 +134,7 @@ fn f17(a0: Ptr, a1: i32, a2: Ptr) -> Ptr { } fn f18(a0: Ptr, a1: Ptr, a2: Ptr) -> Ptr { - let __stream = a2.clone(); + let __stream = a2; let __old = __stream.with(|__f| __f.fd); match __old { 0..=2 => {} diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index 3550c267d..a1bdd6113 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -21,7 +21,7 @@ fn f1(a0: Vec, a1: usize, a2: usize) -> Vec { } fn f3(a0: Vec, a1: Ptr) -> Vec { - let mut r = a0.clone(); + let mut r = a0; r.pop(); r.extend(a1.to_c_string_iterator()); r.push(0); @@ -92,7 +92,7 @@ fn f16(a0: Vec, a1: Ptr) -> usize { // TODO: This should modify a0 in place fn f17(a0: Vec, a1: Ptr) -> Vec { - let mut __tmp2 = a0.clone(); + let mut __tmp2 = a0; __tmp2.pop(); __tmp2.extend(a1.to_c_string_iterator()); __tmp2.push(0); @@ -176,7 +176,7 @@ fn f25(a0: &mut Vec) { } fn f27(a0: Vec) -> Vec { - a0.clone() + a0 } fn f28(a0: &mut Vec) -> Vec { @@ -184,7 +184,7 @@ fn f28(a0: &mut Vec) -> Vec { } fn f29(a0: Ptr>, a1: Vec) { - a0.write(a1.clone()) + a0.write(a1) } fn f30(a0: Ptr>, a1: &mut Vec) { diff --git a/rules/time/tgt_refcount.rs b/rules/time/tgt_refcount.rs index 8100f0d35..6d6cfae5f 100644 --- a/rules/time/tgt_refcount.rs +++ b/rules/time/tgt_refcount.rs @@ -49,7 +49,7 @@ fn f2(a0: nix::time::ClockId, a1: Ptr) -> i32 { } fn f4(a0: Ptr<::libc::time_t>, a1: Ptr) -> Ptr { - let __res = a1.clone(); + let __res = a1; match jiff::Timestamp::from_second(a0.read()) { Ok(__ts) => { let __dt = __ts.to_zoned(jiff::tz::TimeZone::UTC); @@ -64,7 +64,7 @@ fn f4(a0: Ptr<::libc::time_t>, a1: Ptr) -> Ptr { } fn f5(a0: Ptr<::libc::time_t>, a1: Ptr) -> Ptr { - let __res = a1.clone(); + let __res = a1; match jiff::Timestamp::from_second(a0.read()) { Ok(__ts) => { let __dt = __ts.to_zoned(jiff::tz::TimeZone::system()); diff --git a/rules/unistd/tgt_refcount.rs b/rules/unistd/tgt_refcount.rs index c4d5c7ec0..faf9608c9 100644 --- a/rules/unistd/tgt_refcount.rs +++ b/rules/unistd/tgt_refcount.rs @@ -49,7 +49,7 @@ fn f4(a0: Ptr) -> i32 { fn f5(a0: Ptr) -> i32 { match nix::unistd::pipe() { Ok((__r, __w)) => { - let __fds = a0.clone(); + let __fds = a0; __fds.write(FdRegistry::register(__r)); __fds.offset(1).write(FdRegistry::register(__w)); 0 diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index f2c9a615c..59165d22c 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -74,11 +74,11 @@ fn f22(a0: Ptr) -> Ptr { } fn f23(a0: Ptr) -> Ptr { - a0.clone() + a0 } fn f24(a0: Ptr) -> Ptr { - a0.clone() + a0 } fn f25(a0: Ptr, a1: usize) -> Ptr { @@ -109,8 +109,10 @@ fn f30(a0: usize) -> Vec>> { .collect::>() } -fn f31(a0: Ptr>>>, a1: Vec) { - a0.with_mut(|__v: &mut Vec>>| __v.push(Rc::new(RefCell::new(a1.clone())))) +fn f31(a0: Ptr>>>, a1: &mut Vec) { + a0.with_mut(|__v: &mut Vec>>| { + __v.push(Rc::new(RefCell::new(std::mem::take(&mut *a1)))) + }) } fn f32(a0: Ptr>>>, a1: usize) { @@ -178,7 +180,7 @@ fn f51(a0: Ptr) -> Ptr { } fn f52(a0: Ptr>>>, a1: Vec) { - a0.with_mut(|__v: &mut Vec>>| __v.push(Rc::new(RefCell::new(a1.clone())))) + a0.with_mut(|__v: &mut Vec>>| __v.push(Rc::new(RefCell::new(a1)))) } fn f53( @@ -209,7 +211,7 @@ fn f57(a0: Ptr) -> Ptr { } fn f58(a0: Ptr>, a1: Vec) { - a0.write(a1.clone()) + a0.write(a1) } fn f60(a0: Ptr>, a1: Ptr) -> Ptr { @@ -259,11 +261,11 @@ fn f81(a0: Ptr) -> Ptr { } fn f82(a0: Ptr) -> Ptr { - a0.clone() + a0 } fn f83(a0: Ptr) -> Ptr { - a0.clone() + a0 } fn f84(a0: Ptr, a1: usize) -> Ptr { @@ -357,5 +359,5 @@ fn f104(a0: Ptr) -> Ptr { } fn f105(a0: Ptr>, a1: Vec) { - a0.write(a1.clone()) + a0.write(a1) } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 542283391..c4277a7d6 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -138,8 +138,8 @@ unsafe fn f30(a0: usize) -> Vec> { .map(|_| >::default()) .collect::>() } -unsafe fn f31(a0: &mut Vec>, a1: Vec) { - a0.push(a1) +unsafe fn f31(a0: &mut Vec>, a1: &mut Vec) { + a0.push(std::mem::take(&mut *a1)) } unsafe fn f32(a0: &mut Vec>, a1: usize) { a0.resize_with(a1 as usize, || >::default()) diff --git a/tests/unit/out/refcount/12_test.rs b/tests/unit/out/refcount/12_test.rs index de352b0c6..ba1b9e409 100644 --- a/tests/unit/out/refcount/12_test.rs +++ b/tests/unit/out/refcount/12_test.rs @@ -15,8 +15,7 @@ fn main_0() -> i32 { __v.push(Rc::new(RefCell::new( (0..(10_usize) as usize) .map(|_| ::default()) - .collect::>() - .clone(), + .collect::>(), ))) }); return 0; diff --git a/tests/unit/out/refcount/auto.rs b/tests/unit/out/refcount/auto.rs index 45d2ce428..f1628708d 100644 --- a/tests/unit/out/refcount/auto.rs +++ b/tests/unit/out/refcount/auto.rs @@ -18,7 +18,7 @@ fn main_0() -> i32 { (*v.borrow_mut()).push(2); let sum: Value = Rc::new(RefCell::new(0)); 'loop_: for mut elem in v.as_pointer() as Ptr { - let elem: Value = Rc::new(RefCell::new(elem.read().clone())); + let elem: Value = Rc::new(RefCell::new(elem.read())); (*sum.borrow_mut()) += (*elem.borrow()); } assert!(((*sum.borrow()) == 3)); diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index 2b8c7c403..c3819e4ea 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -201,8 +201,7 @@ fn main_0() -> i32 { __v.push(Rc::new(RefCell::new( (0..(10_usize) as usize) .map(|_| ::default()) - .collect::>() - .clone(), + .collect::>(), ))) }, ); @@ -335,7 +334,7 @@ fn main_0() -> i32 { let __rhs = (*i.borrow()); (map1.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -353,7 +352,7 @@ fn main_0() -> i32 { assert!( (((map2.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -362,7 +361,7 @@ fn main_0() -> i32 { ); (map2.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -374,7 +373,7 @@ fn main_0() -> i32 { assert!( (((map1.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -384,7 +383,7 @@ fn main_0() -> i32 { assert!( (((map2.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index 245903fcd..c2c67a7c0 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -190,7 +190,7 @@ fn main_0() -> i32 { .borrow()), )); { - let _ptr = ({ bar_2(x1.as_pointer()) }).clone(); + let _ptr = ({ bar_2(x1.as_pointer()) }); _ptr.write(_ptr.read() + 10) }; ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.postfix_inc()); @@ -221,8 +221,7 @@ fn main_0() -> i32 { .v .as_pointer(), ) - }) - .clone(); + }); _ptr.write(_ptr.read() + 10) }; ({ @@ -259,7 +258,7 @@ fn main_0() -> i32 { .with_mut(|__v| __v.postfix_inc()); ({ ptr_1((x1.as_pointer())) }).with_mut(|__v| __v.prefix_inc()); { - let _ptr = ({ ptr_1((x1.as_pointer())) }).clone(); + let _ptr = ({ ptr_1((x1.as_pointer())) }); _ptr.write(_ptr.read() + 1) }; ({ @@ -281,8 +280,7 @@ fn main_0() -> i32 { .v .as_pointer()), ) - }) - .clone(); + }); _ptr.write(_ptr.read() + 1) }; { @@ -294,8 +292,7 @@ fn main_0() -> i32 { .v .as_pointer()), ) - }) - .clone(); + }); _ptr.write(_ptr.read() + 1) }; let ptr1: Value = Rc::new(RefCell::new( diff --git a/tests/unit/out/refcount/compound_assign_ref.rs b/tests/unit/out/refcount/compound_assign_ref.rs index 6b94fc47a..df941a462 100644 --- a/tests/unit/out/refcount/compound_assign_ref.rs +++ b/tests/unit/out/refcount/compound_assign_ref.rs @@ -13,7 +13,7 @@ fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(Vec::new())); (*v.borrow_mut()).push(10); { - let _ptr = (v.as_pointer() as Ptr).clone(); + let _ptr = (v.as_pointer() as Ptr); _ptr.write(_ptr.read() + 5) }; assert!((((v.as_pointer() as Ptr).read()) == 15)); diff --git a/tests/unit/out/refcount/cstring.rs b/tests/unit/out/refcount/cstring.rs index 82bb41958..a76123813 100644 --- a/tests/unit/out/refcount/cstring.rs +++ b/tests/unit/out/refcount/cstring.rs @@ -21,7 +21,7 @@ pub fn test_memcpy_0() { &((src.as_pointer() as Ptr) as Ptr).to_any(), 6_usize as usize, ); - ((dst.as_pointer() as Ptr) as Ptr).to_any().clone() + ((dst.as_pointer() as Ptr) as Ptr).to_any() })); assert!({ let _lhs = (*r.borrow()).clone(); @@ -46,7 +46,7 @@ pub fn test_memset_1() { ((buf.as_pointer() as Ptr) as Ptr) .to_any() .memset((('x' as u8) as i32) as u8, 4_usize as usize); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() })); assert!({ let _lhs = (*r.borrow()).clone(); @@ -107,9 +107,7 @@ pub fn test_memmove_3() { &((buf.as_pointer() as Ptr) as Ptr).to_any(), 4_usize as usize, ); - ((buf.as_pointer() as Ptr).offset((1) as isize) as Ptr) - .to_any() - .clone() + ((buf.as_pointer() as Ptr).offset((1) as isize) as Ptr).to_any() })); assert!({ let _lhs = (*r.borrow()).clone(); @@ -533,7 +531,7 @@ pub fn test_strrchr_9() { ]))); assert!( ({ - let __s = (buf.as_pointer() as Ptr).clone(); + let __s = (buf.as_pointer() as Ptr); let __t = (('a' as u8) as i32) as u8; match __s .to_c_string_iterator() @@ -555,7 +553,7 @@ pub fn test_strrchr_9() { } pub fn test_strdup_10() { let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello").clone(), + Ptr::from_string_literal(b"hello"), ))); assert!(!((*d.borrow()).is_null())); assert!( @@ -604,7 +602,7 @@ pub fn test_strdup_10() { ); libcc2rs::free_refcount(((*d2.borrow()).clone() as Ptr).to_any()); let d3: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - (buf.as_pointer() as Ptr).clone(), + (buf.as_pointer() as Ptr), ))); assert!(!((*d3.borrow()).is_null())); assert!( @@ -628,7 +626,7 @@ pub fn test_strdup_10() { pub fn test_strcspn_11() { assert!( ({ - let __set = Ptr::from_string_literal(b"el").clone(); + let __set = Ptr::from_string_literal(b"el"); Ptr::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -637,7 +635,7 @@ pub fn test_strcspn_11() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __set = Ptr::from_string_literal(b"xyz"); Ptr::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -646,7 +644,7 @@ pub fn test_strcspn_11() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"abc").clone(); + let __set = Ptr::from_string_literal(b"abc"); Ptr::from_string_literal(b"") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -668,7 +666,7 @@ pub fn test_strcspn_11() { pub fn test_strspn_12() { assert!( ({ - let __set = Ptr::from_string_literal(b"hel").clone(); + let __set = Ptr::from_string_literal(b"hel"); Ptr::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -677,7 +675,7 @@ pub fn test_strspn_12() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __set = Ptr::from_string_literal(b"xyz"); Ptr::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -686,7 +684,7 @@ pub fn test_strspn_12() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"a").clone(); + let __set = Ptr::from_string_literal(b"a"); Ptr::from_string_literal(b"aaa") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -708,7 +706,7 @@ pub fn test_strspn_12() { pub fn test_strstr_13() { let h: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __needle = Ptr::from_string_literal(b"world").clone(); + let __needle = Ptr::from_string_literal(b"world"); let mut __p = (*h.borrow()).clone(); loop { let mut __h = __p.to_c_string_iterator(); @@ -731,7 +729,7 @@ pub fn test_strstr_13() { }); assert!( ({ - let __needle = Ptr::from_string_literal(b"xyz").clone(); + let __needle = Ptr::from_string_literal(b"xyz"); let mut __p = (*h.borrow()).clone(); loop { let mut __h = __p.to_c_string_iterator(); @@ -759,8 +757,8 @@ pub fn test_strstr_13() { ]))); assert!( ({ - let __needle = Ptr::from_string_literal(b"ll").clone(); - let mut __p = (buf.as_pointer() as Ptr).clone(); + let __needle = Ptr::from_string_literal(b"ll"); + let mut __p = (buf.as_pointer() as Ptr); loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -781,7 +779,7 @@ pub fn test_strpbrk_14() { let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).clone(); - let __set = Ptr::from_string_literal(b"wo").clone(); + let __set = Ptr::from_string_literal(b"wo"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -798,7 +796,7 @@ pub fn test_strpbrk_14() { assert!( ({ let __s = (*s.borrow()).clone(); - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __set = Ptr::from_string_literal(b"xyz"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -817,8 +815,8 @@ pub fn test_strpbrk_14() { ]))); assert!( ({ - let __s = (buf.as_pointer() as Ptr).clone(); - let __set = Ptr::from_string_literal(b"b").clone(); + let __s = (buf.as_pointer() as Ptr); + let __set = Ptr::from_string_literal(b"b"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) diff --git a/tests/unit/out/refcount/errno.rs b/tests/unit/out/refcount/errno.rs index 2cf9c8bcb..065a2f4d2 100644 --- a/tests/unit/out/refcount/errno.rs +++ b/tests/unit/out/refcount/errno.rs @@ -18,7 +18,7 @@ pub fn test_errno_0() { pub fn test_errno_preserved_across_strdup_1() { libcc2rs::cpp2rust_errno().write(99); let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello").clone(), + Ptr::from_string_literal(b"hello"), ))); assert!((((!((*d.borrow()).is_null())) as i32) != 0)); assert!(((((libcc2rs::cpp2rust_errno().read()) == 99) as i32) != 0)); diff --git a/tests/unit/out/refcount/fcntl.rs b/tests/unit/out/refcount/fcntl.rs index 7b8bf8ad1..b88f7f246 100644 --- a/tests/unit/out/refcount/fcntl.rs +++ b/tests/unit/out/refcount/fcntl.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { assert!( (((match nix::unistd::pipe() { Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); + let __fds = (fds.as_pointer() as Ptr); __fds.write(FdRegistry::register(__r)); __fds.offset(1).write(FdRegistry::register(__w)); 0 diff --git a/tests/unit/out/refcount/fd_io.rs b/tests/unit/out/refcount/fd_io.rs index f12727727..2cc681801 100644 --- a/tests/unit/out/refcount/fd_io.rs +++ b/tests/unit/out/refcount/fd_io.rs @@ -74,7 +74,7 @@ fn main_0() -> i32 { ((buf.as_pointer() as Ptr) as Ptr) .to_any() .memset((0) as u8, ::std::mem::size_of::<[u8; 16]>() as usize); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; assert!( (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index b2c8507c0..4ad312318 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -17,16 +17,15 @@ fn main_0() -> i32 { let v_begin: Value> = Rc::new(RefCell::new((v.as_pointer() as Ptr))); let v_end: Value> = Rc::new(RefCell::new((v.as_pointer() as Ptr).to_end())); let it: Value> = Rc::new(RefCell::new( - (*v_begin.borrow()).clone().offset( + (*v_begin.borrow()).offset( (*v_begin.borrow()) - .clone() .clone() .into_iter() .enumerate() .position(|(index_0, value_0)| { - index_0 < (*v_end.borrow()).clone().get_offset() as usize && value_0.read() == 2 + index_0 < (*v_end.borrow()).get_offset() as usize && value_0.read() == 2 }) - .unwrap_or((*v_end.borrow()).clone().get_offset() as usize) as isize, + .unwrap_or((*v_end.borrow()).get_offset() as usize) as isize, ), )); let v_result_true: Value = Rc::new(RefCell::new( @@ -35,21 +34,21 @@ fn main_0() -> i32 { let m: Value>> = Rc::new(RefCell::new(BTreeMap::new())); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(1.clone()) + __v.entry(1) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) .write(1_f64); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2.clone()) + __v.entry(2) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) .write(2_f64); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(3.clone()) + __v.entry(3) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) diff --git a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs index b809e1870..dc405232d 100644 --- a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs @@ -81,7 +81,7 @@ fn main_0() -> i32 { (('X' as u8) as i32) as u8, ::std::mem::size_of::<[u8; 16]>() as usize, ); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; let n: Value = Rc::new(RefCell::new({ let __a0 = ((buf.as_pointer() as Ptr) as Ptr).to_any(); @@ -128,7 +128,7 @@ fn main_0() -> i32 { (('X' as u8) as i32) as u8, ::std::mem::size_of::<[u8; 16]>() as usize, ); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; let n: Value = Rc::new(RefCell::new( ({ @@ -213,7 +213,7 @@ fn main_0() -> i32 { (('Y' as u8) as i32) as u8, ::std::mem::size_of::<[u8; 10]>() as usize, ); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; let n: Value = Rc::new(RefCell::new({ let __a0 = ((buf.as_pointer() as Ptr) as Ptr).to_any(); @@ -250,7 +250,7 @@ fn main_0() -> i32 { (('Y' as u8) as i32) as u8, ::std::mem::size_of::<[u8; 10]>() as usize, ); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; let n: Value = Rc::new(RefCell::new( ({ diff --git a/tests/unit/out/refcount/foreach.rs b/tests/unit/out/refcount/foreach.rs index 74d3697cb..0a4972280 100644 --- a/tests/unit/out/refcount/foreach.rs +++ b/tests/unit/out/refcount/foreach.rs @@ -21,7 +21,7 @@ fn main_0() -> i32 { } let sum: Value = Rc::new(RefCell::new(0)); 'loop_: for mut x in v.as_pointer() as Ptr { - let x: Value = Rc::new(RefCell::new(x.read().clone())); + let x: Value = Rc::new(RefCell::new(x.read())); (*sum.borrow_mut()) += (*x.borrow()); } assert!(((*sum.borrow()) == 45)); diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index ce6419efa..7649198e2 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -43,7 +43,7 @@ fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(::default())); (*(*s.borrow()).v.borrow_mut()).push(1); 'loop_: for mut e in (*s.borrow()).v.as_pointer() as Ptr { - let e: Value = Rc::new(RefCell::new(e.read().clone())); + let e: Value = Rc::new(RefCell::new(e.read())); (*(*s.borrow()).a.borrow_mut()).postfix_inc(); } return 0; diff --git a/tests/unit/out/refcount/foreach_double.rs b/tests/unit/out/refcount/foreach_double.rs index 7766ac69c..668606662 100644 --- a/tests/unit/out/refcount/foreach_double.rs +++ b/tests/unit/out/refcount/foreach_double.rs @@ -16,9 +16,9 @@ fn main_0() -> i32 { (*v.borrow_mut()).push(3); let square: Value = Rc::new(RefCell::new(0)); 'loop_: for mut e1 in v.as_pointer() as Ptr { - let e1: Value = Rc::new(RefCell::new(e1.read().clone())); + let e1: Value = Rc::new(RefCell::new(e1.read())); 'loop_: for mut e2 in v.as_pointer() as Ptr { - let e2: Value = Rc::new(RefCell::new(e2.read().clone())); + let e2: Value = Rc::new(RefCell::new(e2.read())); (*square.borrow_mut()) += ((*e1.borrow()) * (*e2.borrow())); } } @@ -52,15 +52,21 @@ fn main_0() -> i32 { let m: Value>>> = Rc::new(RefCell::new(Vec::new())); let v1: Value> = Rc::new(RefCell::new(Vec::new())); (m.as_pointer() as Ptr>>>).with_mut(|__v: &mut Vec>>| { - __v.push(Rc::new(RefCell::new((*v1.borrow()).clone()))) + __v.push(Rc::new(RefCell::new(std::mem::take( + &mut (*v1.borrow_mut()), + )))) }); let v2: Value> = Rc::new(RefCell::new(Vec::new())); (m.as_pointer() as Ptr>>>).with_mut(|__v: &mut Vec>>| { - __v.push(Rc::new(RefCell::new((*v2.borrow()).clone()))) + __v.push(Rc::new(RefCell::new(std::mem::take( + &mut (*v2.borrow_mut()), + )))) }); let v3: Value> = Rc::new(RefCell::new(Vec::new())); (m.as_pointer() as Ptr>>>).with_mut(|__v: &mut Vec>>| { - __v.push(Rc::new(RefCell::new((*v3.borrow()).clone()))) + __v.push(Rc::new(RefCell::new(std::mem::take( + &mut (*v3.borrow_mut()), + )))) }); 'loop_: for mut row in m.as_pointer() as Ptr>> { let row: Ptr> = row.upgrade().deref().as_pointer(); diff --git a/tests/unit/out/refcount/foreach_map.rs b/tests/unit/out/refcount/foreach_map.rs index 2fd932604..042cce5cc 100644 --- a/tests/unit/out/refcount/foreach_map.rs +++ b/tests/unit/out/refcount/foreach_map.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < 100) { (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) diff --git a/tests/unit/out/refcount/foreach_mut.rs b/tests/unit/out/refcount/foreach_mut.rs index 09ffe44e3..6418ab6bd 100644 --- a/tests/unit/out/refcount/foreach_mut.rs +++ b/tests/unit/out/refcount/foreach_mut.rs @@ -16,11 +16,11 @@ fn main_0() -> i32 { (*v1.borrow_mut()).push(3); let sum: Value = Rc::new(RefCell::new(0)); 'loop_: for mut x in v1.as_pointer() as Ptr { - let x: Value = Rc::new(RefCell::new(x.read().clone())); + let x: Value = Rc::new(RefCell::new(x.read())); (*sum.borrow_mut()) += (*x.borrow_mut()).prefix_inc(); } 'loop_: for x in v1.as_pointer() as Ptr { - let x: Value = Rc::new(RefCell::new(x.read().clone())); + let x: Value = Rc::new(RefCell::new(x.read())); (*sum.borrow_mut()) += (*x.borrow()); } 'loop_: for mut x in v1.as_pointer() as Ptr { @@ -38,26 +38,26 @@ fn main_0() -> i32 { (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(1_usize))); (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(2_usize))); 'loop_: for mut p in v2.as_pointer() as Ptr> { - let p: Value> = Rc::new(RefCell::new(p.read().clone())); + let p: Value> = Rc::new(RefCell::new(p.read())); { let _ptr = (*p.borrow()).clone(); _ptr.write(_ptr.read() + 5) }; } 'loop_: for p in v2.as_pointer() as Ptr> { - let p: Value> = Rc::new(RefCell::new(p.read().clone())); + let p: Value> = Rc::new(RefCell::new(p.read())); let __rhs = ((*p.borrow()).read()); (*sum.borrow_mut()) += __rhs; } 'loop_: for mut p in v2.as_pointer() as Ptr> { - let p: Value> = Rc::new(RefCell::new(p.read().clone())); + let p: Value> = Rc::new(RefCell::new(p.read())); { let _ptr = (*p.borrow()).clone(); _ptr.write(_ptr.read() + 5) }; } 'loop_: for mut p in v2.as_pointer() as Ptr> { - let p: Value> = Rc::new(RefCell::new(p.read().clone())); + let p: Value> = Rc::new(RefCell::new(p.read())); let __rhs = ((*p.borrow()).read()); (*sum.borrow_mut()) += __rhs; } diff --git a/tests/unit/out/refcount/ifaddrs.rs b/tests/unit/out/refcount/ifaddrs.rs index 20dc87a98..bc4312479 100644 --- a/tests/unit/out/refcount/ifaddrs.rs +++ b/tests/unit/out/refcount/ifaddrs.rs @@ -14,7 +14,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __out = (list.as_pointer()).clone(); + let __out = (list.as_pointer()); match nix::ifaddrs::getifaddrs() { Ok(__ifas) => { let __list: Vec = __ifas.collect(); diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index 2394ba929..cdb55376b 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -241,7 +241,7 @@ fn main_0() -> i32 { __sl[..__n].copy_from_slice(__s.as_bytes()); __sl[__n] = 0; }); - (text.as_pointer() as Ptr).clone() + (text.as_pointer() as Ptr) } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -314,7 +314,7 @@ fn main_0() -> i32 { __sl[..__n].copy_from_slice(__s.as_bytes()); __sl[__n] = 0; }); - (text.as_pointer() as Ptr).clone() + (text.as_pointer() as Ptr) } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -365,7 +365,7 @@ fn main_0() -> i32 { __sl[..__n].copy_from_slice(__s.as_bytes()); __sl[__n] = 0; }); - (text.as_pointer() as Ptr).clone() + (text.as_pointer() as Ptr) } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); diff --git a/tests/unit/out/refcount/iterators.rs b/tests/unit/out/refcount/iterators.rs index 542289110..6ea8c0ce3 100644 --- a/tests/unit/out/refcount/iterators.rs +++ b/tests/unit/out/refcount/iterators.rs @@ -30,7 +30,7 @@ fn main_0() -> i32 { (*v.borrow_mut()).push(Ptr::alloc(2)); (*v.borrow_mut()).push(Ptr::alloc(3)); 'loop_: for mut p in v.as_pointer() as Ptr> { - let p: Value> = Rc::new(RefCell::new(p.read().clone())); + let p: Value> = Rc::new(RefCell::new(p.read())); println!("{}", ((*p.borrow()).read())); } return 0; diff --git a/tests/unit/out/refcount/lseek_ftruncate.rs b/tests/unit/out/refcount/lseek_ftruncate.rs index 5da75c3cf..2547c1c10 100644 --- a/tests/unit/out/refcount/lseek_ftruncate.rs +++ b/tests/unit/out/refcount/lseek_ftruncate.rs @@ -95,7 +95,7 @@ fn main_0() -> i32 { ((buf.as_pointer() as Ptr) as Ptr) .to_any() .memset((0) as u8, ::std::mem::size_of::<[u8; 16]>() as usize); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; assert!( (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { diff --git a/tests/unit/out/refcount/map-reallocation.rs b/tests/unit/out/refcount/map-reallocation.rs index 72572fd3a..b2649021e 100644 --- a/tests/unit/out/refcount/map-reallocation.rs +++ b/tests/unit/out/refcount/map-reallocation.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { let __rhs = (*sentinel.borrow()); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*sentinel.borrow()).clone()) + __v.entry((*sentinel.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -43,7 +43,7 @@ fn main_0() -> i32 { let __rhs = (*i.borrow()); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -55,7 +55,7 @@ fn main_0() -> i32 { let __rhs = (*i.borrow()); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*i.borrow()).clone()) + __v.entry((*i.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -85,7 +85,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry((*sentinel.borrow()).clone()) + __v.entry((*sentinel.borrow())) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 77707d781..5bf2841c8 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -22,21 +22,21 @@ fn main_0() -> i32 { let m: Value>> = Rc::new(RefCell::new(BTreeMap::new())); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) .write(1_u32); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(1_i16.clone()) + __v.entry(1_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) .write(2_u32); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -45,7 +45,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -55,7 +55,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(1_i16.clone()) + __v.entry(1_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -65,7 +65,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -75,7 +75,7 @@ fn main_0() -> i32 { let x: Value = Rc::new(RefCell::new(4)); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(1_i16.clone()) + __v.entry(1_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -84,7 +84,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -94,7 +94,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(1_i16.clone()) + __v.entry(1_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -104,7 +104,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -115,7 +115,7 @@ fn main_0() -> i32 { foo_0( ((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -125,7 +125,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -135,7 +135,7 @@ fn main_0() -> i32 { ({ bar_1((m.as_pointer() as Ptr>>).with_mut( |__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }, @@ -144,7 +144,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -153,7 +153,7 @@ fn main_0() -> i32 { ); let __rhs = ((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -161,7 +161,7 @@ fn main_0() -> i32 { .wrapping_add( ((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(2_i16.clone()) + __v.entry(2_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -169,7 +169,7 @@ fn main_0() -> i32 { ); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -177,7 +177,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0_i16.clone()) + __v.entry(0_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -192,8 +192,7 @@ fn main_0() -> i32 { &1_i16, ))); let const_it: Value> = Rc::new(RefCell::new( - RefcountMapIter::find_key((m.as_pointer() as Ptr>>), &10_i16) - .clone(), + RefcountMapIter::find_key((m.as_pointer() as Ptr>>), &10_i16), )); let x1: Value = Rc::new(RefCell::new(if (*it.borrow()) == (*end.borrow()) { 0_u32 @@ -201,13 +200,11 @@ fn main_0() -> i32 { (*(*it.borrow()).second().borrow()) })); assert!(((*x1.borrow()) == 4_u32)); - let x2: Value = Rc::new(RefCell::new( - if (*const_it.borrow()) == (*end.borrow()).clone() { - 0_u32 - } else { - (*(*const_it.borrow()).second().borrow()) - }, - )); + let x2: Value = Rc::new(RefCell::new(if (*const_it.borrow()) == (*end.borrow()) { + 0_u32 + } else { + (*(*const_it.borrow()).second().borrow()) + })); assert!(((*x2.borrow()) == 0_u32)); let x3: Value = Rc::new(RefCell::new( if (*it.borrow()) @@ -221,7 +218,7 @@ fn main_0() -> i32 { assert!(((*x3.borrow()) == 4_u32)); let x4: Value = Rc::new(RefCell::new( if (*const_it.borrow()) - == RefcountMapIter::end((m.as_pointer() as Ptr>>)).clone() + == RefcountMapIter::end((m.as_pointer() as Ptr>>)) { 0_u32 } else { @@ -231,7 +228,7 @@ fn main_0() -> i32 { assert!(((*x4.borrow()) == 0_u32)); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(4_i16.clone()) + __v.entry(4_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -245,7 +242,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(4_i16.clone()) + __v.entry(4_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -259,7 +256,7 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(4_i16.clone()) + __v.entry(4_i16) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -372,8 +369,7 @@ fn main_0() -> i32 { __v.entry( ((indexes.as_pointer() as Ptr) .offset(((*i.borrow()) as usize)) - .read()) - .clone(), + .read()), ) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() diff --git a/tests/unit/out/refcount/memcpy_overlap.rs b/tests/unit/out/refcount/memcpy_overlap.rs index 821853c50..e10a5708f 100644 --- a/tests/unit/out/refcount/memcpy_overlap.rs +++ b/tests/unit/out/refcount/memcpy_overlap.rs @@ -19,9 +19,7 @@ fn main_0() -> i32 { &((buf.as_pointer() as Ptr) as Ptr).to_any(), 4_usize as usize, ); - ((buf.as_pointer() as Ptr).offset((2) as isize) as Ptr) - .to_any() - .clone() + ((buf.as_pointer() as Ptr).offset((2) as isize) as Ptr).to_any() }; assert!((((*buf.borrow())[(0) as usize] as i32) == 1)); assert!((((*buf.borrow())[(1) as usize] as i32) == 2)); diff --git a/tests/unit/out/refcount/memcpy_struct_bytes.rs b/tests/unit/out/refcount/memcpy_struct_bytes.rs index e141580f6..43030c7b2 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.rs @@ -50,7 +50,7 @@ fn main_0() -> i32 { &((src.as_pointer()) as Ptr).to_any(), ::std::mem::size_of::<[u8; 8]>() as usize, ); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; let dst: Value = >::default(); { @@ -58,7 +58,7 @@ fn main_0() -> i32 { &((buf.as_pointer() as Ptr) as Ptr).to_any(), 8usize as usize, ); - ((dst.as_pointer()) as Ptr).to_any().clone() + ((dst.as_pointer()) as Ptr).to_any() }; assert!(((((*(*dst.borrow()).x.borrow()) == 3) as i32) != 0)); assert!(((((*(*dst.borrow()).y.borrow()) == 7) as i32) != 0)); diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 84575f4d6..f5785cf21 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -82,9 +82,7 @@ fn main_0() -> i32 { &(((table.as_pointer() as Ptr).offset(0)) as Ptr).to_any(), (((*table_size.borrow()) as u64).wrapping_mul((4usize as u64)) as usize) as usize, ); - (((table.as_pointer() as Ptr).offset((*table_size.borrow()))) as Ptr) - .to_any() - .clone() + (((table.as_pointer() as Ptr).offset((*table_size.borrow()))) as Ptr).to_any() }; assert!( (((*(*table.borrow())[(4) as usize].bits.borrow()) as i32) == 1) diff --git a/tests/unit/out/refcount/memset.rs b/tests/unit/out/refcount/memset.rs index b36cf8b35..f402c7748 100644 --- a/tests/unit/out/refcount/memset.rs +++ b/tests/unit/out/refcount/memset.rs @@ -21,7 +21,7 @@ fn main_0() -> i32 { (1) as u8, (::std::mem::size_of::() as usize).wrapping_mul(((*N.borrow()) as usize)) as usize, ); - ((*arr.borrow()).clone() as Ptr).to_any().clone() + ((*arr.borrow()).clone() as Ptr).to_any() }; let sum: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(0)); diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs index 8aea22f46..c69604b9f 100644 --- a/tests/unit/out/refcount/netdb.rs +++ b/tests/unit/out/refcount/netdb.rs @@ -20,10 +20,10 @@ pub fn test_ipv4_literal_0() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"127.0.0.1").clone(); - let __service = Ptr::from_string_literal(b"8080").clone(); - let __hints = (hints.as_pointer()).clone(); - let __out = (res.as_pointer()).clone(); + let __node = Ptr::from_string_literal(b"127.0.0.1"); + let __service = Ptr::from_string_literal(b"8080"); + let __hints = (hints.as_pointer()); + let __out = (res.as_pointer()); let __family = if __hints.is_null() { ::libc::AF_UNSPEC } else { @@ -191,10 +191,10 @@ pub fn test_ipv6_literal_1() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"::1").clone(); - let __service = Ptr::from_string_literal(b"443").clone(); - let __hints = (hints.as_pointer()).clone(); - let __out = (res.as_pointer()).clone(); + let __node = Ptr::from_string_literal(b"::1"); + let __service = Ptr::from_string_literal(b"443"); + let __hints = (hints.as_pointer()); + let __out = (res.as_pointer()); let __family = if __hints.is_null() { ::libc::AF_UNSPEC } else { @@ -352,10 +352,10 @@ pub fn test_null_hints_2() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"127.0.0.1").clone(); - let __service = Ptr::from_string_literal(b"80").clone(); - let __hints = Ptr::::null().clone(); - let __out = (res.as_pointer()).clone(); + let __node = Ptr::from_string_literal(b"127.0.0.1"); + let __service = Ptr::from_string_literal(b"80"); + let __hints = Ptr::::null(); + let __out = (res.as_pointer()); let __family = if __hints.is_null() { ::libc::AF_UNSPEC } else { diff --git a/tests/unit/out/refcount/new_alloc_array.rs b/tests/unit/out/refcount/new_alloc_array.rs index 9c3a85496..c4e12b232 100644 --- a/tests/unit/out/refcount/new_alloc_array.rs +++ b/tests/unit/out/refcount/new_alloc_array.rs @@ -20,7 +20,7 @@ fn main_0() -> i32 { (0) as u8, (::std::mem::size_of::() as usize).wrapping_mul(100_usize) as usize, ); - ((*array.borrow()).clone() as Ptr).to_any().clone() + ((*array.borrow()).clone() as Ptr).to_any() }; (*array.borrow()).offset((99) as isize).write(-1_i32); let p1: Value> = Rc::new(RefCell::new((*array.borrow()).clone())); diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 4ac3a136e..e4c54beb9 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -444,24 +444,18 @@ fn main_0() -> i32 { let m: Value>> = Rc::new(RefCell::new(BTreeMap::new())); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry( - Lt { - v: Rc::new(RefCell::new(2)), - } - .clone(), - ) + __v.entry(Lt { + v: Rc::new(RefCell::new(2)), + }) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) .write(20); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry( - Lt { - v: Rc::new(RefCell::new(1)), - } - .clone(), - ) + __v.entry(Lt { + v: Rc::new(RefCell::new(1)), + }) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -475,12 +469,9 @@ fn main_0() -> i32 { assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry( - Lt { - v: Rc::new(RefCell::new(2)), - } - .clone(), - ) + __v.entry(Lt { + v: Rc::new(RefCell::new(2)), + }) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) diff --git a/tests/unit/out/refcount/pipe_io.rs b/tests/unit/out/refcount/pipe_io.rs index 5f51cf011..b46063fb4 100644 --- a/tests/unit/out/refcount/pipe_io.rs +++ b/tests/unit/out/refcount/pipe_io.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { assert!( (((match nix::unistd::pipe() { Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); + let __fds = (fds.as_pointer() as Ptr); __fds.write(FdRegistry::register(__r)); __fds.offset(1).write(FdRegistry::register(__w)); 0 @@ -50,7 +50,7 @@ fn main_0() -> i32 { ((buf.as_pointer() as Ptr) as Ptr) .to_any() .memset((0) as u8, ::std::mem::size_of::<[u8; 4]>() as usize); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() }; assert!( (((match FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { diff --git a/tests/unit/out/refcount/pointers.rs b/tests/unit/out/refcount/pointers.rs index a16dfc198..2fb7aa29b 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/pointers.rs @@ -59,7 +59,7 @@ fn main_0() -> i32 { (*t3.borrow_mut()) = (*t2.borrow()).clone(); (*(*(*t3.borrow()).upgrade().deref()).x.borrow_mut()) = 15; { - let _ptr = ({ TestImpl::as_ptr(&(*t3.borrow())) }).clone(); + let _ptr = ({ TestImpl::as_ptr(&(*t3.borrow())) }); _ptr.write(_ptr.read() + 10) }; assert!( diff --git a/tests/unit/out/refcount/poll.rs b/tests/unit/out/refcount/poll.rs index f996dc137..acf0a506e 100644 --- a/tests/unit/out/refcount/poll.rs +++ b/tests/unit/out/refcount/poll.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { assert!( (((match nix::unistd::pipe() { Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); + let __fds = (fds.as_pointer() as Ptr); __fds.write(FdRegistry::register(__r)); __fds.offset(1).write(FdRegistry::register(__w)); 0 @@ -56,7 +56,7 @@ fn main_0() -> i32 { (*(*pfd.borrow())[(1) as usize].revents.borrow_mut()) = 42_i16; assert!( ((({ - let __p = (pfd.as_pointer() as Ptr).clone(); + let __p = (pfd.as_pointer() as Ptr); let __timeout = match nix::poll::PollTimeout::try_from(0) { Ok(__t) => __t, Err(_) => panic!("poll: unsupported timeout {}", 0), diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index e547adace..2fc46195c 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -106,9 +106,8 @@ impl ByteRepr for JPEGData { } pub fn push_param_0(dest: Ptr>>>) { let dest: Value>>>> = Rc::new(RefCell::new(dest)); - ((*dest.borrow()).to_strong().as_pointer() as Ptr>>>).with_mut( - |__v: &mut Vec>>| __v.push(Rc::new(RefCell::new(Vec::new().clone()))), - ); + ((*dest.borrow()).to_strong().as_pointer() as Ptr>>>) + .with_mut(|__v: &mut Vec>>| __v.push(Rc::new(RefCell::new(Vec::new())))); } pub fn push_local_from_field_1(jpg: Ptr, cond: bool) { let jpg: Value> = Rc::new(RefCell::new(jpg)); @@ -123,18 +122,15 @@ pub fn push_local_from_field_1(jpg: Ptr, cond: bool) { } ((*dest.borrow()).to_strong().as_pointer() as Ptr>>>).with_mut( |__v: &mut Vec>>| { - __v.push(Rc::new(RefCell::new( - { - let __count = (head.as_pointer() as Ptr) - .offset((3) as isize) - .get_offset() - - (head.as_pointer() as Ptr).get_offset(); - PtrValueIter::new(&(head.as_pointer() as Ptr), __count) - .map(|item| u8::try_from(item).ok().unwrap()) - .collect::>() - } - .clone(), - ))) + __v.push(Rc::new(RefCell::new({ + let __count = (head.as_pointer() as Ptr) + .offset((3) as isize) + .get_offset() + - (head.as_pointer() as Ptr).get_offset(); + PtrValueIter::new(&(head.as_pointer() as Ptr), __count) + .map(|item| u8::try_from(item).ok().unwrap()) + .collect::>() + }))) }, ); } diff --git a/tests/unit/out/refcount/pwd.rs b/tests/unit/out/refcount/pwd.rs index 7cd84a262..38af3b897 100644 --- a/tests/unit/out/refcount/pwd.rs +++ b/tests/unit/out/refcount/pwd.rs @@ -64,10 +64,10 @@ pub fn test_getpwuid_r_2() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __pwbuf = (pw.as_pointer()).clone(); - let __buf = (buf.as_pointer() as Ptr).clone(); + let __pwbuf = (pw.as_pointer()); + let __buf = (buf.as_pointer() as Ptr); let __buflen = ::std::mem::size_of::<[u8; 4096]>(); - let __out = (result.as_pointer()).clone(); + let __out = (result.as_pointer()); match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw( nix::unistd::geteuid().as_raw(), )) { @@ -169,10 +169,10 @@ pub fn test_getpwuid_r_erange_3() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __pwbuf = (pw.as_pointer()).clone(); - let __buf = (tiny.as_pointer() as Ptr).clone(); + let __pwbuf = (pw.as_pointer()); + let __buf = (tiny.as_pointer() as Ptr); let __buflen = ::std::mem::size_of::<[u8; 1]>(); - let __out = (result.as_pointer()).clone(); + let __out = (result.as_pointer()); match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw( nix::unistd::geteuid().as_raw(), )) { diff --git a/tests/unit/out/refcount/redundant_copy_in_conversion.rs b/tests/unit/out/refcount/redundant_copy_in_conversion.rs index 28c591b48..ea7213a93 100644 --- a/tests/unit/out/refcount/redundant_copy_in_conversion.rs +++ b/tests/unit/out/refcount/redundant_copy_in_conversion.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub fn sink_0(it: RefcountMapIter) -> i32 { let it: Value> = Rc::new(RefCell::new(it)); let cit: Value> = Rc::new(RefCell::new((*it.borrow()).clone())); - return if (*cit.borrow()) == (*it.borrow()).clone() { + return if (*cit.borrow()) == (*it.borrow()) { (*(*it.borrow()).second().borrow()) } else { 0 @@ -22,7 +22,7 @@ fn main_0() -> i32 { let m: Value>> = Rc::new(RefCell::new(BTreeMap::new())); (m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { - __v.entry(0.clone()) + __v.entry(0) .or_insert_with(|| Rc::new(RefCell::new(::default()))) .as_pointer() }) @@ -35,13 +35,11 @@ fn main_0() -> i32 { &0, ))); let const_it: Value> = Rc::new(RefCell::new((*it0.borrow()).clone())); - let r: Value = Rc::new(RefCell::new( - if (*const_it.borrow()) == (*end.borrow()).clone() { - 0 - } else { - 1 - }, - )); + let r: Value = Rc::new(RefCell::new(if (*const_it.borrow()) == (*end.borrow()) { + 0 + } else { + 1 + })); (*r.borrow_mut()) += ({ sink_0((*it0.borrow()).clone()) }); (*r.borrow_mut()) += if (*end.borrow()) == (*end.borrow()) { 0 diff --git a/tests/unit/out/refcount/reference_wrapper.rs b/tests/unit/out/refcount/reference_wrapper.rs index b04c05926..b6850a53b 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.rs @@ -39,7 +39,7 @@ impl ByteRepr for Point { pub fn set_0(ref_: Ptr, val: i32) { let ref_: Value> = Rc::new(RefCell::new(ref_)); let val: Value = Rc::new(RefCell::new(val)); - (*ref_.borrow()).clone().write((*val.borrow())); + (*ref_.borrow()).write((*val.borrow())); } pub fn read_1(ref_: Ptr) -> i32 { let ref_: Value> = Rc::new(RefCell::new(ref_)); @@ -52,7 +52,7 @@ pub fn main() { fn main_0() -> i32 { let i1: Value = Rc::new(RefCell::new(10)); let ref_1: Value> = Rc::new(RefCell::new(i1.as_pointer())); - (*ref_1.borrow()).clone().write(20); + (*ref_1.borrow()).write(20); let i2: Ptr = (*ref_1.borrow()).clone(); { let _ptr = i2.clone(); @@ -63,8 +63,8 @@ fn main_0() -> i32 { let i4: Value = Rc::new(RefCell::new(2)); let ref_3: Value> = Rc::new(RefCell::new(i3.as_pointer())); let ref_4: Value> = Rc::new(RefCell::new(i4.as_pointer())); - let __rhs = ((*ref_4.borrow()).clone().read()); - (*ref_3.borrow()).clone().write(__rhs); + let __rhs = ((*ref_4.borrow()).read()); + (*ref_3.borrow()).write(__rhs); write!( libcc2rs::cout(), "{:} {:}\n", @@ -83,12 +83,8 @@ fn main_0() -> i32 { y: Rc::new(RefCell::new(4)), })); let point_ref: Value> = Rc::new(RefCell::new(point.as_pointer())); - (*(*(*point_ref.borrow()).clone().upgrade().deref()) - .x - .borrow_mut()) = 30; - (*(*(*point_ref.borrow()).clone().upgrade().deref()) - .y - .borrow_mut()) = 40; + (*(*(*point_ref.borrow()).upgrade().deref()).x.borrow_mut()) = 30; + (*(*(*point_ref.borrow()).upgrade().deref()).y.borrow_mut()) = 40; write!( libcc2rs::cout(), "{:} {:}\n", diff --git a/tests/unit/out/refcount/select.rs b/tests/unit/out/refcount/select.rs index 161fbfcbc..732d95175 100644 --- a/tests/unit/out/refcount/select.rs +++ b/tests/unit/out/refcount/select.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { assert!( (((match nix::unistd::pipe() { Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); + let __fds = (fds.as_pointer() as Ptr); __fds.write(FdRegistry::register(__r)); __fds.offset(1).write(FdRegistry::register(__w)); 0 @@ -36,17 +36,15 @@ fn main_0() -> i32 { ((tv.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 16usize as usize); - ((tv.as_pointer()) as Ptr) - .to_any() - .clone() + ((tv.as_pointer()) as Ptr).to_any() }; (*(*tv.borrow()).tv_sec.borrow_mut()) = 0_i64; assert!( ((({ - let __rp = (rset.as_pointer()).clone(); - let __wp = Ptr::::null().clone(); - let __ep = Ptr::::null().clone(); - let __tp = (tv.as_pointer()).clone(); + let __rp = (rset.as_pointer()); + let __wp = Ptr::::null(); + let __ep = Ptr::::null(); + let __tp = (tv.as_pointer()); let __r_fds: Vec = match __rp.is_null() { true => Vec::new(), false => __rp.with(|__s| { @@ -192,10 +190,10 @@ fn main_0() -> i32 { (*(*tv.borrow()).tv_sec.borrow_mut()) = 1_i64; assert!( ((({ - let __rp = (rset.as_pointer()).clone(); - let __wp = Ptr::::null().clone(); - let __ep = Ptr::::null().clone(); - let __tp = (tv.as_pointer()).clone(); + let __rp = (rset.as_pointer()); + let __wp = Ptr::::null(); + let __ep = Ptr::::null(); + let __tp = (tv.as_pointer()); let __r_fds: Vec = match __rp.is_null() { true => Vec::new(), false => __rp.with(|__s| { diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 9f4fabe23..63e9fea69 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -19,7 +19,7 @@ fn main_0() -> i32 { .offset((3) as isize) .get_offset() - (input.as_pointer() as Ptr).get_offset(); - let mut outptr = (output.as_pointer() as Ptr).clone(); + let mut outptr = (output.as_pointer() as Ptr); for value in PtrValueIter::new(&(input.as_pointer() as Ptr), count) { outptr.write(value.into()); outptr += 1; diff --git a/tests/unit/out/refcount/stdio_nofd.rs b/tests/unit/out/refcount/stdio_nofd.rs index e459d55b7..57753ab75 100644 --- a/tests/unit/out/refcount/stdio_nofd.rs +++ b/tests/unit/out/refcount/stdio_nofd.rs @@ -174,7 +174,7 @@ pub fn test_fgets_getc_2() { )); assert!( (((!(({ - let __buf = (buf.as_pointer() as Ptr).clone(); + let __buf = (buf.as_pointer() as Ptr); let __n = 8; if __n <= 0 { Ptr::null() @@ -218,7 +218,7 @@ pub fn test_fgets_getc_2() { assert!(((((*fp.borrow()).with_mut(|__f| __f.getc()) == ('l' as i32)) as i32) != 0)); assert!( (((!(({ - let __buf = (buf.as_pointer() as Ptr).clone(); + let __buf = (buf.as_pointer() as Ptr); let __n = 4; if __n <= 0 { Ptr::null() @@ -261,7 +261,7 @@ pub fn test_fgets_getc_2() { ); assert!( (((!(({ - let __buf = (buf.as_pointer() as Ptr).clone(); + let __buf = (buf.as_pointer() as Ptr); let __n = 8; if __n <= 0 { Ptr::null() @@ -304,7 +304,7 @@ pub fn test_fgets_getc_2() { ); assert!( (((({ - let __buf = (buf.as_pointer() as Ptr).clone(); + let __buf = (buf.as_pointer() as Ptr); let __n = 8; if __n <= 0 { Ptr::null() diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index 33c1f344e..e20d268b5 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.rs @@ -35,7 +35,7 @@ pub fn main() { } fn main_0() -> i32 { let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello").clone(), + Ptr::from_string_literal(b"hello"), ))); assert!((((!((*d.borrow()).is_null())) as i32) != 0)); assert!( @@ -86,7 +86,7 @@ fn main_0() -> i32 { ); libcc2rs::free_refcount(((*d2.borrow()).clone() as Ptr).to_any()); let d3: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - (buf.as_pointer() as Ptr).clone(), + (buf.as_pointer() as Ptr), ))); assert!((((!((*d3.borrow()).is_null())) as i32) != 0)); assert!( diff --git a/tests/unit/out/refcount/string_h.rs b/tests/unit/out/refcount/string_h.rs index 232e6f233..ca2653f8d 100644 --- a/tests/unit/out/refcount/string_h.rs +++ b/tests/unit/out/refcount/string_h.rs @@ -21,7 +21,7 @@ pub fn test_memcpy_0() { &((src.as_pointer() as Ptr) as Ptr).to_any(), 6_usize as usize, ); - ((dst.as_pointer() as Ptr) as Ptr).to_any().clone() + ((dst.as_pointer() as Ptr) as Ptr).to_any() })); assert!( ((({ @@ -57,7 +57,7 @@ pub fn test_memset_1() { ((buf.as_pointer() as Ptr) as Ptr) .to_any() .memset(('x' as i32) as u8, 4_usize as usize); - ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() + ((buf.as_pointer() as Ptr) as Ptr).to_any() })); assert!( ((({ @@ -130,9 +130,7 @@ pub fn test_memmove_3() { &((buf.as_pointer() as Ptr) as Ptr).to_any(), 4_usize as usize, ); - ((buf.as_pointer() as Ptr).offset((1) as isize) as Ptr) - .to_any() - .clone() + ((buf.as_pointer() as Ptr).offset((1) as isize) as Ptr).to_any() })); assert!( ((({ @@ -163,7 +161,7 @@ pub fn test_memmove_3() { pub fn test_strchr_4() { let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); + let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('w' as i32) as u8; match __s.to_c_string_iterator().position(|__c| __c == __t) { Some(__i) => __s.offset(__i), @@ -180,7 +178,7 @@ pub fn test_strchr_4() { assert!(((((((*r.borrow()).read()) as i32) == ('w' as i32)) as i32) != 0)); assert!( (((({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); + let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('z' as i32) as u8; match __s.to_c_string_iterator().position(|__c| __c == __t) { Some(__i) => __s.offset(__i), @@ -577,7 +575,7 @@ pub fn test_memchr_8() { pub fn test_strrchr_9() { let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); + let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('l' as i32) as u8; match __s .to_c_string_iterator() @@ -606,7 +604,7 @@ pub fn test_strrchr_9() { ); assert!( (((({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); + let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('z' as i32) as u8; match __s .to_c_string_iterator() @@ -635,7 +633,7 @@ pub fn test_strrchr_9() { ]))); assert!( ((({ - let __s = (buf.as_pointer() as Ptr).clone(); + let __s = (buf.as_pointer() as Ptr); let __t = ('a' as i32) as u8; match __s .to_c_string_iterator() @@ -659,7 +657,7 @@ pub fn test_strrchr_9() { pub fn test_strcspn_10() { assert!( ((({ - let __set = Ptr::from_string_literal(b"el").clone(); + let __set = Ptr::from_string_literal(b"el"); Ptr::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -669,7 +667,7 @@ pub fn test_strcspn_10() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __set = Ptr::from_string_literal(b"xyz"); Ptr::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -679,7 +677,7 @@ pub fn test_strcspn_10() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"abc").clone(); + let __set = Ptr::from_string_literal(b"abc"); Ptr::from_string_literal(b"") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -703,7 +701,7 @@ pub fn test_strcspn_10() { pub fn test_strspn_11() { assert!( ((({ - let __set = Ptr::from_string_literal(b"hel").clone(); + let __set = Ptr::from_string_literal(b"hel"); Ptr::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -713,7 +711,7 @@ pub fn test_strspn_11() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __set = Ptr::from_string_literal(b"xyz"); Ptr::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -723,7 +721,7 @@ pub fn test_strspn_11() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"a").clone(); + let __set = Ptr::from_string_literal(b"a"); Ptr::from_string_literal(b"aaa") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) @@ -747,8 +745,8 @@ pub fn test_strspn_11() { pub fn test_strstr_12() { let h: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __needle = Ptr::from_string_literal(b"world").clone(); - let mut __p = (*h.borrow()).reinterpret_cast::().clone(); + let __needle = Ptr::from_string_literal(b"world"); + let mut __p = (*h.borrow()).reinterpret_cast::(); loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -773,8 +771,8 @@ pub fn test_strstr_12() { ); assert!( (((({ - let __needle = Ptr::from_string_literal(b"xyz").clone(); - let mut __p = (*h.borrow()).reinterpret_cast::().clone(); + let __needle = Ptr::from_string_literal(b"xyz"); + let mut __p = (*h.borrow()).reinterpret_cast::(); loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -802,8 +800,8 @@ pub fn test_strstr_12() { ]))); assert!( ((({ - let __needle = Ptr::from_string_literal(b"ll").clone(); - let mut __p = (buf.as_pointer() as Ptr).clone(); + let __needle = Ptr::from_string_literal(b"ll"); + let mut __p = (buf.as_pointer() as Ptr); loop { let mut __h = __p.to_c_string_iterator(); if __needle @@ -824,8 +822,8 @@ pub fn test_strstr_12() { pub fn test_strpbrk_13() { let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); - let __set = Ptr::from_string_literal(b"wo").clone(); + let __s = (*s.borrow()).reinterpret_cast::(); + let __set = Ptr::from_string_literal(b"wo"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -844,8 +842,8 @@ pub fn test_strpbrk_13() { ); assert!( (((({ - let __s = (*s.borrow()).reinterpret_cast::().clone(); - let __set = Ptr::from_string_literal(b"xyz").clone(); + let __s = (*s.borrow()).reinterpret_cast::(); + let __set = Ptr::from_string_literal(b"xyz"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -865,8 +863,8 @@ pub fn test_strpbrk_13() { ]))); assert!( ((({ - let __s = (buf.as_pointer() as Ptr).clone(); - let __set = Ptr::from_string_literal(b"b").clone(); + let __s = (buf.as_pointer() as Ptr); + let __set = Ptr::from_string_literal(b"b"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index a26480fb0..46a0c95a5 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -49,7 +49,7 @@ pub fn print_tm_1(t: i64) { let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ - let __res = (tm.as_pointer()).clone(); + let __res = (tm.as_pointer()); match jiff::Timestamp::from_second((t.as_pointer()).read()) { Ok(__ts) => { let __dt = __ts.to_zoned(jiff::tz::TimeZone::UTC); @@ -97,7 +97,7 @@ pub fn print_local_tm_3(t: i64) { let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ - let __res = (tm.as_pointer()).clone(); + let __res = (tm.as_pointer()); match jiff::Timestamp::from_second((t.as_pointer()).read()) { Ok(__ts) => { let __dt = __ts.to_zoned(jiff::tz::TimeZone::system()); @@ -147,7 +147,7 @@ pub fn test_strftime_5() { let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ - let __res = (tm.as_pointer()).clone(); + let __res = (tm.as_pointer()); match jiff::Timestamp::from_second((t.as_pointer()).read()) { Ok(__ts) => { let __dt = __ts.to_zoned(jiff::tz::TimeZone::UTC); diff --git a/tests/unit/out/refcount/union_addrof_external.rs b/tests/unit/out/refcount/union_addrof_external.rs index 15928f01a..6da731326 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -169,7 +169,7 @@ fn main_0() -> i32 { ((c.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 128usize as usize); - ((c.as_pointer()) as Ptr).to_any().clone() + ((c.as_pointer()) as Ptr).to_any() }; ({ let _out: AnyPtr = ((*c.borrow()).view.as_pointer()).to_any(); diff --git a/tests/unit/out/refcount/union_cross_arm_cast.rs b/tests/unit/out/refcount/union_cross_arm_cast.rs index 70fa8176b..6732aafd1 100644 --- a/tests/unit/out/refcount/union_cross_arm_cast.rs +++ b/tests/unit/out/refcount/union_cross_arm_cast.rs @@ -175,7 +175,7 @@ fn main_0() -> i32 { ((c.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 68usize as usize); - ((c.as_pointer()) as Ptr).to_any().clone() + ((c.as_pointer()) as Ptr).to_any() }; (*(*(*(*c.borrow()).u.borrow()).a().upgrade().deref()) .code diff --git a/tests/unit/out/refcount/union_memset_memcpy.rs b/tests/unit/out/refcount/union_memset_memcpy.rs index fa78907eb..d1c758772 100644 --- a/tests/unit/out/refcount/union_memset_memcpy.rs +++ b/tests/unit/out/refcount/union_memset_memcpy.rs @@ -166,7 +166,7 @@ fn main_0() -> i32 { ((c.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 256usize as usize); - ((c.as_pointer()) as Ptr).to_any().clone() + ((c.as_pointer()) as Ptr).to_any() }; assert!( (((((*(*(*(*c.borrow()).view.borrow()).a().upgrade().deref()) @@ -240,7 +240,6 @@ fn main_0() -> i32 { .raw_() .reinterpret_cast::()) as Ptr) .to_any() - .clone() }; assert!( (((((*(*(*(*c.borrow()).view.borrow()).b().upgrade().deref()) @@ -263,7 +262,7 @@ fn main_0() -> i32 { ((c.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 256usize as usize); - ((c.as_pointer()) as Ptr).to_any().clone() + ((c.as_pointer()) as Ptr).to_any() }; assert!( (((((*(*(*(*c.borrow()).view.borrow()).b().upgrade().deref()) diff --git a/tests/unit/out/refcount/union_nested.rs b/tests/unit/out/refcount/union_nested.rs index 094fc897a..124238a8e 100644 --- a/tests/unit/out/refcount/union_nested.rs +++ b/tests/unit/out/refcount/union_nested.rs @@ -193,7 +193,7 @@ fn main_0() -> i32 { ((ex.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 144usize as usize); - ((ex.as_pointer()) as Ptr).to_any().clone() + ((ex.as_pointer()) as Ptr).to_any() }; (*(*ex.borrow()).kind.borrow_mut()) = 2; (*(*ex.borrow()).level.borrow_mut()) = 1; diff --git a/tests/unit/out/refcount/union_struct_dual_use.rs b/tests/unit/out/refcount/union_struct_dual_use.rs index e80895fae..27a23ef17 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.rs @@ -116,7 +116,7 @@ fn main_0() -> i32 { ((outer.as_pointer()) as Ptr) .to_any() .memset((0) as u8, 16usize as usize); - ((outer.as_pointer()) as Ptr).to_any().clone() + ((outer.as_pointer()) as Ptr).to_any() }; (*(*(*(*outer.borrow()).u.borrow()).inner().upgrade().deref()) .a diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index cc388c6cb..1227c6012 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -38,7 +38,7 @@ fn main_0() -> i32 { (*v2.borrow_mut()).push(3); assert!(((*v2.borrow()).len() == 3_usize)); { - let idx = (v2.as_pointer() as Ptr).clone().get_offset(); + let idx = (v2.as_pointer() as Ptr).get_offset(); (v2.as_pointer() as Ptr>).with_mut(|__v: &mut Vec| __v.remove(idx)); (v2.as_pointer() as Ptr>).to_strong().as_pointer() as Ptr }; @@ -46,9 +46,9 @@ fn main_0() -> i32 { assert!((((v2.as_pointer() as Ptr).offset(0_usize).read()) == 2)); assert!((((v2.as_pointer() as Ptr).offset(1_usize).read()) == 3)); { - let __off = (v2.as_pointer() as Ptr).clone().get_offset(); + let __off = (v2.as_pointer() as Ptr).get_offset(); (*v2.borrow_mut()).insert(__off, 100); - (v2.as_pointer() as Ptr).clone() + (v2.as_pointer() as Ptr) }; ({ copy_0((*v2.borrow()).clone()) }); assert!(((*v2.borrow()).len() == 3_usize)); diff --git a/tests/unit/out/refcount/vector3.rs b/tests/unit/out/refcount/vector3.rs index dccd70df9..66c71b4ba 100644 --- a/tests/unit/out/refcount/vector3.rs +++ b/tests/unit/out/refcount/vector3.rs @@ -63,14 +63,14 @@ fn main_0() -> i32 { 'loop_: for mut v2 in v.as_pointer() as Ptr>> { let v2: Ptr> = v2.upgrade().deref().as_pointer(); 'loop_: for mut i in v2.to_strong().as_pointer() as Ptr { - let i: Value = Rc::new(RefCell::new(i.read().clone())); + let i: Value = Rc::new(RefCell::new(i.read())); println!("{}", ((*i.borrow()) + 3)); } } 'loop_: for mut v2 in v.as_pointer() as Ptr>> { let v2: Value> = Rc::new(RefCell::new(v2.upgrade().deref().borrow().clone())); 'loop_: for mut i in v2.as_pointer() as Ptr { - let i: Value = Rc::new(RefCell::new(i.read().clone())); + let i: Value = Rc::new(RefCell::new(i.read())); println!("{}", (*i.borrow())); } } diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 288910bdf..f217e8bae 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -116,7 +116,7 @@ fn main_0() -> i32 { (*v2.borrow_mut()).push(3); assert!(((*v2.borrow()).len() == 3_usize)); { - let idx = (v2.as_pointer() as Ptr).clone().get_offset(); + let idx = (v2.as_pointer() as Ptr).get_offset(); (v2.as_pointer() as Ptr>).with_mut(|__v: &mut Vec| __v.remove(idx)); (v2.as_pointer() as Ptr>).to_strong().as_pointer() as Ptr }; @@ -124,9 +124,9 @@ fn main_0() -> i32 { assert!((((v2.as_pointer() as Ptr).offset(0_usize).read()) == 2)); assert!((((v2.as_pointer() as Ptr).offset(1_usize).read()) == 3)); { - let __off = (v2.as_pointer() as Ptr).clone().get_offset(); + let __off = (v2.as_pointer() as Ptr).get_offset(); (*v2.borrow_mut()).insert(__off, 100); - (v2.as_pointer() as Ptr).clone() + (v2.as_pointer() as Ptr) }; ({ copy_0((*v2.borrow()).clone()) }); assert!(((*v2.borrow()).len() == 3_usize)); diff --git a/tests/unit/out/refcount/void_return.rs b/tests/unit/out/refcount/void_return.rs index 0cf54c6a0..f1173bb2e 100644 --- a/tests/unit/out/refcount/void_return.rs +++ b/tests/unit/out/refcount/void_return.rs @@ -9,9 +9,7 @@ use std::rc::{Rc, Weak}; pub fn f1_0(first: Ptr, last: Ptr) { let first: Value> = Rc::new(RefCell::new(first)); let last: Value> = Rc::new(RefCell::new(last)); - (*first.borrow()) - .clone() - .sort((*last.borrow()).clone().get_offset()); + (*first.borrow()).sort((*last.borrow()).get_offset()); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/foreach_double.rs b/tests/unit/out/unsafe/foreach_double.rs index 708d9bd82..ed68831bd 100644 --- a/tests/unit/out/unsafe/foreach_double.rs +++ b/tests/unit/out/unsafe/foreach_double.rs @@ -47,11 +47,11 @@ unsafe fn main_0() -> i32 { } let mut m: Vec> = Vec::new(); let mut v1: Vec = Vec::new(); - m.push(v1); + m.push(std::mem::take(&mut v1)); let mut v2: Vec = Vec::new(); - m.push(v2); + m.push(std::mem::take(&mut v2)); let mut v3: Vec = Vec::new(); - m.push(v3); + m.push(std::mem::take(&mut v3)); 'loop_: for row in 0..(m.len()) { let mut row = m.as_mut_ptr().add(row); 'loop_: for col in 0..((*row).len()) { diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index 75a246d40..ce0a42937 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -26,20 +26,18 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { left: (*a).left, right: (*a).right, }; - (*a) = (MinHeapNode { + (*a) = MinHeapNode { data: (*b).data, freq: (*b).freq, left: (*b).left, right: (*b).right, - }) - .clone(); - (*b) = (MinHeapNode { + }; + (*b) = MinHeapNode { data: t.data, freq: t.freq, left: t.left, right: t.right, - }) - .clone(); + }; } #[repr(C)] #[derive(Default)] diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index 36fdf0f03..25c49b6cc 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -96,10 +96,10 @@ unsafe fn main_0() -> i32 { assert!(((other_map.len()) == (0_usize))); let mut key0: (i32, i64) = (1.into(), 1.into()); let mut value: f64 = 2_f64; - (*other_map.entry(key0).or_default().as_mut()) = value; - value = (*other_map.entry(key0).or_default().as_mut()); + (*other_map.entry((key0).clone()).or_default().as_mut()) = value; + value = (*other_map.entry((key0).clone()).or_default().as_mut()); assert!(((other_map.len()) == (1_usize))); - assert!(((*other_map.entry(key0).or_default().as_mut()) == (value))); + assert!(((*other_map.entry((key0).clone()).or_default().as_mut()) == (value))); assert!(((m.len()) == (3_usize))); let mut k: i32 = 0; assert!(((*(m.get(&(k as i16)).expect("out of range!").as_ref() as *const u32)) == (5_u32))); diff --git a/tests/unit/out/unsafe/unistd.rs b/tests/unit/out/unsafe/unistd.rs index 4d15e652d..ef426d0cc 100644 --- a/tests/unit/out/unsafe/unistd.rs +++ b/tests/unit/out/unsafe/unistd.rs @@ -220,7 +220,7 @@ pub unsafe fn test_ftruncate_5() { assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const()); assert!((((!((fp).is_null())) as i32) != 0)); - fd = (libc::fileno(fp)).clone(); + fd = libc::fileno(fp); assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (5_i64)) as i32) != 0)); assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); libc::unlink(path);