diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 72af86963a..4c66e694ed 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -33,7 +33,7 @@ std::unordered_set Converter::decl_ids_; std::unordered_set Converter::globals_; std::vector Converter::global_inits_; Converter::RecordIndex Converter::record_decls_; -std::map Converter::virtual_methods_; +std::map Converter::deferred_impls_; std::map> Converter::declared_record_traits_; std::set> @@ -60,12 +60,56 @@ void Converter::EmitDeferredBlock(const DeferredBlock &block, out += "}\n"; } -void Converter::EmitVirtualMethods(std::string &out) { - for (const auto &[name, impl] : virtual_methods_) { +void Converter::EmitDeferredImpls(std::string &out) { + for (const auto &[header, impl] : deferred_impls_) { EmitDeferredBlock(impl, out); } } +Converter::DeferredBlock &Converter::DeferredImpl(std::string header) { + auto [it, inserted] = deferred_impls_.try_emplace(header); + if (inserted) { + it->second.header = std::move(header); + } + return it->second; +} + +void Converter::AddEqualityComparableMethod(const clang::FunctionDecl *op, + const RecordTrait &trait, + std::string_view method) { + auto *record = GetComparisonRecord(op); + auto name = GetRecordName(record); + clang::QualType lhs = ctx_.getCanonicalTagType(record); + auto rhs = GetComparisonRhsType(op); + if (lhs == rhs) { + EqualityComparableImpl(name, "").body += method; + if (&trait == &kWeaklyEqualityComparableWith) { + converted_record_traits_.emplace(name, trait.refcount.name); + } + return; + } + auto other = GetUnboxedTypeAsString(rhs); + EqualityComparableImpl(name, other).body += method; + if (&trait != &kWeaklyEqualityComparableWith || + HasEqualityOperator(ctx_, rhs, lhs)) { + return; + } + EqualityComparableImpl(other, name).body += + std::format("{} {{ <{} as {}<{}>>::{}(rhs, lhs) }}\n", + GetComparisonTraitSignature(trait, "lhs", "rhs", name), name, + GetRecordTraitSpelling(trait).name, other, trait.method); +} + +Converter::DeferredBlock & +Converter::EqualityComparableImpl(std::string_view self, + std::string_view other) { + const char *name = GetRecordTraitSpelling(kWeaklyEqualityComparableWith).name; + if (other.empty()) { + return DeferredImpl(std::format("impl {} for {}", name, self)); + } + return DeferredImpl(std::format("impl {}<{}> for {}", name, other, self)); +} + void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { bool is_unsafe = model == Model::kUnsafe; for (const auto &[record, traits] : declared_record_traits_) { @@ -74,6 +118,13 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { continue; } const auto &spelling = is_unsafe ? trait->unsafe : trait->refcount; + if (trait == &kWeaklyEqualityComparableWith) { + DeferredImpl(std::format("impl {} for {}", spelling.name, record)) + .body += + std::format("{} {{ unreachable!(\"{}::{} is never defined\") }}\n", + spelling.signature, record, trait->method); + continue; + } out += std::format( "impl {} for {} {{ {} {{ unreachable!(\"{}::{} is never defined\") " "}} }}\n", @@ -85,8 +136,13 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { void Converter::DeclareRecordTraits(const clang::CXXRecordDecl *decl) { auto &traits = declared_record_traits_[GetRecordName(decl)]; for (auto *method : decl->methods()) { - if (auto *trait = GetRecordTrait(method); - trait && !IsDerivedCopyOrMove(method)) { + if (GetComparisonTrait(method)) { + if (IsSameTypeComparison(method, decl)) { + traits.emplace(kWeaklyEqualityComparableWith.refcount.name, + &kWeaklyEqualityComparableWith); + } + } else if (auto *trait = GetRecordTrait(method); + trait && !IsDerivedCopyOrMove(method)) { traits.emplace(trait->refcount.name, trait); } } @@ -489,6 +545,10 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { } DumpVerbose(decl); ScopedValue push_fn(curr_function_, decl); + if (auto *trait = GetComparisonTrait(decl)) { + ConvertComparisonTraitImpl(decl, *trait); + return false; + } std::string function_name; if (decl->isMain()) { // main_0 is private. @@ -512,6 +572,27 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { return false; } +void Converter::ConvertComparisonTraitImpl(clang::FunctionDecl *decl, + const RecordTrait &trait) { + std::string method; + { + Buffer buf(*this); + StrCat(keyword_unsafe_, keyword::kFn, trait.method); + { + PushParen paren(*this); + ConvertFunctionParameters(decl); + } + ConvertFunctionReturnType(decl); + { + PushBrace body(*this); + EmitFunctionPreamble(decl); + ConvertFunctionBody(decl); + } + method = std::move(buf).str(); + } + AddEqualityComparableMethod(decl, trait, method); +} + void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { for (auto *child : body->body()) { if (auto *decl_stmt = clang::dyn_cast(child)) { @@ -1134,6 +1215,10 @@ void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, if (body.empty()) { return; } + if (GetComparisonTrait(method)) { + AddEqualityComparableMethod(method, trait, body); + return; + } converted_record_traits_.emplace(GetRecordName(method->getParent()), trait.refcount.name); StrCat(keyword::kImpl, GetCopyOrMoveTraitName(trait), "for", @@ -2684,7 +2769,7 @@ void Converter::EmitCall(CallInfo &&info) { auto *direct_callee = info.expr->getDirectCallee(); assert(direct_callee); StrCat("libc::", direct_callee->getName()); - } else { + } else if (!EmitComparisonTraitCallee(info)) { PushExprKind push(*this, ExprKind::Callee); Convert(GetCallee(info.expr)); } @@ -2692,6 +2777,19 @@ void Converter::EmitCall(CallInfo &&info) { EmitArgList(info); } +bool Converter::EmitComparisonTraitCallee(const CallInfo &info) { + auto *callee = info.expr->getDirectCallee(); + if (!callee || clang::isa(callee)) { + return false; + } + auto *trait = GetComparisonTrait(callee); + if (!trait) { + return false; + } + StrCat(GetCopyOrMoveTraitName(*trait), token::kDoubleColon, trait->method); + return true; +} + void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) { PushParen outer(*this); StrCat(keyword_unsafe_); @@ -2735,7 +2833,7 @@ void Converter::ConvertUserOperatorCall(clang::CXXOperatorCallExpr *expr) { SetUFCSReceiver(expr->getArg(0), false, method); } StrCat(GetUFCSName(method), token::kDoubleColon, GetMethodName(method)); - } else { + } else if (!EmitComparisonTraitCallee(info)) { StrCat(GetNamedDeclAsString(callee->getCanonicalDecl())); } EmitArgList(info); @@ -5765,14 +5863,10 @@ void Converter::ConvertCXXMethodDecls( Converter::DeferredBlock & Converter::VirtualMethodsFor(const clang::CXXRecordDecl *decl) { - auto name = GetRecordName(decl); - auto [it, inserted] = virtual_methods_.try_emplace(name); - if (inserted) { - it->second.header = std::format( - "{} impl {} for {}", keyword_unsafe_, - GetUnsafeTypeAsString(decl->bases_begin()->getType()), name); - } - return it->second; + return DeferredImpl( + std::format("{} impl {} for {}", keyword_unsafe_, + GetUnsafeTypeAsString(decl->bases_begin()->getType()), + GetRecordName(decl))); } void Converter::ConvertVirtualMethods(clang::CXXRecordDecl *decl) { @@ -5809,20 +5903,21 @@ bool Converter::ConvertOutOfLineVirtualMethod(clang::CXXMethodDecl *decl) { void Converter::ConvertOrdAndPartialOrdTraitsBase( std::string_view cmp_body, std::string_view eq_body, std::string_view record_name) { - if (!cmp_body.empty()) { - StrCat(keyword::kImpl, "std::cmp::Ord for ", record_name, '{'); - StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {"); - StrCat(std::format("{} {{", keyword_unsafe_)); - StrCat(cmp_body); - StrCat("}}}"); - - StrCat(keyword::kImpl, "std::cmp::PartialOrd for", record_name, '{'); - StrCat(R"( + if (cmp_body.empty()) { + return; + } + StrCat(keyword::kImpl, "std::cmp::Ord for ", record_name, '{'); + StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {"); + StrCat(std::format("{} {{", keyword_unsafe_)); + StrCat(cmp_body); + StrCat("}}}"); + + StrCat(keyword::kImpl, "std::cmp::PartialOrd for", record_name, '{'); + StrCat(R"( fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } })"); - } StrCat(keyword::kImpl, "std::cmp::PartialEq for", record_name, '{'); StrCat("fn eq(&self, other: &Self) -> bool {"); @@ -5843,6 +5938,11 @@ std::string Converter::GetComparisonCall(const clang::FunctionDecl *op, GetComparisonReceiver(method, lhs), GetComparisonArg(op->getParamDecl(0), decl, rhs)); } + if (auto *trait = GetComparisonTrait(op)) { + return std::format("{}::{}({}, {})", GetCopyOrMoveTraitName(*trait), + trait->method, lhs, + GetComparisonArg(op->getParamDecl(1), decl, rhs)); + } return std::format("{}({}, {})", GetNamedDeclAsString(op->getCanonicalDecl()), GetComparisonArg(op->getParamDecl(0), decl, lhs), GetComparisonArg(op->getParamDecl(1), decl, rhs)); @@ -5877,12 +5977,16 @@ std::string Converter::GetComparisonBool(const clang::FunctionDecl *op, } std::string Converter::GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *decl, + const clang::CXXRecordDecl *, std::string_view value) { - if (param->getType()->isReferenceType()) { - return std::format("{} as *const {}", value, GetRecordName(decl)); + auto type = param->getType(); + if (!type->isReferenceType()) { + return std::format("(*{}).clone()", value); } - return std::format("{}.clone()", value); + if (type.getNonReferenceType().isConstQualified()) { + return std::string(value); + } + return std::format("{}.cast_mut()", value); } std::string @@ -5890,18 +5994,18 @@ Converter::GetComparisonResultReceiver(const clang::CXXMethodDecl *method, bool returns_ref, std::string_view result) { return GetComparisonReceiver( - method, std::format("{}{}", returns_ref ? "&*" : "&", result)); + method, returns_ref ? std::format("({} as *const _)", result) + : std::format("(&raw const {})", result)); } std::string Converter::GetComparisonReceiver(const clang::CXXMethodDecl *method, std::string_view lhs) { - if (!MethodNeedsMutableReceiver(method)) { - return std::string(lhs); - } + bool is_mut = MethodNeedsMutableReceiver(method); if (!IsMethodOnPtr(method)) { - return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + return is_mut ? std::format("&mut *{}.cast_mut()", lhs) + : std::format("&*{}", lhs); } - return std::format("(&raw const *{}).cast_mut()", lhs); + return is_mut ? std::format("{}.cast_mut()", lhs) : std::string(lhs); } std::string Converter::GetEqBody(const clang::CXXRecordDecl *decl, @@ -5924,23 +6028,58 @@ void Converter::ConvertOrdAndPartialOrdTraits(const clang::CXXRecordDecl *decl, const clang::FunctionDecl *eq, const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) { + const char *kSelfPtr = "(self as *const Self)"; + const char *kOtherPtr = "(other as *const Self)"; std::string cmp_body; if (cmp) { - cmp_body = GetComparisonCall(cmp, decl, "self", "other"); + cmp_body = GetComparisonCall(cmp, decl, kSelfPtr, kOtherPtr); } else if (lt) { cmp_body = std::format("if {} {{ std::cmp::Ordering::Less }} else if {} {{ " "std::cmp::Ordering::Greater }} else {{ " "std::cmp::Ordering::Equal }}", - GetComparisonBool(lt, decl, "self", "other"), - GetComparisonBool(lt, decl, "other", "self")); + GetComparisonBool(lt, decl, kSelfPtr, kOtherPtr), + GetComparisonBool(lt, decl, kOtherPtr, kSelfPtr)); } ConvertOrdAndPartialOrdTraitsBase( - cmp_body, GetEqBody(decl, eq, lt, cmp, "self", "other"), + cmp_body, GetEqBody(decl, eq, lt, cmp, kSelfPtr, kOtherPtr), GetRecordName(decl)); + if (eq && !GetComparisonTrait(eq)) { + ConvertEqualityComparableImpl(decl, eq); + } +} + +std::pair +Converter::GetComparisonOperandNames(const clang::FunctionDecl *op) { + auto params = DefinitionParameters(op); + return {clang::isa(op) + ? "this" + : GetNamedDeclAsString(params.front()), + GetNamedDeclAsString(params.back())}; +} + +void Converter::ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, + const clang::FunctionDecl *op) { + const auto &trait = op->getOverloadedOperator() == clang::OO_ExclaimEqual + ? kWeaklyEqualityComparableWithNotEqual + : kWeaklyEqualityComparableWith; + auto [lhs, rhs] = GetComparisonOperandNames(op); + AddEqualityComparableMethod( + op, trait, + std::format("{} {{ {} }}\n", + GetComparisonTraitSignature(trait, lhs, rhs, "Self"), + GetComparisonBool(op, decl, lhs, rhs))); +} + +std::string Converter::GetComparisonTraitSignature( + const RecordTrait &trait, std::string_view lhs, std::string_view rhs, + std::string_view rhs_type) const { + return std::format("unsafe fn {}({}: *const Self, {}: *const {}) -> bool", + trait.method, lhs, rhs, rhs_type); } void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { const clang::FunctionDecl *eq = nullptr; + const clang::FunctionDecl *ne = nullptr; const clang::FunctionDecl *lt = nullptr; const clang::FunctionDecl *cmp = nullptr; auto consider = [&](const clang::FunctionDecl *fn) { @@ -5956,6 +6095,9 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { case clang::OO_EqualEqual: eq = fn; break; + case clang::OO_ExclaimEqual: + ne = fn; + break; case clang::OO_Less: lt = fn; break; @@ -5979,7 +6121,8 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { for (const auto *method : decl->methods()) { consider(method); } - for (auto op : {clang::OO_EqualEqual, clang::OO_Less, clang::OO_Spaceship}) { + for (auto op : {clang::OO_EqualEqual, clang::OO_ExclaimEqual, clang::OO_Less, + clang::OO_Spaceship}) { auto name = ctx_.DeclarationNames.getCXXOperatorName(op); for (const auto *found : decl->getDeclContext()->lookup(name)) { consider_decl(found); @@ -5991,6 +6134,10 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { } } + if (eq && ne && !GetComparisonTrait(ne)) { + ConvertEqualityComparableImpl(decl, ne); + } + if (!eq && !lt && !cmp) { return; } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index ef5f2b43a6..074462a88a 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -110,7 +110,7 @@ class Converter : public clang::RecursiveASTVisitor { static void EmitOpaqueRecords(Model model, std::string &out); static void EmitGlobalInits(Model model, std::string &out); - static void EmitVirtualMethods(std::string &out); + static void EmitDeferredImpls(std::string &out); static void EmitUndefinedRecordTraits(Model model, std::string &out); virtual bool VisitBuiltinType(clang::BuiltinType *type); @@ -485,6 +485,22 @@ class Converter : public clang::RecursiveASTVisitor { CallInfo CollectCallInfo(clang::CallExpr *expr); + bool EmitComparisonTraitCallee(const CallInfo &info); + + void ConvertComparisonTraitImpl(clang::FunctionDecl *decl, + const RecordTrait &trait); + + virtual std::string + GetComparisonTraitSignature(const RecordTrait &trait, std::string_view lhs, + std::string_view rhs, + std::string_view rhs_type) const; + + std::pair + GetComparisonOperandNames(const clang::FunctionDecl *op); + + void ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, + const clang::FunctionDecl *op); + void ConvertParamTy(clang::QualType param_type, clang::Expr *expr); virtual void ConvertParamTyConstCast(clang::QualType param_type, @@ -1374,7 +1390,16 @@ class Converter : public clang::RecursiveASTVisitor { std::string header; std::string body; }; - static std::map virtual_methods_; + static std::map deferred_impls_; + + static DeferredBlock &DeferredImpl(std::string header); + + DeferredBlock &EqualityComparableImpl(std::string_view self, + std::string_view other); + + void AddEqualityComparableMethod(const clang::FunctionDecl *op, + const RecordTrait &trait, + std::string_view method); static std::map> declared_record_traits_; static std::set> converted_record_traits_; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8e93241570..eb4f59fef5 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -662,8 +662,106 @@ bool HasUserCopyConstructor(const clang::RecordDecl *decl) { }); } +const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn) { + if (auto *method = clang::dyn_cast(fn)) { + return method->getParent(); + } + return fn->getNumParams() == 2 ? fn->getParamDecl(0) + ->getType() + .getNonReferenceType() + ->getAsCXXRecordDecl() + : nullptr; +} + +clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn) { + return fn->getParamDecl(fn->getNumParams() - 1) + ->getType() + .getNonReferenceType() + .getUnqualifiedType() + .getCanonicalType(); +} + +bool HasEqualityOperator(clang::ASTContext &ctx, clang::QualType lhs, + clang::QualType rhs) { + auto same = [](clang::QualType type, clang::QualType expected) { + return type.getNonReferenceType().getUnqualifiedType().getCanonicalType() == + expected; + }; + auto is_equality = [&](const clang::NamedDecl *found) { + auto *fn = clang::dyn_cast_or_null(found); + if (!fn || fn->getOverloadedOperator() != clang::OO_EqualEqual || + fn->isDeleted()) { + return false; + } + if (auto *method = clang::dyn_cast(fn)) { + return method->isInstance() && method->getNumParams() == 1 && + same(ctx.getCanonicalTagType(method->getParent()), lhs) && + same(method->getParamDecl(0)->getType(), rhs); + } + return fn->getNumParams() == 2 && + same(fn->getParamDecl(0)->getType(), lhs) && + same(fn->getParamDecl(1)->getType(), rhs); + }; + auto name = ctx.DeclarationNames.getCXXOperatorName(clang::OO_EqualEqual); + for (auto type : {lhs, rhs}) { + auto *record = type->getAsCXXRecordDecl(); + if (!record || !record->hasDefinition()) { + continue; + } + if (llvm::any_of(record->methods(), is_equality) || + llvm::any_of(record->getDeclContext()->lookup(name), is_equality) || + llvm::any_of(record->friends(), [&](const clang::FriendDecl *decl) { + return is_equality(decl->getFriendDecl()); + })) { + return true; + } + } + return false; +} + +const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { + auto op = fn->getOverloadedOperator(); + if (op != clang::OO_EqualEqual && op != clang::OO_ExclaimEqual) { + return nullptr; + } + auto *record = GetComparisonRecord(fn); + if (!record || !IsUserDefinedDecl(record) || fn->isDeleted() || + fn->getDescribedFunctionTemplate() || + !fn->getReturnType()->isBooleanType()) { + return nullptr; + } + if (auto *method = clang::dyn_cast(fn); + method ? method->getNumParams() != 1 : fn->getNumParams() != 2) { + return nullptr; + } + if (auto *method = clang::dyn_cast(fn); + method && (method->isVirtual() || !method->isConst() || + !method->isImplicitObjectMemberFunction() || + method->getRefQualifier() == clang::RQ_RValue)) { + return nullptr; + } + for (auto *param : fn->parameters()) { + auto type = param->getType(); + if (!type->isLValueReferenceType() || + !type.getNonReferenceType().isConstQualified()) { + return nullptr; + } + } + if (op == clang::OO_EqualEqual) { + return &kWeaklyEqualityComparableWith; + } + auto &ctx = fn->getASTContext(); + return HasEqualityOperator(ctx, ctx.getCanonicalTagType(record), + GetComparisonRhsType(fn)) + ? &kWeaklyEqualityComparableWithNotEqual + : nullptr; +} + const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { method = method->getCanonicalDecl(); + if (auto *trait = GetComparisonTrait(method)) { + return trait; + } if (auto *dtor = clang::dyn_cast(method)) { return IsConvertedDestructor(dtor) && !dtor->getParent()->isAbstract() ? &kDestructible @@ -700,7 +798,8 @@ bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { ctor && ctor->isDefaultConstructor()) { return false; } - return !method->isUserProvided() && GetRecordTrait(method); + return !method->isUserProvided() && !GetComparisonTrait(method) && + GetRecordTrait(method); } std::vector GetDerivedCopyOrMoves(const clang::RecordDecl *decl) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index c89d862b37..8570fcd042 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -164,6 +164,18 @@ inline constexpr RecordTrait kDestructible{ "destroy", {"Destructible", "fn destroy(this: Ptr)", "this.clone()"}, {"DestructibleUnsafe", "unsafe fn destroy(this: *mut Self)", "this"}}; +inline constexpr RecordTrait kWeaklyEqualityComparableWith{ + "equal", + {"WeaklyEqualityComparableWith", + "fn equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, + {"WeaklyEqualityComparableWithUnsafe", + "unsafe fn equal(this: *const Self, _: *const Self) -> bool", "this"}}; +inline constexpr RecordTrait kWeaklyEqualityComparableWithNotEqual{ + "not_equal", + {"WeaklyEqualityComparableWith", + "fn not_equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, + {"WeaklyEqualityComparableWithUnsafe", + "unsafe fn not_equal(this: *const Self, _: *const Self) -> bool", "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, @@ -180,6 +192,15 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); + +clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn); + +bool HasEqualityOperator(clang::ASTContext &ctx, clang::QualType lhs, + clang::QualType rhs); + +const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn); + // Whether method is a C++ defaulted copy or move member that is translated as // a memberwise derive of its trait, rather than from its body. bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 8a6d96c9d8..9ab287222a 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -665,27 +665,34 @@ ConverterRefCount::GetComparisonReceiver(const clang::CXXMethodDecl *, } // Records implement the comparisons of the standard library (CppLess and -// CppEq) with their comparison operators, which get pointers to the values. -// They don't implement Ord and PartialEq, which get references to the values, -// as passing those to the operators would require copying the values. +// WeaklyEqualityComparableWith) with their comparison operators, which get +// pointers to the values. They don't implement Ord and PartialEq, which get +// references to the values, as passing those to the operators would require +// copying the values. void ConverterRefCount::ConvertOrdAndPartialOrdTraits( const clang::CXXRecordDecl *decl, const clang::FunctionDecl *eq, const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) { auto record_name = GetRecordName(decl); - auto emit = [&](std::string_view trait, std::string_view fn, - std::string_view body) { - StrCat(std::format("impl {} for {} {{ fn {}(__lhs: Ptr, " - "__rhs: Ptr) -> bool {{ {} }} }}", - trait, record_name, fn, body)); - }; - if (lt) { - emit("CppLess", "less", GetComparisonBool(lt, decl, "__lhs", "__rhs")); - } else if (cmp) { - emit("CppLess", "less", - std::format("{} == std::cmp::Ordering::Less", - GetComparisonCall(cmp, decl, "__lhs", "__rhs"))); - } - emit("CppEq", "equal", GetEqBody(decl, eq, lt, cmp, "__lhs", "__rhs")); + if (auto *op = lt ? lt : cmp) { + auto [lhs, rhs] = GetComparisonOperandNames(op); + StrCat(std::format( + "impl CppLess for {} {{ fn less({}: Ptr, {}: Ptr) -> bool " + "{{ {} }} }}", + record_name, lhs, rhs, + lt ? GetComparisonBool(lt, decl, lhs, rhs) + : std::format("{} == std::cmp::Ordering::Less", + GetComparisonCall(cmp, decl, lhs, rhs)))); + } + if (eq && !GetComparisonTrait(eq)) { + ConvertEqualityComparableImpl(decl, eq); + } +} + +std::string ConverterRefCount::GetComparisonTraitSignature( + const RecordTrait &trait, std::string_view lhs, std::string_view rhs, + std::string_view rhs_type) const { + return std::format("fn {}({}: Ptr, {}: Ptr<{}>) -> bool", trait.method, + lhs, rhs, rhs_type); } // Whether decl is copied by copying its bytes or the pointers it holds. diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index d824157de8..d4446f434a 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -58,6 +58,11 @@ class ConverterRefCount final : public Converter { const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) override; + std::string + GetComparisonTraitSignature(const RecordTrait &trait, std::string_view lhs, + std::string_view rhs, + std::string_view rhs_type) const override; + bool RecordImplementsClone(const clang::RecordDecl *decl) override; bool RecordDerivesClone(const clang::RecordDecl *decl); diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index 605e46ba59..a71f783d37 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -32,8 +32,8 @@ std::string TranspileSrc(std::string_view cc_code, Model model, cc_code, tool_args, std::filesystem::path(filename).filename().string(), filename.ends_with(".c") ? CLANG_C_COMPILER : CLANG_CXX_COMPILER); Converter::EmitOpaqueRecords(model, rs_code); - Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); + Converter::EmitDeferredImpls(rs_code); Converter::EmitGlobalInits(model, rs_code); return rs_code; } @@ -75,8 +75,8 @@ std::string TranspileDir(std::string_view build_dir, Model model, FrontendActionFactory factory(rs_code, model, rules_dir); Tool.run(&factory); Converter::EmitOpaqueRecords(model, rs_code); - Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); + Converter::EmitDeferredImpls(rs_code); Converter::EmitGlobalInits(model, rs_code); return rs_code; } diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 1b747a5be4..92c6b8d0d4 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -2,11 +2,11 @@ // Distributed under the MIT license that can be found in the LICENSE file. // The comparisons that the C++ standard library does with operator< and -// operator==, in the refcount model. +// operator==. use std::cmp::Ordering; -use crate::rc::Ptr; +use crate::rc::{AsPointer, Ptr, Value}; use crate::reinterpret::ByteRepr; // operator<. Records implement it with their comparison operators. @@ -14,9 +14,63 @@ pub trait CppLess: Sized { fn less(lhs: Ptr, rhs: Ptr) -> bool; } -// operator==. Records implement it with their comparison operators. -pub trait CppEq: Sized { - fn equal(lhs: Ptr, rhs: Ptr) -> bool; +// TODO: equal and not_equal return a boolean-testable type in C++ +// ([concept.booleantestable]); replace bool with BooleanTestable. +pub trait WeaklyEqualityComparableWith = Self>: + Sized +{ + fn equal(this: Ptr, rhs: Ptr) -> bool; + + fn not_equal(this: Ptr, rhs: Ptr) -> bool { + !Self::equal(this, rhs) + } +} + +pub trait WeaklyEqualityComparableWithUnsafe = Self>: + Sized +{ + /// # Safety + /// `rhs` must point to a live value. + unsafe fn equal(this: *const Self, rhs: *const U) -> bool; + + /// # Safety + /// `this` and `rhs` must point to live values. + unsafe fn not_equal(this: *const Self, rhs: *const U) -> bool { + unsafe { !Self::equal(this, rhs) } + } +} + +pub trait EqualityComparable: WeaklyEqualityComparableWith {} + +impl> EqualityComparable for T {} + +pub trait EqualityComparableUnsafe: WeaklyEqualityComparableWithUnsafe {} + +impl> EqualityComparableUnsafe for T {} + +pub trait EqualityComparableWith>: + EqualityComparable + WeaklyEqualityComparableWith +{ +} + +impl EqualityComparableWith for T +where + T: EqualityComparable + WeaklyEqualityComparableWith, + U: EqualityComparable + WeaklyEqualityComparableWith, +{ +} + +pub trait EqualityComparableWithUnsafe< + U: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, +>: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe +{ +} + +impl EqualityComparableWithUnsafe for T +where + T: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, + U: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, +{ } impl CppLess for T { @@ -25,9 +79,104 @@ impl CppLess for T { } } -impl + ByteRepr, U: ByteRepr> CppEq for T { - fn equal(lhs: Ptr, rhs: Ptr) -> bool { - lhs.with(|a| rhs.with(|b| a == b)) +macro_rules! impl_weakly_equality_comparable_with { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::WeaklyEqualityComparableWith for $ty + where + $ty: PartialEq + $crate::ByteRepr, + { + fn equal(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| a == b)) + } + } + )*}; +} +pub(crate) use impl_weakly_equality_comparable_with; + +macro_rules! impl_weakly_equality_comparable_with_unsafe { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::WeaklyEqualityComparableWithUnsafe for $ty + where + $ty: PartialEq, + { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { *this == *rhs } + } + } + )*}; +} +pub(crate) use impl_weakly_equality_comparable_with_unsafe; + +impl_weakly_equality_comparable_with!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + Ptr, Option, +); + +impl WeaklyEqualityComparableWith for Vec { + fn equal(this: Ptr, rhs: Ptr) -> bool { + let len = this.with(Vec::len); + let (a, b) = (this.decay(), rhs.decay()); + len == rhs.with(Vec::len) && (0..len).all(|i| T::equal(a.offset(i), b.offset(i))) + } +} + +impl WeaklyEqualityComparableWith for Box<[T]> { + fn equal(this: Ptr, rhs: Ptr) -> bool { + let len = this.with(|elems| elems.len()); + let (a, b) = (this.decay(), rhs.decay()); + len == rhs.with(|elems| elems.len()) && (0..len).all(|i| T::equal(a.offset(i), b.offset(i))) + } +} + +impl WeaklyEqualityComparableWith + for (Value, Value) +where + Self: ByteRepr, +{ + fn equal(this: Ptr, rhs: Ptr) -> bool { + let pointers = |pair: &Self| { + ( + AsPointer::::as_pointer(&pair.0), + AsPointer::::as_pointer(&pair.1), + ) + }; + let (a0, a1) = this.with(pointers); + let (b0, b1) = rhs.with(pointers); + A::equal(a0, b0) && B::equal(a1, b1) + } +} + +impl_weakly_equality_comparable_with_unsafe!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + *mut T, *const T, Option, +); + +impl WeaklyEqualityComparableWithUnsafe for Vec { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { + let (len, a, b) = ((*this).len(), (*this).as_ptr(), (*rhs).as_ptr()); + len == (*rhs).len() && (0..len).all(|i| T::equal(a.add(i), b.add(i))) + } + } +} + +impl WeaklyEqualityComparableWithUnsafe for [T; N] { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + let (a, b) = (this as *const T, rhs as *const T); + (0..N).all(|i| unsafe { T::equal(a.add(i), b.add(i)) }) + } +} + +impl WeaklyEqualityComparableWithUnsafe + for (A, B) +{ + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { + A::equal(&raw const (*this).0, &raw const (*rhs).0) + && B::equal(&raw const (*this).1, &raw const (*rhs).1) + } } } diff --git a/libcc2rs/src/fn_ptr.rs b/libcc2rs/src/fn_ptr.rs index aa5c2dbb0d..c149582224 100644 --- a/libcc2rs/src/fn_ptr.rs +++ b/libcc2rs/src/fn_ptr.rs @@ -493,6 +493,18 @@ impl PartialEq for FnPtr { impl Eq for FnPtr {} +impl crate::WeaklyEqualityComparableWith for FnPtr { + fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| a.addr == b.addr)) + } +} + +impl crate::WeaklyEqualityComparableWithUnsafe for FnPtr { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { (*this).addr == (*rhs).addr } + } +} + impl ByteRepr for FnPtr {} impl crate::ZeroInitialization for FnPtr { diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 9b8d672467..6a737d9af9 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -140,6 +140,12 @@ impl PartialEq for AnyPtr { } } +impl crate::WeaklyEqualityComparableWith for AnyPtr { + fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| *a.ptr == *b.ptr)) + } +} + impl std::fmt::Debug for AnyPtr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Debug::fmt(&self.ptr.as_bytes(), f) diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index c4e8e12b6b..1df7cc903f 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -23,22 +23,26 @@ fn f2< a1: T1, a2: T2, ) -> T2 { - let mut __first = a0; + let __first: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while __first != a1 { - __out.iter_deref().write(T4::cpp_from(__first.iter_deref())); - __first.iter_inc(); + while ::not_equal(__first.as_pointer(), __last.as_pointer()) { + __out.iter_deref().write(T4::cpp_from(__first.borrow().iter_deref())); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out } -fn f3, T2, T3: CppEq>(a0: T1, a1: T1, a2: Ptr) -> T1 { - let mut __it = a0; - while __it != a1 && !CppEq::equal(__it.iter_deref(), a2.clone()) { - __it.iter_inc(); +fn f3, T2: WeaklyEqualityComparableWith, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal(__it.borrow().iter_deref(), a2.clone()) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } fn f6, T2, T3: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) @@ -62,15 +66,16 @@ where } fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { - let mut __best = a0.clone(); - if a0 != a1 { - let mut __it = a0; - __it.iter_inc(); - while __it != a1 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + let mut __best = __it.borrow().clone(); + if ::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best @@ -80,22 +85,23 @@ fn f9(a0: Ptr, a1: Ptr) { Swappable::swap(a0, a1) } -fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( +fn f10, T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr>( a0: T1, a1: T1, ) -> T1 { - if a0 == a1 { - a1 + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + if ::equal(__it.as_pointer(), __last.as_pointer()) { + __last.borrow().clone() } else { - let mut __write = a0.clone(); - let mut __it = a0; - __it.iter_inc(); - while __it != a1 { - if !CppEq::equal(__write.iter_deref(), __it.iter_deref()) { + let mut __write = __it.borrow().clone(); + __it.borrow_mut().iter_inc(); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + if !WeaklyEqualityComparableWith::equal(__write.iter_deref(), __it.borrow().iter_deref()) { __write.iter_inc(); - __write.iter_deref().write(__it.iter_deref().read()); + __write.iter_deref().write(__it.borrow().iter_deref().read()); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } __write.iter_inc(); __write @@ -103,20 +109,22 @@ fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( } fn f12, T2: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) { - let mut __it = a0; - while __it != a1 { - __it.iter_deref().write(Clone::clone(&a2)); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow().iter_deref().write(Clone::clone(&a2)); + __it.borrow_mut().iter_inc(); } } fn f13>(a0: T1, a1: T1, a2: &mut ::std::fs::File) -> ::std::fs::File { - let mut __it = a0; + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while __it != a1 { - __bytes.push(__it.iter_deref().read() as u8); - __it.iter_inc(); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + __bytes.push(__it.borrow().iter_deref().read() as u8); + __it.borrow_mut().iter_inc(); } __out.write_all(&__bytes); __out.try_clone().unwrap() diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index b13370b5d9..7a1531f4de 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -24,7 +24,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: ) -> T2 { let mut __first = a0; let mut __out = a2; - while __first != a1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { *__out.iter_deref() = T4::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -32,9 +32,9 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: __out } -unsafe fn f3, T2, T3: PartialEq>(a0: T1, a1: T1, a2: T2) -> T1 { +unsafe fn f3, T2: WeaklyEqualityComparableWithUnsafe, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { let mut __it = a0; - while __it != a1 && *__it.iter_deref() != a2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { __it.iter_inc(); } __it @@ -68,10 +68,10 @@ where unsafe fn f8, T2: PartialOrd>(a0: T1, a1: T1) -> T1 { let mut __best = a0.clone(); - if a0 != a1 { + if WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) { let mut __it = a0; __it.iter_inc(); - while __it != a1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -87,15 +87,15 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { SwappableUnsafe::swap(&mut *__a, __b) } -unsafe fn f10, T2: PartialEq + Clone>(a0: T1, a1: T1) -> T1 { - if a0 == a1 { +unsafe fn f10, T2: WeaklyEqualityComparableWithUnsafe + Clone>(a0: T1, a1: T1) -> T1 { + if WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { a1 } else { let mut __write = a0.clone(); let mut __it = a0; __it.iter_inc(); - while __it != a1 { - if *__write.iter_deref() != *__it.iter_deref() { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { + if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); } @@ -108,7 +108,7 @@ unsafe fn f10, T2: PartialEq + Clone>(a0: T1, a1: unsafe fn f12, T2: Clone>(a0: T1, a1: T1, a2: T2) { let mut __it = a0; - while __it != a1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { *__it.iter_deref() = Clone::clone(&a2); __it.iter_inc(); } @@ -122,7 +122,7 @@ unsafe fn f13>( let mut __it = a0; let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while __it != a1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index ee31e5ba33..1b6e93a23d 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -8,7 +8,8 @@ use std::marker::PhantomData; use std::rc::Rc; use crate::{ - ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, + ByteRepr, EqualityComparable, EqualityComparableUnsafe, MapNode, PostfixDec, PostfixInc, + PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, }; pub trait CppIterator: Clone { @@ -17,7 +18,7 @@ pub trait CppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait CppInputIterator: CppIterator + PartialEq {} +pub trait CppInputIterator: CppIterator + EqualityComparable {} pub trait CppBidirectionalIterator: CppInputIterator { fn iter_dec(&mut self) -> &mut Self; @@ -37,7 +38,7 @@ pub trait UnsafeCppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait UnsafeCppInputIterator: UnsafeCppIterator + PartialEq {} +pub trait UnsafeCppInputIterator: UnsafeCppIterator + EqualityComparableUnsafe {} pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { fn iter_dec(&mut self) -> &mut Self; @@ -174,6 +175,30 @@ macro_rules! uninhabited_iterator { self.never() } } + + impl crate::MoveConstructible for $name { + fn move_constructor(_: Ptr, src: Ptr) { + src.with(|it| it.never()) + } + } + + impl crate::CopyConstructible for $name { + fn copy_constructor(_: Ptr, src: Ptr) { + src.with(|it| it.never()) + } + } + + impl crate::MoveConstructibleUnsafe for $name { + unsafe fn move_constructor(_: *mut Self, src: *mut Self) { + unsafe { (*src).never() } + } + } + + impl crate::CopyConstructibleUnsafe for $name { + unsafe fn copy_constructor(_: *mut Self, src: *const Self) { + unsafe { (*src).never() } + } + } }; } @@ -207,8 +232,8 @@ uninhabited_iterator_ops!(UnsafeInputIterator, UnsafeCppIterator, *mut T); uninhabited_iterator_ops!(UnsafeOutputIterator, UnsafeCppIterator, *mut T); uninhabited_iterator_ops!(UnsafeForwardIterator, UnsafeCppIterator, *mut T); -impl CppInputIterator for InputIterator {} -impl CppInputIterator for ForwardIterator {} +impl CppInputIterator for InputIterator {} +impl CppInputIterator for ForwardIterator {} impl UnsafeCppInputIterator for UnsafeInputIterator {} impl UnsafeCppInputIterator for UnsafeForwardIterator {} @@ -265,9 +290,9 @@ impl CppIterator for BidirectionalIterator { } } -impl CppInputIterator for BidirectionalIterator {} +impl CppInputIterator for BidirectionalIterator {} -impl CppBidirectionalIterator for BidirectionalIterator { +impl CppBidirectionalIterator for BidirectionalIterator { fn iter_dec(&mut self) -> &mut Self { match self { Self::Map(node) => *node = MapNode::prev(node), @@ -343,7 +368,7 @@ impl UnsafeCppBidirectionalIterator for UnsafeBidirectionalIterator { } macro_rules! random_access_iterator { - ($name:ident, $ptr:ty, $iter:ident, $input:ident, $bidi:ident, $random:ident, $null:expr) => { + ($name:ident, $ptr:ty, $iter:ident, $input:ident, $bidi:ident, $random:ident, $eq:ident, $null:expr) => { pub enum $name { Vec($ptr), } @@ -413,11 +438,17 @@ macro_rules! random_access_iterator { } } - impl $input for $name where $ptr: $input {} + impl $input for $name + where + $ptr: $input, + Self: $eq, + { + } impl $bidi for $name where $ptr: $bidi, + Self: $eq, { fn iter_dec(&mut self) -> &mut Self { match self { @@ -437,6 +468,7 @@ macro_rules! random_access_iterator { impl $random for $name where $ptr: $random, + Self: $eq, { fn iter_add(&self, n: isize) -> Self { match self { @@ -469,6 +501,7 @@ random_access_iterator!( CppInputIterator, CppBidirectionalIterator, CppRandomAccessIterator, + EqualityComparable, Ptr::null() ); @@ -487,9 +520,25 @@ random_access_iterator!( UnsafeCppInputIterator, UnsafeCppBidirectionalIterator, UnsafeCppRandomAccessIterator, + EqualityComparableUnsafe, std::ptr::null_mut() ); +crate::constructor::impl_trivial_copy_move!( + BidirectionalIterator, RandomAccessIterator, + UnsafeBidirectionalIterator, UnsafeRandomAccessIterator, +); + +crate::cmp::impl_weakly_equality_comparable_with!( + InputIterator, OutputIterator, ForwardIterator, + BidirectionalIterator, RandomAccessIterator, +); + +crate::cmp::impl_weakly_equality_comparable_with_unsafe!( + UnsafeInputIterator, UnsafeOutputIterator, UnsafeForwardIterator, + UnsafeBidirectionalIterator, UnsafeRandomAccessIterator, +); + pub trait IterStep: Clone + PartialEq { fn iter_step(&mut self); } diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index dfe55827ee..153918f166 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -58,12 +58,12 @@ fn f8, T2>(a0: T1) -> Ptr { a0.iter_deref() } -fn f9, T2>(a0: T1, a1: T1) -> bool { - a0 == a1 +fn f9, T2>(a0: Ptr, a1: Ptr) -> bool { + WeaklyEqualityComparableWith::equal(a0, a1) } -fn f10, T2>(a0: T1, a1: T1) -> bool { - a0 != a1 +fn f10, T2>(a0: Ptr, a1: Ptr) -> bool { + WeaklyEqualityComparableWith::not_equal(a0, a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + PartialEq, T2: CppInputIterator, T3>(a0: T1, a1: T2) -> bool { - a0 == a1 +fn f27 + WeaklyEqualityComparableWith, T2: CppInputIterator + WeaklyEqualityComparableWith, T3>(a0: Ptr, a1: Ptr) -> bool { + WeaklyEqualityComparableWith::equal(a0, a1) } diff --git a/rules/iterator_category/tgt_unsafe.rs b/rules/iterator_category/tgt_unsafe.rs index c16b316384..5a9629caf1 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -58,12 +58,12 @@ fn f8, T2>(a0: T1) -> *mut T2 { a0.iter_deref() } -fn f9, T2>(a0: T1, a1: T1) -> bool { - a0 == a1 +unsafe fn f9, T2>(a0: T1, a1: T1) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } -fn f10, T2>(a0: T1, a1: T1) -> bool { - a0 != a1 +unsafe fn f10, T2>(a0: T1, a1: T1) -> bool { + WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + PartialEq, T2: UnsafeCppInputIterator, T3>(a0: T1, a1: T2) -> bool { - a0 == a1 +unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, T3>(a0: T1, a1: T2) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 50219d6641..8233935bf1 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -133,3 +133,7 @@ where { a0.get_value::().as_pointer() } + +fn f28, T2: WeaklyEqualityComparableWith>(a0: (Value, Value), a1: (Value, Value)) -> bool { + !(WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer())) +} diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index e3fa54ce19..e45a4353ce 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -98,8 +98,8 @@ where &*a0.get::() } -fn f28(a0: (T1, T2), a1: (T1, T2)) -> bool { - a0 != a1 +unsafe fn f28, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { + !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) } fn f29(a0: (T1, T2), a1: (T1, T2)) -> bool { diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index a931448642..a374cf2cd8 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -93,10 +93,11 @@ fn f80(a0: Ptr>, fn f92, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: T3) -> Vec { let mut __v = Vec::new(); - let mut __it = a0; - while __it != a1 { - __v.push(T1::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(T1::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } __v } @@ -137,10 +138,11 @@ fn f101 + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( ) -> RandomAccessIterator { let start_idx = a1.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = a2; - while __it != a3 { - temp_vec.push(T1::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a2)); + let __last: Value = Rc::new(RefCell::new(a3)); + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(T1::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } a0.with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index c10cb2cb55..5fc277be99 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -152,7 +152,7 @@ fn f91(a0: Vec) -> Vec { unsafe fn f92, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { let mut __v = Vec::new(); let mut __it = a0; - while __it != a1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __v.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -193,7 +193,7 @@ unsafe fn f101, T2, T3: UnsafeCppInputIterator, T4>( let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = a2; - while __it != a3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a3) { __tmp.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index 8a185bce62..51be3124d8 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -33,35 +33,37 @@ fn main_0() -> i32 { let s1: Value = Rc::new(RefCell::new(S { a: 1, b: 2 })); let s2: Value = Rc::new(RefCell::new(S { a: 1, b: 2 })); let s3: Value = Rc::new(RefCell::new(S { a: 1, b: 3 })); - assert!(({ operator_eq_0(s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ operator_ne_1(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ operator_eq_0(s1.as_pointer(), s3.as_pointer(),) })); - assert!(({ operator_lt_2(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ operator_lt_2(s3.as_pointer(), s1.as_pointer(),) })); - assert!((({ compare_3(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); - assert!((({ compare_3(s3.as_pointer(), s1.as_pointer(),) }) == 1)); - assert!((({ compare_3(s1.as_pointer(), s2.as_pointer(),) }) == 0)); + assert!(({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s3.as_pointer(),) })); + assert!(({ operator_lt_0(s1.as_pointer(), s3.as_pointer(),) })); + assert!(!({ operator_lt_0(s3.as_pointer(), s1.as_pointer(),) })); + assert!((({ compare_1(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); + assert!((({ compare_1(s3.as_pointer(), s1.as_pointer(),) }) == 1)); + assert!((({ compare_1(s1.as_pointer(), s2.as_pointer(),) }) == 0)); return 0; } -pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) - && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); -} -pub fn operator_ne_1(x: Ptr, y: Ptr) -> bool { - return !({ operator_eq_0((x).clone(), (y).clone()) }); -} -pub fn operator_lt_2(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }) || (({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) && ({ x.with(|__s| __s.b) } < { y.with(|__s| __s.b) })); } -pub fn compare_3(x: Ptr, y: Ptr) -> i32 { - if ({ operator_lt_2((x).clone(), (y).clone()) }) { +pub fn compare_1(x: Ptr, y: Ptr) -> i32 { + if ({ operator_lt_0((x).clone(), (y).clone()) }) { return -1_i32; } - if ({ operator_lt_2((y).clone(), (x).clone()) }) { + if ({ operator_lt_0((y).clone(), (x).clone()) }) { return 1; } return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) + && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); + } + fn not_equal(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs index f48036273a..21e57ddc31 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -34,63 +34,65 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - operator_eq_0(_x, &s2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &s2) }) ); assert!( (unsafe { let _x: *const S = &s1; - operator_ne_1(_x, &s3) + WeaklyEqualityComparableWithUnsafe::not_equal(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s1; - operator_eq_0(_x, &s3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &s3) }) ); assert!( (unsafe { let _x: *const S = &s1; - operator_lt_2(_x, &s3) + operator_lt_0(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s3; - operator_lt_2(_x, &s1) + operator_lt_0(_x, &s1) }) ); - assert!(((unsafe { compare_3(&s1, &s3,) }) == (-1_i32))); - assert!(((unsafe { compare_3(&s3, &s1,) }) == (1))); - assert!(((unsafe { compare_3(&s1, &s2,) }) == (0))); + assert!(((unsafe { compare_1(&s1, &s3,) }) == (-1_i32))); + assert!(((unsafe { compare_1(&s3, &s1,) }) == (1))); + assert!(((unsafe { compare_1(&s1, &s2,) }) == (0))); return 0; } -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); -} -pub unsafe fn operator_ne_1(x: *const S, y: *const S) -> bool { - return !(unsafe { - let _x: *const S = x; - operator_eq_0(_x, y) - }); -} -pub unsafe fn operator_lt_2(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b))); } -pub unsafe fn compare_3(x: *const S, y: *const S) -> i32 { +pub unsafe fn compare_1(x: *const S, y: *const S) -> i32 { if (unsafe { let _x: *const S = x; - operator_lt_2(_x, y) + operator_lt_0(_x, y) }) { return -1_i32; } if (unsafe { let _x: *const S = y; - operator_lt_2(_x, x) + operator_lt_0(_x, x) }) { return 1; } return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); + } + unsafe fn not_equal(x: *const S, y: *const S) -> bool { + return !(unsafe { + let _x: *const S = x; + WeaklyEqualityComparableWithUnsafe::equal(_x, y) + }); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 80212c0812..f98c669f4f 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -848,13 +848,6 @@ fn main_0() -> i32 { #[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p13_pointer_to_incomplete_class_X; -impl p4_1_pure_virtual_without_definition_HasPureVirtual - for p4_1_pure_virtual_without_definition_OverridesPureVirtual -{ - fn f(&mut self) { - (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); - } -} impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn destroy(this: Ptr) { unreachable!( @@ -876,6 +869,13 @@ impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment ) } } +impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + fn f(&mut self) { + (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); let _ = ctorCount_1.with(|_| ()); diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 9b239de46c..f1bd018218 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -758,13 +758,6 @@ unsafe fn main_0() -> i32 { } #[derive(Clone, Copy, Default, VaArg, FnPtrArg)] pub struct p13_pointer_to_incomplete_class_X; -unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual - for p4_1_pure_virtual_without_definition_OverridesPureVirtual -{ - unsafe fn f(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); - } -} impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { unsafe fn destroy(this: *mut Self) { unreachable!( @@ -786,6 +779,13 @@ impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssi ) } } +unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + unsafe fn f(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_0); std::cell::LazyCell::force(&*&raw const ctorCount_1); diff --git a/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp b/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp new file mode 100644 index 0000000000..308a473718 --- /dev/null +++ b/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp @@ -0,0 +1,70 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include +#include + +// N4950 [concept.equalitycomparable]/1.3: t != u is the opposite of t == u, +// also when the type defines both operators. +namespace p1_3_not_equal { +static int not_equal_calls = 0; + +struct Meters { + int value; + bool operator==(const Meters &other) const { return value == other.value; } + bool operator!=(const Meters &other) const { + ++not_equal_calls; + return value != other.value; + } +}; + +void test() { + Meters three{3}; + Meters also_three{3}; + Meters four{4}; + assert(three == also_three); + assert(!(three != also_three)); + assert(three != four); + assert(not_equal_calls == 2); +} +} // namespace p1_3_not_equal + +// N4950 [concept.equalitycomparable]/1.2, /1.4: u == t and u != t give the +// results of t == u and t != u. +namespace p1_2_reversed_operands { +struct Meters { + int value; + bool operator==(const int &other) const { return value == other; } +}; + +void test() { + Meters three{3}; + assert(three == 3); + assert(3 == three); + assert(three != 4); + assert(4 != three); +} +} // namespace p1_2_reversed_operands + +// N4950 [concept.equalitycomparable]/1: the operands may have different +// types. +namespace p1_different_types { +struct Meters { + int value; + bool operator==(const int &other) const { return value == other; } +}; + +void test() { + std::vector lengths{{1}, {2}, {3}}; + auto found = std::find(lengths.begin(), lengths.end(), 2); + assert(found != lengths.end()); + assert(found->value == 2); + assert(std::find(lengths.begin(), lengths.end(), 7) == lengths.end()); +} +} // namespace p1_different_types + +int main() { + p1_3_not_equal::test(); + p1_2_reversed_operands::test(); + p1_different_types::test(); + return 0; +} diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs new file mode 100644 index 0000000000..ac6ac28c57 --- /dev/null +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs @@ -0,0 +1,212 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static not_equal_calls_0: Value = Rc::new(RefCell::new(0)); +); +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_3_not_equal_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_1() { + let three: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 3 })); + let also_three: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 3 })); + let four: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 4 })); + assert!( + ({ WeaklyEqualityComparableWith::equal(three.as_pointer(), also_three.as_pointer(),) }) + ); + assert!( + !({ + WeaklyEqualityComparableWith::not_equal(three.as_pointer(), also_three.as_pointer()) + }) + ); + assert!(({ WeaklyEqualityComparableWith::not_equal(three.as_pointer(), four.as_pointer(),) })); + assert!((not_equal_calls_0.with(|rc| *rc.borrow()) == 2)); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_2_reversed_operands_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_2() { + let three: Value = + Rc::new(RefCell::new(p1_2_reversed_operands_Meters { value: 3 })); + assert!( + ({ + let _other: Value = Rc::new(RefCell::new(3)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + ({ + let _other: Value = Rc::new(RefCell::new(3)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + !({ + let _other: Value = Rc::new(RefCell::new(4)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + !({ + let _other: Value = Rc::new(RefCell::new(4)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_different_types_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_3() { + let lengths: Value> = Rc::new(RefCell::new(Vec::from([ + p1_different_types_Meters { value: 1 }, + p1_different_types_Meters { value: 2 }, + p1_different_types_Meters { value: 3 }, + ]))); + let found: Value> = Rc::new(RefCell::new( + ({ + let __tmp_0: Value = Rc::new(RefCell::new(2)); + { + let __it: Value> = + Rc::new(RefCell::new(lengths.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(lengths.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_0.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }), + )); + assert!(WeaklyEqualityComparableWith::not_equal( + found.as_pointer(), + Rc::new(RefCell::new(lengths.decay().end())).as_pointer() + )); + assert!((({ (*found.borrow()).iter_deref() }).with(|__s| __s.value) == 2)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_2: Value = Rc::new(RefCell::new(7)); + { + let __it: Value> = + Rc::new(RefCell::new(lengths.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(lengths.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_2.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }) + )) + .as_pointer(), + Rc::new(RefCell::new(lengths.decay().end())).as_pointer(), + ) { + (__tmp_1, __tmp_3) => { + WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_3).clone()) + } + }); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_2() }); + ({ test_3() }); + return 0; +} +impl WeaklyEqualityComparableWith for p1_3_not_equal_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { other.with(|__s| __s.value) }); + } + fn not_equal(this: Ptr, other: Ptr) -> bool { + (*not_equal_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.value) } != { other.with(|__s| __s.value) }); + } +} +impl WeaklyEqualityComparableWith for p1_2_reversed_operands_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl WeaklyEqualityComparableWith for p1_different_types_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl WeaklyEqualityComparableWith for i32 { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWith for i32 { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +pub fn __cpp2rust_init_globals() { + let _ = not_equal_calls_0.with(|_| ()); +} diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs new file mode 100644 index 0000000000..527546e493 --- /dev/null +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -0,0 +1,171 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut not_equal_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_3_not_equal_Meters { + pub value: i32, +} +pub unsafe fn test_1() { + let mut three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; + let mut also_three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; + let mut four: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 4 }; + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &also_three,) })); + assert!( + !(unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const three, &also_three,) }) + ); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const three, &four,) })); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut not_equal_calls_0)) == (2))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_2_reversed_operands_Meters { + pub value: i32, +} +pub unsafe fn test_2() { + let mut three: p1_2_reversed_operands_Meters = p1_2_reversed_operands_Meters { value: 3 }; + assert!( + (unsafe { + let mut _other: i32 = 3; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + (unsafe { + let mut _other: i32 = 3; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + !(unsafe { + let mut _other: i32 = 4; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + !(unsafe { + let mut _other: i32 = 4; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_different_types_Meters { + pub value: i32, +} +pub unsafe fn test_3() { + let mut lengths: Vec = Vec::from([ + p1_different_types_Meters { value: 1 }, + p1_different_types_Meters { value: 2 }, + p1_different_types_Meters { value: 3 }, + ]); + let mut found: UnsafeRandomAccessIterator = { + let mut __tmp_0 = { lengths.begin() }; + let mut __tmp_1 = { lengths.end() }; + let mut __it = (__tmp_0).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { + __it.iter_inc(); + } + __it + }; + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &found, + &lengths.end() + )); + assert!((((*found.iter_deref()).value) == (2))); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ + let mut __tmp_2 = { lengths.begin() }; + let mut __tmp_3 = { lengths.end() }; + let mut __it = (__tmp_2).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) + { + __it.iter_inc(); + } + __it + }, + &lengths.end() + )); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_3() }); + return 0; +} +impl WeaklyEqualityComparableWithUnsafe for p1_3_not_equal_Meters { + unsafe fn equal(this: *const Self, other: *const p1_3_not_equal_Meters) -> bool { + return (((*this).value) == ((*other).value)); + } + unsafe fn not_equal(this: *const Self, other: *const p1_3_not_equal_Meters) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut not_equal_calls_0)).prefix_inc(); + return (((*this).value) != ((*other).value)); + } +} +impl WeaklyEqualityComparableWithUnsafe for p1_2_reversed_operands_Meters { + unsafe fn equal(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl WeaklyEqualityComparableWithUnsafe for p1_different_types_Meters { + unsafe fn equal(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + unsafe fn equal(lhs: *const Self, rhs: *const p1_2_reversed_operands_Meters) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + unsafe fn equal(lhs: *const Self, rhs: *const p1_different_types_Meters) -> bool { + >::equal(rhs, lhs) + } +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const not_equal_calls_0); +} diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index 4dd51e9cb0..ed07a6ef03 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -127,8 +127,26 @@ pub fn test_4() { Rc::new(RefCell::new(2)), Rc::new(RefCell::new(0)), ))); - assert!((*a.borrow()) != (*b.borrow())); - assert!(({ !((*a.borrow()) != (*a.borrow())) })); + assert!( + !(WeaklyEqualityComparableWith::equal( + (*a.borrow()).0.as_pointer(), + (*b.borrow()).0.as_pointer() + ) && WeaklyEqualityComparableWith::equal( + (*a.borrow()).1.as_pointer(), + (*b.borrow()).1.as_pointer() + )) + ); + assert!( + ({ + !(!(WeaklyEqualityComparableWith::equal( + (*a.borrow()).0.as_pointer(), + (*a.borrow()).0.as_pointer(), + ) && WeaklyEqualityComparableWith::equal( + (*a.borrow()).1.as_pointer(), + (*a.borrow()).1.as_pointer(), + ))) + }) + ); assert!((*a.borrow()) < (*b.borrow())); assert!(({ !((*b.borrow()) < (*a.borrow())) })); assert!((*b.borrow()) < (*c.borrow())); diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index c78e30a131..c109916ae7 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -139,8 +139,14 @@ pub unsafe fn test_4() { let mut a: (i32, i32) = (1, 2); let mut b: (i32, i32) = (1, 3); let mut c: (i32, i32) = (2, 0); - assert!(a != b); - assert!(!(a != a)); + assert!( + !(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &b.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &b.1)) + ); + assert!( + !(!(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &a.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &a.1))) + ); assert!(a < b); assert!(!(b < a)); assert!(b < c); diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index b74e57284a..d99c5277d1 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -101,17 +101,6 @@ impl Counter { }); return this.with(|__s| __s.v); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - field!(this, calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -impl CppEq for Counter { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Counter::operator_eq(__lhs.clone(), __rhs.clone()) - } } #[derive( Copy, @@ -199,8 +188,8 @@ fn main_0() -> i32 { assert!((({ Counter::Get(c1.as_pointer(),) }) == 3)); assert!((({ Counter::Get(c2.as_pointer(),) }) == 3)); assert!((({ Counter::Get((pc).clone(),) }) == 3)); - assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ Counter::operator_eq(c2.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c2.as_pointer(), c1.as_pointer(),) })); assert!(({ (*c1.borrow()).calls } == 3)); assert!(({ (*c2.borrow()).calls } == 2)); let t: Value = Rc::new(RefCell::new(Tally { calls: 0 })); @@ -213,4 +202,12 @@ fn main_0() -> i32 { assert!(({ (*ct.borrow()).calls } == 10)); return 0; } +impl WeaklyEqualityComparableWith for Counter { + fn equal(this: Ptr, o: Ptr) -> bool { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index 449d379793..0f5a446b89 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -38,7 +38,11 @@ pub fn sum_1(v: Ptr>) -> i32 { let mut total: i32 = 0; { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { + 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_0,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_0).clone()) + } + } { 'for_body: { total += (({ (*it.borrow()).iter_deref() }).read()); } @@ -93,34 +97,34 @@ fn main_0() -> i32 { ) }),) { - (__tmp_0,) => __tmp_0.decay(), + (__tmp_1,) => __tmp_1.decay(), } .write(7); assert!(((vec_elem!(h.as_pointer(), vec_, 0_usize).read()) == 7)); let m: Value, Value>)>> = Rc::new(RefCell::new(Map::new())); ({ - let __tmp_2: Value = Rc::new(RefCell::new(8)); + let __tmp_3: Value = Rc::new(RefCell::new(8)); MoveConstructible::push_moved( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_1,) => { + (__tmp_2,) => { ({ (*m.borrow_mut()).subscript_move( - __tmp_1, + __tmp_2, |__k| cpp_move!(__k), || Default::default(), ) }) } }, - __tmp_2.as_pointer(), + __tmp_3.as_pointer(), ) }); assert!( ((match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_3,) => { + (__tmp_4,) => { ({ (*m.borrow_mut()).subscript_move( - __tmp_3, + __tmp_4, |__k| cpp_move!(__k), || Default::default(), ) diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 1c838005ce..1d75ac83e3 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -420,13 +420,16 @@ fn main_0() -> i32 { object!(der2, Derived, der.as_pointer()); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { - let mut __tmp_0 = { vec_.decay().begin() }; - let mut __tmp_1 = { vec_.decay().end() }; let mut __v = Vec::new(); - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(vec_.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(vec_.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -439,13 +442,13 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - DefaultConstructible::default_constructor(__tmp_3.as_pointer()); - __tmp_3.as_pointer() + DefaultConstructible::default_constructor(__tmp_1.as_pointer()); + __tmp_1.as_pointer() },) { - (__tmp_2,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_2).clone()), + (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; object!(self_src, SelfPtr); @@ -464,13 +467,13 @@ fn main_0() -> i32 { } }); { - let __tmp_5: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Counted::construct(__tmp_5.as_pointer(), 30); - __tmp_5.as_pointer() + Counted::construct(__tmp_3.as_pointer(), 30); + __tmp_3.as_pointer() },) { - (__tmp_4,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_4).clone()), + (__tmp_2,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_2).clone()), } }; assert!( diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 8eb3283d6f..d094221826 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -22,38 +22,48 @@ fn main_0() -> i32 { }); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(7)); + let __tmp_2: Value = Rc::new(RefCell::new(7)); { - let mut __tmp_2 = { v.decay().begin() }; - let mut __tmp_3 = { v.decay().end() }; - let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_2.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - assert!((*it.borrow()) != v.decay().end()); + assert!( + match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_3,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_3).clone()) + } + } + ); assert!(((({ (*it.borrow()).iter_deref() }).read()) == 7)); { - let mut __tmp_5 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_5); + let mut __tmp_4 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_4); let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(__tmp_5.iter_at(__i), __tmp_5.iter_at(__j)); + Swappable::swap(__tmp_4.iter_at(__i), __tmp_4.iter_at(__j)); } }; { - let mut __tmp_6 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_6); + let mut __tmp_5 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_6.iter_at(__x), &__tmp_6.iter_at(__y))); - reorder(__order, |__i| __tmp_6.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); + reorder(__order, |__i| __tmp_5.iter_at(__i)); }; assert!(({ (*v.borrow())[0_usize] } == 4) && ({ (*v.borrow())[1_usize] } == 7)); return 0; diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index 70a1267555..8562a87dd6 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -28,20 +28,22 @@ fn main_0() -> i32 { let mut alias: Ptr>> = (rows.as_pointer()); { let mut __tmp_0 = { ({ select_rows_0((alias).clone(), (calls.as_pointer())) }) }; - let mut __tmp_3 = { + let mut __tmp_1 = { { - let mut __tmp_1 = { (alias).decay().offset(0_usize).decay() }; - let mut __tmp_2 = { (alias).decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new((alias).decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + (alias).decay().offset(0_usize).decay().offset((3) as isize), + )); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - __tmp_0.with_mut(|__v: &mut Vec>| __v.push(__tmp_3)) + __tmp_0.with_mut(|__v: &mut Vec>| __v.push(__tmp_1)) }; printf!( b"calls=%d size=%zu last=%d\n", diff --git a/tests/unit/out/refcount/emplace_receiver_order.rs b/tests/unit/out/refcount/emplace_receiver_order.rs index 1f85e96f87..78a71cd0ac 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -35,41 +35,45 @@ fn main_0() -> i32 { let mut receiver: Ptr>> = ({ select_rows_0((rows.as_pointer()), (calls.as_pointer())) }); { - let mut __tmp_2 = { + let mut __tmp_0 = { { - let mut __tmp_0 = { rows.decay().offset(0_usize).decay() }; - let mut __tmp_1 = - { rows.decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + rows.decay().offset(0_usize).decay().offset((3) as isize), + )); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - receiver.with_mut(|__v: &mut Vec>| __v.push(__tmp_2)) + receiver.with_mut(|__v: &mut Vec>| __v.push(__tmp_0)) }; } else { { - let mut __tmp_3 = + let mut __tmp_1 = { ({ select_rows_0((rows.as_pointer()), (calls.as_pointer())) }) }; - let mut __tmp_6 = { + let mut __tmp_2 = { { - let mut __tmp_4 = { rows.decay().offset(0_usize).decay() }; - let mut __tmp_5 = - { rows.decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_4).clone(); - while __it != __tmp_5 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + rows.decay().offset(0_usize).decay().offset((3) as isize), + )); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - __tmp_3.with_mut(|__v: &mut Vec>| __v.push(__tmp_6)) + __tmp_1.with_mut(|__v: &mut Vec>| __v.push(__tmp_2)) }; } printf!( diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 504af54ae4..e0982d9a88 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -23,16 +23,6 @@ pub struct P { #[offset(0)] pub x: i32, } -impl P { - pub fn operator_eq(this: Ptr, o: Ptr

) -> bool { - return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); - } -} -impl CppEq for P { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - P::operator_eq(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -55,20 +45,27 @@ fn main_0() -> i32 { let v_end: Value> = Rc::new(RefCell::new(v.decay().end())); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(2)); + let __tmp_3: Value = Rc::new(RefCell::new(2)); { - let mut __tmp_3 = { (*v_end.borrow()).clone() }; - let mut __it = ({ (*v_begin.borrow()).clone() }); - while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + let __it: Value> = + Rc::new(RefCell::new(({ (*v_begin.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new(({ (*v_end.borrow()).clone() }))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_3.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - let mut v_result_true: bool = (*it.borrow()) != v.decay().end(); + let mut v_result_true: bool = match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_4,) => WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_4).clone()), + }; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_5,) => { @@ -96,94 +93,167 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - let mut m_result_true: bool = (*m_begin.borrow()) != (*m_end.borrow()); + let mut m_result_true: bool = + WeaklyEqualityComparableWith::not_equal(m_begin.as_pointer(), m_end.as_pointer()); assert!( ((v_result_true) && (m_result_true)) - && (({ - let __tmp_10: Value = Rc::new(RefCell::new(2)); - { - let mut __tmp_8 = { v.decay().begin() }; - let mut __tmp_9 = { v.decay().begin() }; - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 - && !CppEq::equal(__it.iter_deref(), __tmp_10.as_pointer().clone()) - { - __it.iter_inc(); - } - __it + && (match ( + Rc::new(RefCell::new( + ({ + let __tmp_9: Value = Rc::new(RefCell::new(2)); + { + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().begin())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_9.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v.decay().begin())).as_pointer(), + ) { + (__tmp_8, __tmp_10) => { + WeaklyEqualityComparableWith::equal((__tmp_8).clone(), (__tmp_10).clone()) } - }) == v.decay().begin()) + }) ); let w: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5]))); - assert!( - ({ - let __tmp_13: Value = Rc::new(RefCell::new(4)); - { - let mut __tmp_11 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_12 = { w.decay().end() }; - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 - && !CppEq::equal(__it.iter_deref(), __tmp_13.as_pointer().clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_12: Value = Rc::new(RefCell::new(4)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_12.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(3_isize) - ); - assert!( - ({ - let __tmp_16: Value = Rc::new(RefCell::new(1)); - { - let mut __tmp_14 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_15 = { w.decay().end() }; - let mut __it = (__tmp_14).clone(); - while __it != __tmp_15 - && !CppEq::equal(__it.iter_deref(), __tmp_16.as_pointer().clone()) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(3_isize))).as_pointer(), + ) { + (__tmp_11, __tmp_13) => { + WeaklyEqualityComparableWith::equal((__tmp_11).clone(), (__tmp_13).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_15: Value = Rc::new(RefCell::new(1)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_15.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().end() - ); - assert!( - ({ - let __tmp_19: Value = Rc::new(RefCell::new(5)); - { - let mut __tmp_17 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_18 = { w.decay().begin().iter_add(4_isize) }; - let mut __it = (__tmp_17).clone(); - while __it != __tmp_18 - && !CppEq::equal(__it.iter_deref(), __tmp_19.as_pointer().clone()) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().end())).as_pointer(), + ) { + (__tmp_14, __tmp_16) => { + WeaklyEqualityComparableWith::equal((__tmp_14).clone(), (__tmp_16).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_18: Value = Rc::new(RefCell::new(5)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_18.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(4_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))).as_pointer(), + ) { + (__tmp_17, __tmp_19) => { + WeaklyEqualityComparableWith::equal((__tmp_17).clone(), (__tmp_19).clone()) + } + }); let p: Value> = Rc::new(RefCell::new(Vec::from([ P { x: 0 }, P { x: 1 }, P { x: 2 }, ]))); - assert!( - ({ - let __tmp_22: Value

= Rc::new(RefCell::new(P { x: 1 })); - { - let mut __tmp_20 = { p.decay().begin() }; - let mut __tmp_21 = { p.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), (__tmp_22.as_pointer()).clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_21: Value

= Rc::new(RefCell::new(P { x: 1 })); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(p.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(p.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + (__tmp_21.as_pointer()).clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == p.decay().begin().iter_add(1_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(p.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_22) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_22).clone()) + } + }); return 0; } +impl WeaklyEqualityComparableWith for P { + fn equal(this: Ptr, o: Ptr

) -> bool { + return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index c9e3cff5e4..d4b2be0dee 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -9,13 +9,10 @@ use std::rc::{Rc, Weak}; pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); -} -pub fn scaled_2(v: Ptr, mut k: i32) -> i32 { +pub fn scaled_1(v: Ptr, mut k: i32) -> i32 { return ({ v.with(|__s| __s.x) } * { k }); } -pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { +pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } #[derive( @@ -35,12 +32,7 @@ pub struct V { #[offset(0)] pub x: i32, } -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} -pub fn get_4(w: Ptr) -> i32 { +pub fn get_3(w: Ptr) -> i32 { return w.with(|__s| __s.x); } #[derive( @@ -60,7 +52,7 @@ pub struct W_int_ { #[offset(0)] pub x: i32, } -pub fn get_5(w: Ptr) -> i64 { +pub fn get_4(w: Ptr) -> i64 { return w.with(|__s| __s.x); } #[derive( @@ -97,7 +89,7 @@ pub struct D { #[offset(0)] pub x: i32, } -pub fn declared_then_defined_6(d: Ptr) -> i32 { +pub fn declared_then_defined_5(d: Ptr) -> i32 { return (d.with(|__s| __s.x) + 1); } pub fn main() { @@ -109,16 +101,21 @@ fn main_0() -> i32 { let b: Value = Rc::new(RefCell::new(V { x: 3 })); let c: Value = Rc::new(RefCell::new(V { x: 4 })); assert!((({ get_0(a.as_pointer(),) }) == 3)); - assert!(({ operator_eq_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!((({ scaled_2(c.as_pointer(), 2,) }) == 8)); - assert!((({ scaled_3(c.as_pointer(), 1.5_f64,) }) == 6_f64)); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!((({ scaled_1(c.as_pointer(), 2,) }) == 8)); + assert!((({ scaled_2(c.as_pointer(), 1.5_f64,) }) == 6_f64)); let wi: Value = Rc::new(RefCell::new(W_int_ { x: 5 })); let wl: Value = Rc::new(RefCell::new(W_long_ { x: 6_i64 })); - assert!((({ get_4(wi.as_pointer(),) }) == 5)); - assert!((({ get_5(wl.as_pointer(),) }) == 6_i64)); + assert!((({ get_3(wi.as_pointer(),) }) == 5)); + assert!((({ get_4(wl.as_pointer(),) }) == 6_i64)); let d: Value = Rc::new(RefCell::new(D { x: 7 })); - assert!((({ declared_then_defined_6(d.as_pointer(),) }) == 8)); + assert!((({ declared_then_defined_5(d.as_pointer(),) }) == 8)); return 0; } +impl WeaklyEqualityComparableWith for V { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 2ee95d677a..38a0839aa7 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -219,7 +219,7 @@ fn main_0() -> i32 { }), ), )); - let mut x1: u32 = if (*it.borrow()) == (*end.borrow()) { + let mut x1: u32 = if WeaklyEqualityComparableWith::equal(it.as_pointer(), end.as_pointer()) { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -227,9 +227,16 @@ fn main_0() -> i32 { .borrow()) }; assert!((x1 == 4_u32)); - let mut x2: u32 = if (*const_it.borrow()) - == , Value)>>::from(({ (*end.borrow()).clone() })) + let mut x2: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*end.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_20,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_20).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -237,10 +244,14 @@ fn main_0() -> i32 { .borrow()) }; assert!((x2 == 0_u32)); - let mut x3: u32 = if (*it.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) + let mut x3: u32 = if match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) { + (__tmp_21,) => WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_21).clone()), + } { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -248,11 +259,19 @@ fn main_0() -> i32 { .borrow()) }; assert!((x3 == 4_u32)); - let mut x4: u32 = if (*const_it.borrow()) - == , Value)>>::from( - m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()), - ) { + let mut x4: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + ))) + .as_pointer(),) + { + (__tmp_22,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_22).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -261,16 +280,16 @@ fn main_0() -> i32 { }; assert!((x4 == 0_u32)); match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_20,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_20, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_23,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) } } .write(5_u32); let it4: Value, Value)>> = Rc::new(RefCell::new( ({ - let __tmp_21: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_21.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_24.as_pointer())) }), )); let mut p: Ptr = ((*({ (*it4.borrow()).iter_deref() }).upgrade().deref()) @@ -279,8 +298,8 @@ fn main_0() -> i32 { let mut x5: u32 = (p.read()); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_22,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_22, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_25,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_25, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -301,8 +320,8 @@ fn main_0() -> i32 { }); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_23,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_26,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_26, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -321,10 +340,10 @@ fn main_0() -> i32 { let const_it4: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_27: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_24.as_pointer()) + __m.find(&__tmp_27.as_pointer()) }) }), ), @@ -339,66 +358,90 @@ fn main_0() -> i32 { ); let r: Ptr, Value)>> = m.as_pointer(); assert!(({ ((*r.upgrade().deref()).len() == 4_usize) })); - assert!( - ({ - let __tmp_25: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_29: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_29.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_25.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_28, __tmp_30) => { + WeaklyEqualityComparableWith::not_equal((__tmp_28).clone(), (__tmp_30).clone()) + } + }); Map::erase((r).clone(), &({ (*it4.borrow()).clone() })); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_26: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_32: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_32.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_26.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_31, __tmp_33) => { + WeaklyEqualityComparableWith::equal((__tmp_31).clone(), (__tmp_33).clone()) + } + }); match (Rc::new(RefCell::new(7_i16)).as_pointer(),) { - (__tmp_27,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_27, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_34,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_34, |__k| cpp_move!(__k), || 0_u32) }) } } .write(7_u32); match (Rc::new(RefCell::new(8_i16)).as_pointer(),) { - (__tmp_28,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_28, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_35,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_35, |__k| cpp_move!(__k), || 0_u32) }) } } .write(8_u32); match (Rc::new(RefCell::new(9_i16)).as_pointer(),) { - (__tmp_29,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_29, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_36,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_36, |__k| cpp_move!(__k), || 0_u32) }) } } .write(9_u32); assert!(({ ((*r.upgrade().deref()).len() == 6_usize) })); assert!( (({ - let __tmp_30: Value = Rc::new(RefCell::new(10_i16)); - Map::erase_key(m.as_pointer(), &__tmp_30.as_pointer()) + let __tmp_37: Value = Rc::new(RefCell::new(10_i16)); + Map::erase_key(m.as_pointer(), &__tmp_37.as_pointer()) }) == 0_usize) ); let mut key9: i32 = 9; assert!( (({ - let __tmp_31: Value = Rc::new(RefCell::new((key9 as i16))); - Map::erase_key(m.as_pointer(), &__tmp_31.as_pointer()) + let __tmp_38: Value = Rc::new(RefCell::new((key9 as i16))); + Map::erase_key(m.as_pointer(), &__tmp_38.as_pointer()) }) == 1_usize) ); assert!(({ ((*r.upgrade().deref()).len() == 5_usize) })); let cit: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_32: Value = Rc::new(RefCell::new(7_i16)); + let __tmp_39: Value = Rc::new(RefCell::new(7_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_32.as_pointer()) + __m.find(&__tmp_39.as_pointer()) }) }), ), @@ -406,34 +449,54 @@ fn main_0() -> i32 { let next: Value, Value)>> = Rc::new(RefCell::new( Map::erase(m.as_pointer(), &({ (*cit.borrow()).clone() })), )); - assert!( - (*next.borrow()) - == ({ - let __tmp_33: Value = Rc::new(RefCell::new(8_i16)); - m.as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&__tmp_33.as_pointer()) - }) - }) - ); + assert!(match (Rc::new(RefCell::new( + ({ + let __tmp_41: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| __m.find(&__tmp_41.as_pointer())) + }) + )) + .as_pointer(),) + { + (__tmp_40,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_40).clone()) + } + }); { (*next.borrow_mut()) = Map::erase(m.as_pointer(), &({ (*next.borrow()).clone() })); }; - assert!( - (*next.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + assert!(match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(),) + { + (__tmp_42,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_42).clone()) + } + }); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_34: Value = Rc::new(RefCell::new(8_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_44: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_44.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_34.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_43, __tmp_45) => { + WeaklyEqualityComparableWith::equal((__tmp_43).clone(), (__tmp_45).clone()) + } + }); let other_map: Value< Map<(Value, Value), (Value<(Value, Value)>, Value)>, > = Rc::new(RefCell::new(Map::new())); @@ -444,18 +507,18 @@ fn main_0() -> i32 { ))); let mut value: f64 = 2_f64; match (key0.as_pointer(),) { - (__tmp_35,) => ({ (*other_map.borrow_mut()).subscript(__tmp_35, || 0_f64) }), + (__tmp_46,) => ({ (*other_map.borrow_mut()).subscript(__tmp_46, || 0_f64) }), } .write(value); value = (match (key0.as_pointer(),) { - (__tmp_36,) => ({ (*other_map.borrow_mut()).subscript(__tmp_36, || 0_f64) }), + (__tmp_47,) => ({ (*other_map.borrow_mut()).subscript(__tmp_47, || 0_f64) }), } .read()); assert!(({ ((*other_map.borrow()).len() == 1_usize) })); assert!( ((match (key0.as_pointer(),) { - (__tmp_37,) => { - ({ (*other_map.borrow_mut()).subscript(__tmp_37, || 0_f64) }) + (__tmp_48,) => { + ({ (*other_map.borrow_mut()).subscript(__tmp_48, || 0_f64) }) } } .read()) @@ -465,9 +528,9 @@ fn main_0() -> i32 { let mut k: i32 = 0; assert!( ({ - let __tmp_38: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_49: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_38.as_pointer()) + .get(&__tmp_49.as_pointer()) .expect("out of range!") .borrow() .1 @@ -478,9 +541,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_39: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_50: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_39.as_pointer()) + .get(&__tmp_50.as_pointer()) .expect("out of range!") .borrow() .1 @@ -491,9 +554,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_40: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_51: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_40.as_pointer()) + .get(&__tmp_51.as_pointer()) .expect("out of range!") .borrow() .1 @@ -509,8 +572,8 @@ fn main_0() -> i32 { 'loop_: while (i > 30_u32) { 'for_body: { ({ - let __tmp_41: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_41.as_pointer()) + let __tmp_52: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_52.as_pointer()) }); } i.prefix_dec(); @@ -521,8 +584,8 @@ fn main_0() -> i32 { 'loop_: while (i > 60_u32) { 'for_body: { ({ - let __tmp_42: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_42.as_pointer()) + let __tmp_53: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_53.as_pointer()) }); } i.prefix_dec(); @@ -533,8 +596,8 @@ fn main_0() -> i32 { 'loop_: while (i > 0_u32) { 'for_body: { ({ - let __tmp_43: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_43.as_pointer()) + let __tmp_54: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_54.as_pointer()) }); } i.prefix_dec(); @@ -545,7 +608,7 @@ fn main_0() -> i32 { 'loop_: while ((i as usize) < (*indexes.borrow()).len()) { 'for_body: { match (indexes.decay().offset((i as usize)),) { - (__tmp_44,) => ({ (*m2.borrow_mut()).subscript(__tmp_44, || false) }), + (__tmp_55,) => ({ (*m2.borrow_mut()).subscript(__tmp_55, || false) }), } .write(((i).wrapping_rem(2_u32) != 0)); } @@ -576,9 +639,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_45 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; + let mut __tmp_56 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_45.0.as_pointer(), || __tmp_45); + Map::emplace(m3.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -599,9 +662,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_46 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; + let mut __tmp_57 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_46.0.as_pointer(), || __tmp_46); + Map::emplace(m3.as_pointer(), &__tmp_57.0.as_pointer(), || __tmp_57); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -619,25 +682,25 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_48 = { + let mut __tmp_59 = { match (Rc::new(RefCell::new(( Rc::new(RefCell::new(4)), Rc::new(RefCell::new(5)), ))) .as_pointer(),) { - (__tmp_47,) => ( + (__tmp_58,) => ( Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).0.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).0.as_pointer().read()), )), Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).1.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).1.as_pointer().read()), )), ), } }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_48.0.as_pointer(), || __tmp_48); + Map::emplace(m3.as_pointer(), &__tmp_59.0.as_pointer(), || __tmp_59); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -646,8 +709,8 @@ fn main_0() -> i32 { assert!(({ ((*m3.borrow()).len() == 2_usize) })); assert!( ((match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_49,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_49, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_60,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_60, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -655,23 +718,23 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(4)).as_pointer(),) { - (__tmp_50,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_50, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_61,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_61, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) == 5) ); let hinted: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_51 = { + let mut __tmp_62 = { , Value)>>::from( m3.as_pointer() .with(|__m: &Map, Value)>| __m.end()), ) }; - let mut __tmp_52 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; - let _ = (__tmp_51).clone(); - Map::emplace(m3.as_pointer(), &__tmp_52.0.as_pointer(), || __tmp_52).0 + let mut __tmp_63 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; + let _ = (__tmp_62).clone(); + Map::emplace(m3.as_pointer(), &__tmp_63.0.as_pointer(), || __tmp_63).0 })); assert!( ({ @@ -727,8 +790,8 @@ fn main_0() -> i32 { assert!(({ ((*(*tried_new.borrow()).1.borrow()) as bool) })); assert!( ((match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_53,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_53, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_64,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -758,10 +821,10 @@ fn main_0() -> i32 { assert!(({ ((*(*point_new.borrow()).1.borrow()) as bool) })); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_54,) => { + (__tmp_65,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_54, + __tmp_65, |__k| cpp_move!(__k), || ::default(), ) @@ -773,10 +836,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_55,) => { + (__tmp_66,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_55, + __tmp_66, |__k| cpp_move!(__k), || ::default(), ) @@ -787,7 +850,7 @@ fn main_0() -> i32 { == 4) ); { - let mut __tmp_56 = { + let mut __tmp_67 = { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ @@ -798,7 +861,7 @@ fn main_0() -> i32 { ) }; let (__it, __inserted) = - Map::emplace(points.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); + Map::emplace(points.as_pointer(), &__tmp_67.0.as_pointer(), || __tmp_67); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -806,10 +869,10 @@ fn main_0() -> i32 { }; assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_57,) => { + (__tmp_68,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_57, + __tmp_68, |__k| cpp_move!(__k), || ::default(), ) @@ -821,10 +884,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_58,) => { + (__tmp_69,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_58, + __tmp_69, |__k| cpp_move!(__k), || ::default(), ) @@ -867,9 +930,9 @@ fn main_0() -> i32 { ); k = 0; let value_0: Ptr = ({ - let __tmp_59: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_70: Value = Rc::new(RefCell::new((k as i16))); (*m.borrow()) - .get(&__tmp_59.as_pointer()) + .get(&__tmp_70.as_pointer()) .expect("out of range!") .borrow() .1 @@ -908,10 +971,10 @@ fn main_0() -> i32 { ); { match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_60,) => { + (__tmp_71,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_60, + __tmp_71, |__k| cpp_move!(__k), || 0_i32, ) @@ -922,10 +985,10 @@ fn main_0() -> i32 { }; assert!( ((match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_61,) => { + (__tmp_72,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_61, + __tmp_72, |__k| cpp_move!(__k), || 0_i32, ) @@ -939,75 +1002,75 @@ fn main_0() -> i32 { { let t: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_62,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_62, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_73,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_73, |__k| cpp_move!(__k), || 0_i32) }) } } .write(5); { match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_63,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_63, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_74,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_74, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| *__v = *__v + 3) }; match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_64,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_75,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_75, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| __v.postfix_inc()); let r: Ptr = match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_65,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_65, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_76,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_76, |__k| cpp_move!(__k), || 0_i32) }) } }; r.write(6); let mut p: Ptr = (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_66,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_66, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_77,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_77, |__k| cpp_move!(__k), || 0_i32) }) } }); p.write(4); ({ inc_2(match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_67,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_67, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_78,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_78, |__k| cpp_move!(__k), || 0_i32) }) } }) }); Swappable::swap( match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_68,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_68, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_79,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_79, |__k| cpp_move!(__k), || 0_i32) }) } }, match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_69,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_69, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_80,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_80, |__k| cpp_move!(__k), || 0_i32) }) } }, ); let mut x: i32 = ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_70,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_70, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_81,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_81, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) + (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_71,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_71, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_82,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_82, |__k| cpp_move!(__k), || 0_i32) }) } } .read())); assert!( (((x == 10) && ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_72,) => { + (__tmp_83,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_72, + __tmp_83, |__k| cpp_move!(__k), || 0_i32, ) @@ -1017,10 +1080,10 @@ fn main_0() -> i32 { .read()) == 4)) && ((match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_73,) => { + (__tmp_84,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_73, + __tmp_84, |__k| cpp_move!(__k), || 0_i32, ) @@ -1030,10 +1093,10 @@ fn main_0() -> i32 { .read()) == 6)) && ((match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_74,) => { + (__tmp_85,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_74, + __tmp_85, |__k| cpp_move!(__k), || 0_i32, ) diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 23a1742f03..6b30fb39c0 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -45,14 +45,8 @@ impl MoveConstructible for Key { } } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Key::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Key::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, o: Ptr) -> bool { + Key::operator_lt(this.clone(), o.clone()) } } pub fn make_key_3(__return: Ptr, mut k: i32) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 6576af11ae..d502571423 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -29,21 +29,13 @@ pub struct Key { pub identity: i32, } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } -pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); -} #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(4)] pub struct Mapped { @@ -82,7 +74,11 @@ fn main_0() -> i32 { identity: 7, })); ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -114,31 +110,43 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) - & (((*a_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_0,) => { + WeaklyEqualityComparableWith::equal(a_it.as_pointer(), (__tmp_0).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_1,) => { + WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_1).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - != distinct + & ((match (Rc::new(RefCell::new( + distinct .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_2,) => { + WeaklyEqualityComparableWith::not_equal(b_it.as_pointer(), (__tmp_2).clone()) + } + }) as i32)) != 0 }; ok = { @@ -157,7 +165,11 @@ fn main_0() -> i32 { != 0 }; ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let mut distinct_count: usize = 0_usize; @@ -200,7 +212,12 @@ fn main_0() -> i32 { })); ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let equivalent: Value, Value)>> = @@ -233,32 +250,51 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - != equivalent + & ((match (Rc::new(RefCell::new( + equivalent .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_3,) => WeaklyEqualityComparableWith::not_equal( + first_it.as_pointer(), + (__tmp_3).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_4,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_4).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_b.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_b.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_5,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_5).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -300,7 +336,12 @@ fn main_0() -> i32 { } ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let later_key: Value = Rc::new(RefCell::new(Key { @@ -319,12 +360,18 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_6,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_6).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -384,12 +431,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_7,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_7).clone()) + } + }) as i32)) != 0 }; ok = { @@ -418,12 +468,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_8,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_8).clone()) + } + }) as i32)) != 0 }; ok = { @@ -443,6 +496,11 @@ fn main_0() -> i32 { }; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWith for Key { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); + } +} pub fn __cpp2rust_init_globals() { let _ = default_constructions_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index bd21add8dd..3e3dc3f6cd 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -295,7 +295,7 @@ fn main_0() -> i32 { as i32)) != 0 }; - let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; + let mut found : bool = match (Rc::new(RefCell::new(m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) )).as_pointer(),) { (__tmp_6,) => { WeaklyEqualityComparableWith::equal(({ (*result.borrow()) .0 .as_pointer() }), (__tmp_6 ).clone()) } } ; ok = { ((ok as i32) & (found as i32)) != 0 }; ok = { ((ok as i32) @@ -390,14 +390,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_6,) => { + (__tmp_7,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_7).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -429,7 +429,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_7,) => { + (__tmp_8,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -438,7 +438,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_7).clone()), + Moved((__tmp_8).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -470,14 +470,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_8,) => { + (__tmp_9,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_9).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -510,7 +510,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_9,) => { + (__tmp_10,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -519,7 +519,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_9).clone()), + Moved((__tmp_10).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -573,13 +573,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_10,) => { + (__tmp_11,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItem::construct_1(__v.as_pointer(), (__tmp_10).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -604,13 +604,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_11,) => { + (__tmp_12,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_12).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -655,13 +655,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_13.as_pointer(), 30); - __tmp_13.as_pointer() + Item::construct_1(__tmp_14.as_pointer(), 30); + __tmp_14.as_pointer() },) { - (__tmp_12,) => { + (__tmp_13,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -670,7 +670,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_12).clone()), + Moved((__tmp_13).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -698,13 +698,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_15.as_pointer(), 40); - __tmp_15.as_pointer() + Item::construct_1(__tmp_16.as_pointer(), 40); + __tmp_16.as_pointer() },) { - (__tmp_14,) => { + (__tmp_15,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -713,7 +713,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_14).clone()), + Moved((__tmp_15).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fdd9e50724..db0277c11c 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -52,14 +52,8 @@ impl CopyConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_4(__lhs.clone(), __rhs.clone())) - && !(operator_lt_4(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { @@ -117,17 +111,16 @@ fn main_0() -> i32 { assert!((((((r1 + r2) + r3) + r4) + r5) == 56)); let values: Value> = Rc::new(RefCell::new(Box::new([1, 7, 7, 3]))); let mut max: Ptr = { - let mut __tmp_2 = { values.decay() }; - let mut __tmp_3 = { values.decay().offset((4) as isize) }; - let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { - let mut __it = (__tmp_2).clone(); - __it.iter_inc(); - while __it != __tmp_3 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + let __it: Value> = Rc::new(RefCell::new(values.decay())); + let __last: Value> = Rc::new(RefCell::new(values.decay().offset((4) as isize))); + let mut __best = __it.borrow().clone(); + if >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best @@ -135,11 +128,11 @@ fn main_0() -> i32 { assert!(({ (max).clone() } == { values.decay().offset((1) as isize) })); assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { - (__tmp_4, __tmp_5) => { - if CppLess::less((__tmp_4).clone().clone(), (__tmp_5).clone().clone()) { - (__tmp_5).clone() + (__tmp_2, __tmp_3) => { + if CppLess::less((__tmp_2).clone().clone(), (__tmp_3).clone().clone()) { + (__tmp_3).clone() } else { - (__tmp_4).clone() + (__tmp_2).clone() } } } @@ -149,11 +142,11 @@ fn main_0() -> i32 { ); assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { - (__tmp_6, __tmp_7) => { - if CppLess::less((__tmp_7).clone().clone(), (__tmp_6).clone().clone()) { - (__tmp_7).clone() + (__tmp_4, __tmp_5) => { + if CppLess::less((__tmp_5).clone().clone(), (__tmp_4).clone().clone()) { + (__tmp_5).clone() } else { - (__tmp_6).clone() + (__tmp_4).clone() } } } @@ -164,46 +157,46 @@ fn main_0() -> i32 { calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( ({ + let __tmp_7: Value = Rc::new(RefCell::new(::zero_init())); let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 1) }); - __tmp_9.as_pointer() + ({ make_5(Ptr::clone(&__tmp_7.as_pointer()), 1) }); + __tmp_7.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 2) }); - __tmp_11.as_pointer() + ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 2) }); + __tmp_9.as_pointer() }, ) { - (__tmp_8, __tmp_10) => { - if CppLess::less((__tmp_8).clone().clone(), (__tmp_10).clone().clone()) { - (__tmp_10).clone() - } else { + (__tmp_6, __tmp_8) => { + if CppLess::less((__tmp_6).clone().clone(), (__tmp_8).clone().clone()) { (__tmp_8).clone() + } else { + (__tmp_6).clone() } } } .with(|__s| __s.n) == 2) }) && ({ + let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 1) }); - __tmp_13.as_pointer() + ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 1) }); + __tmp_11.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_15.as_pointer()), 2) }); - __tmp_15.as_pointer() + ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 2) }); + __tmp_13.as_pointer() }, ) { - (__tmp_12, __tmp_14) => { - if CppLess::less((__tmp_14).clone().clone(), (__tmp_12).clone().clone()) { - (__tmp_14).clone() - } else { + (__tmp_10, __tmp_12) => { + if CppLess::less((__tmp_12).clone().clone(), (__tmp_10).clone().clone()) { (__tmp_12).clone() + } else { + (__tmp_10).clone() } } } @@ -218,16 +211,16 @@ fn main_0() -> i32 { 'loop_: while (i < 3) { 'for_body: { largest = (({ - let __tmp_17: Value = Rc::new(RefCell::new((largest as u64))); + let __tmp_15: Value = Rc::new(RefCell::new((largest as u64))); (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { - (__tmp_16,) => { + (__tmp_14,) => { if CppLess::less( - __tmp_17.as_pointer().clone(), - (__tmp_16).clone().clone(), + __tmp_15.as_pointer().clone(), + (__tmp_14).clone().clone(), ) { - (__tmp_16).clone() + (__tmp_14).clone() } else { - __tmp_17.as_pointer() + __tmp_15.as_pointer() } } } diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 35144fd896..ecdf2fe32e 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,17 +25,6 @@ pub struct Eq { #[offset(4)] pub b: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -77,19 +66,10 @@ impl Cmp { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -110,9 +90,6 @@ pub struct Both { pub a: i32, } impl Both { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -127,13 +104,8 @@ impl Both { } } impl CppLess for Both { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Both { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, _a0: Ptr) -> bool { + Both::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -168,13 +140,8 @@ impl OrdOnly { } } impl CppLess for OrdOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for OrdOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + OrdOnly::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -207,18 +174,10 @@ impl Inner { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); - } } impl CppLess for Inner { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Inner { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Inner::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -262,19 +221,10 @@ impl Outer { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ Inner::operator_eq(field_ptr!(this, i), field_ptr!(_a0, i)) }) - && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); - } } impl CppLess for Outer { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Outer { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Outer::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -295,12 +245,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { - return !({ Secondary::operator_eq((this).clone(), (_a0).clone()) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -323,13 +267,8 @@ impl Secondary { } } impl CppLess for Secondary { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Secondary { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, _a0: Ptr) -> bool { + Secondary::operator_lt(this.clone(), _a0.clone()) } } #[derive( @@ -362,18 +301,10 @@ impl PtrMember { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); - } } impl CppLess for PtrMember { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for PtrMember { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + PtrMember::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } pub fn main() { @@ -384,8 +315,8 @@ fn main_0() -> i32 { let e1: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e2: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e3: Value = Rc::new(RefCell::new(Eq { a: 1, b: 3 })); - assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ Eq::operator_eq(e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e3.as_pointer(),) })); let c1: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 2 })); let c2: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 3 })); let c3: Value = Rc::new(RefCell::new(Cmp { a: 2, b: 0 })); @@ -394,7 +325,7 @@ fn main_0() -> i32 { assert!( ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) == std::cmp::Ordering::Greater ); - assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c1.as_pointer(),) })); assert!( ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) @@ -404,7 +335,7 @@ fn main_0() -> i32 { assert!( ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Both::operator_eq(b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(b2.as_pointer(), b2.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(OrdOnly { a: 1 })); let o2: Value = Rc::new(RefCell::new(OrdOnly { a: 2 })); assert!( @@ -429,14 +360,14 @@ fn main_0() -> i32 { assert!( ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(x1.as_pointer(), x3.as_pointer(),) })); assert!( ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ Secondary::operator_ne(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_lt(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_ge(s2.as_pointer(), s1.as_pointer(),) })); assert!(!({ Secondary::operator_lt(s2.as_pointer(), s1.as_pointer(),) })); @@ -450,11 +381,52 @@ fn main_0() -> i32 { ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(p1.as_pointer(), p3.as_pointer(),) })); assert!( ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); return 0; } +impl WeaklyEqualityComparableWith for Both { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Inner { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); + } +} +impl WeaklyEqualityComparableWith for Outer { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ WeaklyEqualityComparableWith::equal(field_ptr!(this, i), field_ptr!(_a0, i)) }) + && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); + } +} +impl WeaklyEqualityComparableWith for PtrMember { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); + } +} +impl WeaklyEqualityComparableWith for Secondary { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + fn not_equal(this: Ptr, _a0: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((this).clone(), (_a0).clone()) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index a3cce0c780..6ebfb63406 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -24,37 +24,26 @@ pub struct S { pub v: i32, } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); -} -pub fn operator_ne_2(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); -} pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_gt_3(a: Ptr, b: Ptr) -> bool { +pub fn operator_gt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -pub fn operator_le_4(a: Ptr, b: Ptr) -> bool { +pub fn operator_le_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } <= { b.with(|__s| __s.v) }); } -pub fn operator_ge_5(a: Ptr, b: Ptr) -> bool { +pub fn operator_ge_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); } -pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { +pub fn operator_lt_4(a: Ptr, mut b: i32) -> bool { return ({ a.with(|__s| __s.v) } < { b }); } -pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { +pub fn operator_lt_5(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( @@ -75,25 +64,20 @@ pub struct V { pub v: i32, } impl CppLess for V { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_8(__lhs.read(), __rhs.read()) - } -} -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_9(__lhs.read(), __rhs.read()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_7(a.read(), b.read()) } } -pub fn operator_eq_9(mut a: V, mut b: V) -> bool { +pub fn operator_eq_8(mut a: V, mut b: V) -> bool { return (a.v == b.v); } -pub fn operator_ne_10(mut a: V, mut b: V) -> bool { +pub fn operator_ne_6(mut a: V, mut b: V) -> bool { return (a.v != b.v); } -pub fn operator_lt_8(mut a: V, mut b: V) -> bool { +pub fn operator_lt_7(mut a: V, mut b: V) -> bool { return (a.v < b.v); } -pub fn operator_gt_11(mut a: V, mut b: V) -> bool { +pub fn operator_gt_9(mut a: V, mut b: V) -> bool { return (a.v > b.v); } pub fn main() { @@ -104,23 +88,39 @@ fn main_0() -> i32 { let mut x: V = V { v: 1 }; let mut y: V = V { v: 2 }; let mut z: V = V { v: 1 }; - assert!(({ operator_eq_9(x, z,) })); - assert!(({ operator_ne_10(x, y,) })); - assert!(({ operator_lt_8(x, y,) })); - assert!(({ operator_gt_11(y, x,) })); - assert!(!({ operator_lt_8(y, x,) })); + assert!(({ operator_eq_8(x, z,) })); + assert!(({ operator_ne_6(x, y,) })); + assert!(({ operator_lt_7(x, y,) })); + assert!(({ operator_gt_9(y, x,) })); + assert!(!({ operator_lt_7(y, x,) })); let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ne_2(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); - assert!(({ operator_gt_3(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_le_4(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ge_5(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_gt_1(b.as_pointer(), a.as_pointer(),) })); + assert!(({ operator_le_2(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ge_3(a.as_pointer(), c.as_pointer(),) })); assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_lt_6(a.as_pointer(), 5,) })); - assert!(({ operator_lt_7(0, a.as_pointer(),) })); + assert!(({ operator_lt_4(a.as_pointer(), 5,) })); + assert!(({ operator_lt_5(0, a.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } + fn not_equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for V { + fn not_equal(a: Ptr, b: Ptr) -> bool { + operator_ne_6(a.read(), b.read()) + } + fn equal(a: Ptr, b: Ptr) -> bool { + operator_eq_8(a.read(), b.read()) + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index a0088dd538..d0d5e86497 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -24,12 +24,6 @@ pub struct S { pub v: i32, } impl S { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } - pub fn operator_ne(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); - } pub fn operator_lt_3(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); } @@ -47,13 +41,8 @@ impl S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_lt_3(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_lt_3(this.clone(), o.clone()) } } pub fn main() { @@ -64,8 +53,8 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); - assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); assert!(({ S::operator_le(a.as_pointer(), c.as_pointer(),) })); @@ -74,4 +63,12 @@ fn main_0() -> i32 { assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } + fn not_equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 1229dd8525..e616eb253b 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -24,22 +24,17 @@ pub struct X { pub v: i32, } impl CppLess for X { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) + fn less(a: Ptr, b: Ptr) -> bool { + ((operator_lt_1(a.read(), b.read())) != 0) } } -impl CppEq for X { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_eq_1(__lhs.read(), __rhs.read())) != 0) - } -} -pub fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if (a.v == b.v) { 2 } else { 0 }; } -pub fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if (a.v != b.v) { 3 } else { 0 }; } -pub fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if (a.v < b.v) { 4 } else { 0 }; } pub fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -131,13 +126,8 @@ impl Mixed { } } impl CppLess for Mixed { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) - } -} -impl CppEq for Mixed { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_eq(__lhs.clone(), __rhs.clone())) != 0) + fn less(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_lt(this.clone(), o.clone())) != 0) } } #[derive( @@ -185,17 +175,9 @@ pub struct Boolish { pub v: i32, } impl CppLess for Boolish { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + fn less(a: Ptr, b: Ptr) -> bool { { - let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); - MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) - } - } -} -impl CppEq for Boolish { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - { - let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); + let __cmp = operator_lt_6(a.read(), b.read()); MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } @@ -269,14 +251,6 @@ impl RefInt { return ref_true_8.with(|v| v.as_pointer()); } } -impl CppEq for RefInt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - { - let __cmp = RefInt::operator_eq(__lhs.clone(), __rhs.clone()); - RefBool::to_bool(__cmp.clone()) - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -285,10 +259,10 @@ fn main_0() -> i32 { let mut a: X = X { v: 1 }; let mut b: X = X { v: 2 }; let mut c: X = X { v: 1 }; - assert!((({ operator_eq_1(a, c,) }) == 2)); - assert!((({ operator_eq_1(a, b,) }) == 0)); - assert!((({ operator_ne_2(a, b,) }) == 3)); - assert!((({ operator_lt_0(a, b,) }) == 4)); + assert!((({ operator_eq_2(a, c,) }) == 2)); + assert!((({ operator_eq_2(a, b,) }) == 0)); + assert!((({ operator_ne_0(a, b,) }) == 3)); + assert!((({ operator_lt_1(a, b,) }) == 4)); assert!((({ operator_gt_3(b, a,) }) == 5)); assert!((({ operator_le_4(a, c,) }) == 6)); assert!((({ operator_ge_5(a, c,) }) == 7)); @@ -368,16 +342,51 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); assert!( ({ - let mut __tmp_3 = { ris.decay().offset((2) as isize) }; - let mut __it = ris.decay(); - while __it != __tmp_3 && !CppEq::equal(__it.iter_deref(), ri2.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ris.decay())); + let __last: Value> = + Rc::new(RefCell::new(ris.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + ri2.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } == ris.decay()) ); return 0; } +impl WeaklyEqualityComparableWith for Boolish { + fn equal(a: Ptr, b: Ptr) -> bool { + { + let __cmp = operator_eq_7(a.read(), b.read()); + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) + } + } +} +impl WeaklyEqualityComparableWith for Mixed { + fn equal(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_eq(this.clone(), o.clone())) != 0) + } +} +impl WeaklyEqualityComparableWith for RefInt { + fn equal(this: Ptr, _a0: Ptr) -> bool { + { + let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); + RefBool::to_bool(__cmp.clone()) + } + } +} +impl WeaklyEqualityComparableWith for X { + fn not_equal(a: Ptr, b: Ptr) -> bool { + ((operator_ne_0(a.read(), b.read())) != 0) + } + fn equal(a: Ptr, b: Ptr) -> bool { + ((operator_eq_2(a.read(), b.read())) != 0) + } +} pub fn __cpp2rust_init_globals() { let _ = ref_true_8.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 7edce8d200..8d00d4fb59 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -6,10 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); -} -pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } #[derive( @@ -35,13 +32,8 @@ impl S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_0(x.clone(), y.clone()) } } pub fn main() { @@ -52,9 +44,14 @@ fn main_0() -> i32 { object!(a, S(1)); object!(b, S(2)); object!(c, S(1)); - assert!(({ operator_eq_0(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_lt_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_lt_1(b.as_pointer(), a.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 7355fb70d4..84cd7bd9af 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -6,10 +6,6 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) - && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); -} #[derive( Copy, Clone, @@ -29,12 +25,7 @@ pub struct Defaulted { #[offset(4)] pub b: i32, } -impl CppEq for Defaulted { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { +pub fn operator_cmp_0(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( &(_a0.with(|__s| __s.a)), @@ -46,9 +37,6 @@ pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cm } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } -pub fn operator_eq_2(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); -} #[derive( Copy, Clone, @@ -67,22 +55,14 @@ pub struct DefaultedOrd { pub a: i32, } impl CppLess for DefaultedOrd { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_cmp_1(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for DefaultedOrd { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) + fn less(_a0: Ptr, _a1: Ptr) -> bool { + operator_cmp_0(_a0.clone(), _a1.clone()) == std::cmp::Ordering::Less } } -pub fn operator_eq_3(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); -} -pub fn operator_lt_4(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); } -pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { +pub fn operator_add_2(x: Ptr, y: Ptr) -> Inline { return Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; @@ -105,13 +85,8 @@ pub struct Inline { pub a: i32, } impl CppLess for Inline { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Inline { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_3(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_1(x.clone(), y.clone()) } } #[derive( @@ -131,26 +106,9 @@ pub struct OutOfLine { #[offset(0)] pub a: i32, } -impl CppEq for OutOfLine { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_6(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_eq_6(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); -} -pub fn operator_ne_7(x: Ptr, y: Ptr) -> bool { - return !({ operator_eq_6((x).clone(), (y).clone()) }); -} -pub fn operator_eq_8(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); -} -pub fn operator_lt_9(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_3(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); } -pub fn operator_eq_10(x: Ptr, y: Ptr) -> bool { - return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -169,13 +127,8 @@ pub struct Tmpl_int_ { pub v: i32, } impl CppLess for Tmpl_int_ { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_9(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Tmpl_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_8(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_3(x.clone(), y.clone()) } } #[derive( @@ -195,9 +148,6 @@ pub struct Tmpl_long_ { #[offset(0)] pub v: i64, } -pub fn operator_eq_11(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -215,11 +165,6 @@ pub struct TmplDefaulted_int_ { #[offset(0)] pub v: i32, } -impl CppEq for TmplDefaulted_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_11(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -228,56 +173,100 @@ fn main_0() -> i32 { let d1: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d2: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d3: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 3 })); - assert!(({ operator_eq_0(d1.as_pointer(), d2.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(DefaultedOrd { a: 1 })); let o2: Value = Rc::new(RefCell::new(DefaultedOrd { a: 2 })); - assert!(({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); - assert!(({ operator_cmp_1(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); - assert!(({ operator_eq_2(o1.as_pointer(), o1.as_pointer(),) })); + assert!(({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); + assert!(({ operator_cmp_0(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); + assert!(({ WeaklyEqualityComparableWith::equal(o1.as_pointer(), o1.as_pointer(),) })); assert!( - ({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) + ({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); let i1: Value = Rc::new(RefCell::new(Inline { a: 1 })); let i2: Value = Rc::new(RefCell::new(Inline { a: 2 })); let i3: Value = Rc::new(RefCell::new(Inline { a: 1 })); - assert!(({ operator_eq_3(i1.as_pointer(), i3.as_pointer(),) })); - assert!(!({ operator_eq_3(i1.as_pointer(), i2.as_pointer(),) })); - assert!(({ operator_lt_4(i1.as_pointer(), i2.as_pointer(),) })); - assert!(!({ operator_lt_4(i2.as_pointer(), i1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i2.as_pointer(),) })); + assert!(({ operator_lt_1(i1.as_pointer(), i2.as_pointer(),) })); + assert!(!({ operator_lt_1(i2.as_pointer(), i1.as_pointer(),) })); assert!( ({ let _x: Value = Rc::new(RefCell::new( - ({ operator_add_5(i1.as_pointer(), i2.as_pointer()) }), + ({ operator_add_2(i1.as_pointer(), i2.as_pointer()) }), )); let _y: Value = Rc::new(RefCell::new(Inline { a: 3 })); - operator_eq_3(_x.as_pointer(), _y.as_pointer()) + WeaklyEqualityComparableWith::equal(_x.as_pointer(), _y.as_pointer()) }) ); let f1: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f2: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f3: Value = Rc::new(RefCell::new(OutOfLine { a: 5 })); - assert!(({ operator_eq_6(f1.as_pointer(), f2.as_pointer(),) })); - assert!(({ operator_ne_7(f1.as_pointer(), f3.as_pointer(),) })); - assert!(!({ operator_eq_6(f1.as_pointer(), f3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(f1.as_pointer(), f3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f3.as_pointer(),) })); let t1: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); let t2: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 2 })); let t3: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); - assert!(({ operator_eq_8(t1.as_pointer(), t3.as_pointer(),) })); - assert!(!({ operator_eq_8(t1.as_pointer(), t2.as_pointer(),) })); - assert!(({ operator_lt_9(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ operator_lt_3(t1.as_pointer(), t2.as_pointer(),) })); let u1: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 1_i64 })); let u2: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 2_i64 })); - assert!(({ operator_eq_10(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ operator_eq_10(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u2.as_pointer(),) })); let v1: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v2: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v3: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 8 })); - assert!(({ operator_eq_11(v1.as_pointer(), v2.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for Defaulted { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) + && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for DefaultedOrd { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Inline { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for OutOfLine { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } + fn not_equal(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); + } +} +impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Tmpl_long_ { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index e62ec942fc..47bb4adc05 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -33,14 +33,8 @@ impl Pair { } } impl CppLess for Pair { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Pair::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Pair { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Pair::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Pair::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, other: Ptr) -> bool { + Pair::operator_lt(this.clone(), other.clone()) } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 993d253862..54907d11aa 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -33,18 +33,10 @@ impl S { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } pub fn main() { @@ -58,11 +50,16 @@ fn main_0() -> i32 { assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less); - assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); assert!( ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 8aa303c76d..7d3202e71e 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -29,14 +29,8 @@ impl Lt { } } impl CppLess for Lt { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Lt::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Lt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Lt::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Lt::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, o: Ptr) -> bool { + Lt::operator_lt(this.clone(), o.clone()) } } #[derive( @@ -56,16 +50,6 @@ pub struct Eq { #[offset(0)] pub v: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -87,18 +71,10 @@ impl Cmp { pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -119,21 +95,13 @@ pub struct Free { pub v: i32, } impl CppLess for Free { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Free { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -183,40 +151,54 @@ fn main_0() -> i32 { let nine: Value = Rc::new(RefCell::new(Eq { v: 9 })); assert!( ({ - let mut __tmp_1 = { eqs.decay().begin() }; - let mut __tmp_2 = { eqs.decay().end() }; - let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && !CppEq::equal(__it.iter_deref(), two.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + two.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) == 2) ); - assert!( - { - let mut __tmp_3 = { eqs.decay().begin() }; - let mut __tmp_4 = { eqs.decay().end() }; - let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && !CppEq::equal(__it.iter_deref(), nine.as_pointer().clone()) { - __it.iter_inc(); + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + nine.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it - } == eqs.decay().end() - ); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(eqs.decay().end())).as_pointer(), + ) { + (__tmp_1, __tmp_2) => { + WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_2).clone()) + } + }); let cmps: Value> = Rc::new(RefCell::new(Vec::from([ Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }, ]))); { - let mut __tmp_5 = { cmps.decay().begin() }; - let __n = cmps.decay().end().iter_distance(&__tmp_5); + let mut __tmp_3 = { cmps.decay().begin() }; + let __n = cmps.decay().end().iter_distance(&__tmp_3); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); - reorder(__order, |__i| __tmp_5.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_3.iter_at(__x), &__tmp_3.iter_at(__y))); + reorder(__order, |__i| __tmp_3.iter_at(__i)); }; assert!( ({ { (*cmps.borrow())[0_usize] }.v } == 1) && ({ { (*cmps.borrow())[2_usize] }.v } == 3) @@ -224,13 +206,19 @@ fn main_0() -> i32 { let three: Value = Rc::new(RefCell::new(Cmp { v: 3 })); assert!( ({ - let mut __tmp_6 = { cmps.decay().begin() }; - let mut __tmp_7 = { cmps.decay().end() }; - let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && !CppEq::equal(__it.iter_deref(), three.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(cmps.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(cmps.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + three.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -238,23 +226,29 @@ fn main_0() -> i32 { ); let frees: Value> = Rc::new(RefCell::new(Vec::from([Free { v: 2 }, Free { v: 1 }]))); { - let mut __tmp_8 = { frees.decay().begin() }; - let __n = frees.decay().end().iter_distance(&__tmp_8); + let mut __tmp_4 = { frees.decay().begin() }; + let __n = frees.decay().end().iter_distance(&__tmp_4); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_8.iter_at(__x), &__tmp_8.iter_at(__y))); - reorder(__order, |__i| __tmp_8.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_4.iter_at(__x), &__tmp_4.iter_at(__y))); + reorder(__order, |__i| __tmp_4.iter_at(__i)); }; assert!(({ { (*frees.borrow())[0_usize] }.v } == 1)); let ftwo: Value = Rc::new(RefCell::new(Free { v: 2 })); assert!( ({ - let mut __tmp_9 = { frees.decay().begin() }; - let mut __tmp_10 = { frees.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && !CppEq::equal(__it.iter_deref(), ftwo.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(frees.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(frees.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + ftwo.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -262,14 +256,14 @@ fn main_0() -> i32 { ); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_11,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_11, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_5,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(Lt { v: 1 })).as_pointer(),) { - (__tmp_12,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_12, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_6,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); @@ -286,8 +280,8 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_13,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_13, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_7,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -295,4 +289,19 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Free { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index c049702916..d100808c4b 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -86,12 +86,12 @@ pub fn push_local_from_field_1(mut jpg: Ptr, mut cond: bool) { dest = (field_ref!(jpg, app_data).as_pointer()); } match (Rc::new(RefCell::new({ - let mut __tmp_2 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_2 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v })) @@ -117,12 +117,13 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { { dest.with_mut(|__v: &mut Vec>| { __v.push({ - let mut __tmp_3 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = + Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }) @@ -131,9 +132,9 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { } pub fn nested_emplace_move_5(mut bw: Ptr) { { - let mut __tmp_4 = { bw.with(|__s| __s.output.clone()) }; - let mut __tmp_5 = { bw.with(|__s| __s.chunk) }; - __tmp_4.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); + let mut __tmp_2 = { bw.with(|__s| __s.output.clone()) }; + let mut __tmp_3 = { bw.with(|__s| __s.chunk) }; + __tmp_2.with_mut(|__v: &mut Vec| __v.push(__tmp_3)); }; } pub fn self_ref_push_6(mut comps: Ptr>) { @@ -188,36 +189,36 @@ pub fn emplace_ctor_args_7(mut pairs: Ptr>) { }); }; { - let mut __tmp_6 = { + let mut __tmp_4 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_4)); }; { - let mut __tmp_7 = { + let mut __tmp_5 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 4, 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_7)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); }; } pub fn emplace_deque_8(mut queue: Ptr>) { { - let mut __tmp_8 = { + let mut __tmp_6 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 6, 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - queue.with_mut(|__v: &mut Vec| __v.push(__tmp_8)); + queue.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); }; { queue.with_mut(|__v: &mut Vec| { @@ -240,7 +241,7 @@ pub fn emplace_scalar_9(mut values: Ptr>, x: i32) { } pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { let p: Ptr = { - let mut __tmp_9 = { + let mut __tmp_7 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); @@ -248,7 +249,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_9); + (*__b0).push(__tmp_7); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -257,7 +258,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { { field!( { - let mut __tmp_10 = { + let mut __tmp_8 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 4); @@ -265,7 +266,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_10); + (*__b0).push(__tmp_8); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -284,15 +285,15 @@ pub fn emplace_addr_11(values: Ptr>) -> Ptr { } pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr>) { { - let mut __tmp_11 = { (((*values.upgrade().deref()).len()) as i64) }; - values.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); + let mut __tmp_9 = { (((*values.upgrade().deref()).len()) as i64) }; + values.with_mut(|__v: &mut Vec| __v.push(__tmp_9)); }; { - let mut __tmp_12 = { index!(pairs, 0_usize).read() }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_12)); + let mut __tmp_10 = { index!(pairs, 0_usize).read() }; + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_10)); }; { - let mut __tmp_13 = { + let mut __tmp_11 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2( @@ -313,14 +314,14 @@ pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_13)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); }; } pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { return { - let mut __tmp_14 = { (values.decay().read()) }; + let mut __tmp_12 = { (values.decay().read()) }; values.with_mut(|__b0| { - (*__b0).push(__tmp_14); + (*__b0).push(__tmp_12); let __n = (*__b0).len() - 1; values.decay().offset((__n) as isize) }) @@ -368,19 +369,20 @@ impl Default for Bytes { pub fn emplace_from_element_14(mut v: Ptr>>) { let p: Value> = Rc::new(RefCell::new((v).decay().offset(0_usize).decay())); { - let mut __tmp_16 = { + let mut __tmp_13 = { { - let mut __tmp_15 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_15 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_16)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_13)); }; } #[derive( @@ -455,33 +457,34 @@ impl Counted { impl Counted {} pub fn emplace_counted_17(mut v: Ptr>) { { - let mut __tmp_17 = { + let mut __tmp_14 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Counted::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - v.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + v.with_mut(|__v: &mut Vec| __v.push(__tmp_14)); }; } pub fn emplace_from_sibling_18(mut s: Ptr) { let p: Value> = Rc::new(RefCell::new(array_field_ptr!(s, b))); let mut v: Ptr>> = (field_ref!(s, v).as_pointer()); { - let mut __tmp_19 = { + let mut __tmp_15 = { { - let mut __tmp_18 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_18 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_19)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_15)); }; } pub fn main() { @@ -638,14 +641,14 @@ fn main_0() -> i32 { let self_values: Value> = Rc::new(RefCell::new(Vec::from([7_i64]))); let self_pairs: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_20 = { + let mut __tmp_16 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*self_pairs.borrow_mut()).push(__tmp_20); + (*self_pairs.borrow_mut()).push(__tmp_16); }; ({ emplace_self_reads_12((self_values.as_pointer()), (self_pairs.as_pointer())) }); { diff --git a/tests/unit/out/refcount/redundant_copy_in_conversion.rs b/tests/unit/out/refcount/redundant_copy_in_conversion.rs index 9a972e2c1e..2d3679ec5b 100644 --- a/tests/unit/out/refcount/redundant_copy_in_conversion.rs +++ b/tests/unit/out/refcount/redundant_copy_in_conversion.rs @@ -11,9 +11,14 @@ pub fn sink_0(it: BidirectionalIterator<(Value, Value)>) -> i32 { let cit: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from(({ (*it.borrow()).clone() })), )); - return if (*cit.borrow()) - == , Value)>>::from(({ (*it.borrow()).clone() })) + return if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*it.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_0,) => WeaklyEqualityComparableWith::equal(cit.as_pointer(), (__tmp_0).clone()), + } { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) .1 .borrow()) @@ -28,8 +33,8 @@ pub fn main() { fn main_0() -> i32 { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(0)).as_pointer(),) { - (__tmp_0,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_i32) }) } } .write(1); @@ -39,23 +44,28 @@ fn main_0() -> i32 { )); let it0: Value, Value)>> = Rc::new(RefCell::new( ({ - let __tmp_1: Value = Rc::new(RefCell::new(0)); + let __tmp_2: Value = Rc::new(RefCell::new(0)); m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_1.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_2.as_pointer())) }), )); let const_it: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from(({ (*it0.borrow()).clone() })), )); - let mut r: i32 = if (*const_it.borrow()) - == , Value)>>::from(({ (*end.borrow()).clone() })) + let mut r: i32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*end.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_3,) => WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_3).clone()), + } { 0 } else { 1 }; r += ({ sink_0({ (*it0.borrow()).clone() }) }); - r += if (*end.borrow()) == (*end.borrow()) { + r += if WeaklyEqualityComparableWith::equal(end.as_pointer(), end.as_pointer()) { 0 } else { 1 @@ -68,7 +78,10 @@ fn main_0() -> i32 { >::from(({ (*middle.borrow()).clone() })), )); assert!(((({ (*const_middle.borrow()).iter_deref() }).read()) == 8_u32)); - assert!(({ (*const_middle.borrow()) == (*middle.borrow()) })); + assert!(WeaklyEqualityComparableWith::equal( + const_middle.as_pointer(), + middle.as_pointer() + )); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 28168bbd87..65ec82e18c 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -33,14 +33,14 @@ pub fn size_t_in_rules_3() { (0..3).map(|_| 0_usize).collect::>(), )); { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; - let mut __first = src.decay(); + let __first: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); let mut __out = (dst.decay()).reinterpret_cast::(); - while __first != __tmp_0 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as u64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as u64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -80,27 +80,39 @@ pub fn size_t_in_rules_3() { assert!((mx > mn)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_u64)).as_pointer(),) { - (__tmp_1,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_u64) }) } } .write(2_u64); let key: Value = Rc::new(RefCell::new(3_usize)); match ((key.as_pointer()).reinterpret_cast::(),) { - (__tmp_2,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) } } .write(4_u64); - assert!( - ({ - let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_3.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_3.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_2, __tmp_4) => { + WeaklyEqualityComparableWith::not_equal((__tmp_2).clone(), (__tmp_4).clone()) + } + }); assert!( ((*(*m .as_pointer() @@ -129,12 +141,12 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_4,) => ( + (__tmp_5,) => ( Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).0.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64), )), Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).1.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64), )), ), }, @@ -163,9 +175,9 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_5,) => { - let __first = (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64); - let __second = (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64); + (__tmp_6,) => { + let __first = (((*__tmp_6.upgrade().deref()).0.as_pointer().read()) as u64); + let __second = (((*__tmp_6.upgrade().deref()).1.as_pointer().read()) as u64); *(*p.borrow()).0.borrow_mut() = __first; *(*p.borrow()).1.borrow_mut() = __second; } @@ -191,18 +203,18 @@ pub fn size_t_in_rules_3() { let v: Value> = Rc::new(RefCell::new(Vec::from_fn(3_usize, |_| 0_u64))); (*v.borrow_mut()).resize_with(5_usize, || 0_u64); { - let mut __tmp_6 = { >::from(v.decay().begin()) }; + let mut __tmp_7 = { >::from(v.decay().begin()) }; v.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_6.index())); - (__tmp_6).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_7.index())); + (__tmp_7).clone() }; let mut v2: Vec = { - let mut __tmp_7 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_7 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; @@ -216,13 +228,13 @@ pub fn size_t_in_rules_3() { (*v.borrow_mut()).push(((*k.borrow()) as u64)); }; { - let mut __tmp_9 = { v.decay().begin() }; - let mut __tmp_10 = { v.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { - __it.iter_deref() + let __it: Value> = Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(v.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow() + .iter_deref() .write(Clone::clone(&({ ((*k.borrow()) as u64) }))); - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } }; Swappable::swap( @@ -230,13 +242,13 @@ pub fn size_t_in_rules_3() { (k.as_pointer()).reinterpret_cast::(), ); let mut big: usize = (({ - let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_10: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); (match (v.decay().offset(1_usize),) { - (__tmp_11,) => { - if CppLess::less((__tmp_11).clone().clone(), __tmp_12.as_pointer().clone()) { - __tmp_12.as_pointer() + (__tmp_9,) => { + if CppLess::less((__tmp_9).clone().clone(), __tmp_10.as_pointer().clone()) { + __tmp_10.as_pointer() } else { - (__tmp_11).clone() + (__tmp_9).clone() } } } @@ -252,14 +264,14 @@ pub fn size_t_in_rules_3() { .read()) as usize) }; { - let mut __tmp_13 = { + let mut __tmp_11 = { ( Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), ) }; let (__it, __inserted) = - Map::emplace(m2.as_pointer(), &__tmp_13.0.as_pointer(), || __tmp_13); + Map::emplace(m2.as_pointer(), &__tmp_11.0.as_pointer(), || __tmp_11); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -267,9 +279,9 @@ pub fn size_t_in_rules_3() { }; assert!( (((*(*({ - let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); m2.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_14.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_12.as_pointer())) }) .iter_deref() .upgrade() @@ -279,13 +291,13 @@ pub fn size_t_in_rules_3() { == (*k.borrow())) ); { - let __tmp_15: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_15.as_pointer(), || 0_u64) }) + let __tmp_13: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_13.as_pointer(), || 0_u64) }) } .write((big as u64)); let mv: Ptr = ({ - let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_16.as_pointer(), || 0_u64) }) + let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_14.as_pointer(), || 0_u64) }) }) .reinterpret_cast::(); mv.write(1_usize); @@ -303,34 +315,47 @@ pub fn size_t_in_rules_3() { ((*k.borrow()) as u64), ]))); ({ - let __tmp_18: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - let mut __tmp_17 = { >::from(v3.decay().begin()) }; - let __a2 = copy_constructed(__tmp_18.as_pointer()); - (*v3.borrow_mut()).insert(__tmp_17.index(), __a2); - (__tmp_17).clone() + let mut __tmp_15 = { >::from(v3.decay().begin()) }; + let __a2 = copy_constructed(__tmp_16.as_pointer()); + (*v3.borrow_mut()).insert(__tmp_15.index(), __a2); + (__tmp_15).clone() } }); ({ - let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_19.as_pointer().clone())) + let __tmp_17: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_17.as_pointer().clone())) }); - assert!( - ({ - let __tmp_22: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - { - let mut __tmp_20 = { v3.decay().begin() }; - let mut __tmp_21 = { v3.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), __tmp_22.as_pointer().clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(v3.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v3.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_19.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) != v3.decay().end() - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v3.decay().end())).as_pointer(), + ) { + (__tmp_18, __tmp_20) => { + WeaklyEqualityComparableWith::not_equal((__tmp_18).clone(), (__tmp_20).clone()) + } + }); assert!( ({ (((*v3.borrow()).len() == 5_usize) && (big >= (*k.borrow()))) @@ -385,37 +410,37 @@ fn main_0() -> i32 { let mut fr2: u64 = ({ take_ulong_1((sz as u64)) }); assert!((fr2 == 21_u64)); let mut lo: usize = (({ - let __tmp_23: Value = Rc::new(RefCell::new( + let __tmp_21: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); - let __tmp_24: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_23.as_pointer().clone(), __tmp_24.as_pointer().clone()) { - __tmp_23.as_pointer() + let __tmp_22: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_21.as_pointer().clone(), __tmp_22.as_pointer().clone()) { + __tmp_21.as_pointer() } else { - __tmp_24.as_pointer() + __tmp_22.as_pointer() } .read()) }) as usize); let mut hi: usize = (({ - let __tmp_25: Value = Rc::new(RefCell::new( + let __tmp_23: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if CppLess::less(__tmp_25.as_pointer().clone(), ul.as_pointer().clone()) { + (if CppLess::less(__tmp_23.as_pointer().clone(), ul.as_pointer().clone()) { ul.as_pointer() } else { - __tmp_25.as_pointer() + __tmp_23.as_pointer() } .read()) }) as usize); assert!((lo == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!((hi == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let mut bound: usize = (({ - let __tmp_26: Value = Rc::new(RefCell::new((4_usize as u64))); - let __tmp_27: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { - __tmp_26.as_pointer() + let __tmp_24: Value = Rc::new(RefCell::new((4_usize as u64))); + let __tmp_25: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_24.as_pointer().clone(), __tmp_25.as_pointer().clone()) { + __tmp_24.as_pointer() } else { - __tmp_27.as_pointer() + __tmp_25.as_pointer() } .read()) }) as usize); @@ -466,22 +491,22 @@ fn main_0() -> i32 { assert!((sm == 15_isize)); assert!((sm > (l as isize))); let mut smin: isize = (({ - let __tmp_28: Value = Rc::new(RefCell::new((sm as i64))); - let __tmp_29: Value = Rc::new(RefCell::new((sd as i64))); - (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { - __tmp_28.as_pointer() + let __tmp_26: Value = Rc::new(RefCell::new((sm as i64))); + let __tmp_27: Value = Rc::new(RefCell::new((sd as i64))); + (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { + __tmp_26.as_pointer() } else { - __tmp_29.as_pointer() + __tmp_27.as_pointer() } .read()) }) as isize); let mut smax: isize = (({ - let __tmp_30: Value = Rc::new(RefCell::new((sd as i64))); - let __tmp_31: Value = Rc::new(RefCell::new((sm as i64))); - (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { - __tmp_31.as_pointer() + let __tmp_28: Value = Rc::new(RefCell::new((sd as i64))); + let __tmp_29: Value = Rc::new(RefCell::new((sm as i64))); + (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { + __tmp_29.as_pointer() } else { - __tmp_30.as_pointer() + __tmp_28.as_pointer() } .read()) }) as isize); @@ -503,22 +528,22 @@ fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let __tmp_32: Value = Rc::new(RefCell::new((mx as u64))); - let __tmp_33: Value = Rc::new(RefCell::new(1_u64)); - (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { - __tmp_32.as_pointer() + let __tmp_30: Value = Rc::new(RefCell::new((mx as u64))); + let __tmp_31: Value = Rc::new(RefCell::new(1_u64)); + (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { + __tmp_30.as_pointer() } else { - __tmp_33.as_pointer() + __tmp_31.as_pointer() } .read()) }) as usize), (({ - let __tmp_34: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); - let __tmp_35: Value = Rc::new(RefCell::new((mx as u64))); - (if CppLess::less(__tmp_34.as_pointer().clone(), __tmp_35.as_pointer().clone()) { - __tmp_34.as_pointer() + let __tmp_32: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); + let __tmp_33: Value = Rc::new(RefCell::new((mx as u64))); + (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { + __tmp_32.as_pointer() } else { - __tmp_35.as_pointer() + __tmp_33.as_pointer() } .read()) }) as usize), diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 27aee2afb1..0fc9872366 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -51,14 +51,8 @@ impl MoveAssignable for Tracked { } } impl CppLess for Tracked { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Tracked { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_1(__lhs.clone(), __rhs.clone())) - && !(operator_lt_1(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } impl Default for Tracked { @@ -102,14 +96,8 @@ impl MoveOnly { } } impl CppLess for MoveOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_3(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for MoveOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_3(__lhs.clone(), __rhs.clone())) - && !(operator_lt_3(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_3(a.clone(), b.clone()) } } pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { @@ -131,21 +119,13 @@ impl DefaultConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_5(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); } -pub fn operator_eq_5(a: Ptr, b: Ptr) -> bool { - return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -441,37 +421,55 @@ fn main_0() -> i32 { }) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - assert!( - { - let mut __tmp_20 = { bag_vec.decay().begin() }; - let mut __tmp_21 = { bag_vec.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), bags.decay().offset(1).clone()) + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + bags.decay().offset(1).clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it - } == bag_vec.decay().begin().iter_add(1_isize) - ); - assert!( - { - let mut __tmp_22 = { bag_vec.decay().begin() }; - let mut __tmp_23 = { bag_vec.decay().end() }; - let mut __best = __tmp_22.clone(); - if __tmp_22 != __tmp_23 { - let mut __it = (__tmp_22).clone(); - __it.iter_inc(); - while __it != __tmp_23 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_21) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_21).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + let mut __best = __it.borrow().clone(); + if >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best - } == bag_vec.decay().begin().iter_add(2_isize) - ); + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(2_isize))).as_pointer(), + ) { + (__tmp_22, __tmp_23) => { + WeaklyEqualityComparableWith::equal((__tmp_22).clone(), (__tmp_23).clone()) + } + }); assert!( ((if CppLess::less( bags.decay().offset(2).clone(), @@ -517,64 +515,72 @@ fn main_0() -> i32 { .borrow()) == 2) ); - assert!( - bag_map - .as_pointer() - .with(|__m: &Map, Value)>| __m.find(&bags.decay().offset(1))) - == bag_map + assert!(match ( + Rc::new(RefCell::new(bag_map.as_pointer().with( + |__m: &Map, Value)>| __m.find(&bags.decay().offset(1)) + ))) + .as_pointer(), + Rc::new(RefCell::new( + bag_map .as_pointer() .with(|__m: &Map, Value)>| __m.end()) - ); + )) + .as_pointer(), + ) { + (__tmp_26, __tmp_27) => { + WeaklyEqualityComparableWith::equal((__tmp_26).clone(), (__tmp_27).clone()) + } + }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let moves: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_26 = { + let mut __tmp_28 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_26); + (*moves.borrow_mut()).push(__tmp_28); }; { - let mut __tmp_27 = { + let mut __tmp_29 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_27); + (*moves.borrow_mut()).push(__tmp_29); }; { - let mut __tmp_28 = { + let mut __tmp_30 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_28); + (*moves.borrow_mut()).push(__tmp_30); }; { - let mut __tmp_29 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_29); + let mut __tmp_31 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_31); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_29.iter_at(__x), &__tmp_29.iter_at(__y))); - reorder(__order, |__i| __tmp_29.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_31.iter_at(__x), &__tmp_31.iter_at(__y))); + reorder(__order, |__i| __tmp_31.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 1) && ({ (*moves.borrow())[1_usize].v } == 2)) && ({ (*moves.borrow())[2_usize].v } == 3) ); { - let mut __tmp_30 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_30); + let mut __tmp_32 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_32); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_30.iter_at(__x); - let __b = __tmp_30.iter_at(__y); + let __a = __tmp_32.iter_at(__x); + let __b = __tmp_32.iter_at(__y); if FnPtr::, Ptr) -> bool>::new( |a: Ptr, b: Ptr| -> bool { { @@ -599,7 +605,7 @@ fn main_0() -> i32 { std::cmp::Ordering::Equal } }); - reorder(__order, |__i| __tmp_30.iter_at(__i)); + reorder(__order, |__i| __tmp_32.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 3) && ({ (*moves.borrow())[1_usize].v } == 2)) @@ -607,6 +613,11 @@ fn main_0() -> i32 { ); return copies_0.with(|rc| *rc.borrow()); } +impl WeaklyEqualityComparableWith for Bag { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); + } +} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 45fdbba656..d27bbf3f5e 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -39,12 +39,14 @@ fn main_0() -> i32 { let output: Value> = Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::>())); { - let mut __tmp_0 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = output.decay(); - while __first != __tmp_0 { - __out.iter_deref().write((__first.iter_deref().read())); - __first.iter_inc(); + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { + __out + .iter_deref() + .write((__first.borrow().iter_deref().read())); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -55,14 +57,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_1 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = widened.decay().begin(); - while __first != __tmp_1 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as i64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as i64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -71,26 +73,28 @@ fn main_0() -> i32 { ({ (*widened.borrow())[0_usize] } == 1_i64) && ({ (*widened.borrow())[2_usize] } == 3_i64) ); let constructed: Value> = Rc::new(RefCell::new({ - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Degrees::construct(__tmp_3.as_pointer(), 0); - __tmp_3.as_pointer() + Degrees::construct(__tmp_1.as_pointer(), 0); + __tmp_1.as_pointer() },) { - (__tmp_2,) => (0..3_usize) - .map(|_| copy_constructed((__tmp_2).clone().clone())) + (__tmp_0,) => (0..3_usize) + .map(|_| copy_constructed((__tmp_0).clone().clone())) .collect(), } })); { - let mut __tmp_4 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = constructed.decay().begin(); - while __first != __tmp_4 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(>::cpp_from(__first.iter_deref())); - __first.iter_inc(); + .write(>::cpp_from( + __first.borrow().iter_deref(), + )); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -106,14 +110,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_5 = { wide.decay().offset((2) as isize) }; - let mut __first = wide.decay(); + let __first: Value> = Rc::new(RefCell::new(wide.decay())); + let __last: Value> = Rc::new(RefCell::new(wide.decay().offset((2) as isize))); let mut __out = floating.decay().begin(); - while __first != __tmp_5 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as f64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as f64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index bb899c8f52..125d536561 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -28,12 +28,13 @@ fn main_0() -> i32 { { let mut __tmp_0 = { RandomAccessIterator::Vec(str.decay()) }; let mut __tmp_1 = { RandomAccessIterator::Vec(str.decay().to_last()) }; - let mut __it = (__tmp_0).clone(); + let __it: Value> = Rc::new(RefCell::new(__tmp_0)); + let __last: Value> = Rc::new(RefCell::new(__tmp_1)); let __out = &mut (*ofs.borrow_mut()); let mut __bytes: Vec = Vec::new(); - while __it != __tmp_1 { - __bytes.push(__it.iter_deref().read() as u8); - __it.iter_inc(); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __bytes.push(__it.borrow().iter_deref().read() as u8); + __it.borrow_mut().iter_inc(); } __out.write_all(&__bytes); __out.try_clone().unwrap() diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 2f66920724..393e236257 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -55,26 +55,40 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { 'loop_: while (i < len) { 'for_body: { let it: Value> = Rc::new(RefCell::new({ - let mut __tmp_0 = { items.decay().begin() }; - let mut __tmp_1 = { items.decay().end() }; - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 - && !CppEq::equal(__it.iter_deref(), sigma.offset((i) as isize).clone()) - { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(items.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(items.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + sigma.offset((i) as isize).clone(), + ) { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() })); - assert!((*it.borrow()) != items.decay().end()); + assert!( + match (Rc::new(RefCell::new(items.decay().end())).as_pointer(),) { + (__tmp_0,) => { + WeaklyEqualityComparableWith::not_equal( + it.as_pointer(), + (__tmp_0).clone(), + ) + } + } + ); let __rhs = (((*it.borrow()).iter_distance(&items.decay().begin())) as u32); elem!(code, i).write(__rhs); { - let mut __tmp_2 = + let mut __tmp_1 = { >::from(({ (*it.borrow()).clone() })) }; items .as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_2.index())); - (__tmp_2).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_1.index())); + (__tmp_1).clone() }; } i.prefix_inc(); @@ -85,7 +99,11 @@ pub fn sum_4(v: Ptr>) -> i32 { let mut s: i32 = 0; { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { + 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_2,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_2).clone()) + } + } { 'for_body: { s += (({ (*it.borrow()).iter_deref() }).read()); } diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 47f5e85479..37f11f02c4 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -182,14 +182,13 @@ fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Vec::from([21, 22]))); { let mut __tmp_10 = { >::from(v2.decay().begin()) }; - let mut __tmp_11 = { src.decay().begin() }; - let mut __tmp_12 = { src.decay().end() }; let start_idx = __tmp_10.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(src.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } v2.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); @@ -201,27 +200,27 @@ fn main_0() -> i32 { assert!(({ (*v2.borrow())[1_usize] } == 22)); assert!(({ (*v2.borrow())[2_usize] } == 100)); { - let mut __tmp_13 = { >::from(v2.decay().begin()) }; + let mut __tmp_11 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); - (__tmp_13).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_11.index())); + (__tmp_11).clone() }; { - let mut __tmp_14 = { >::from(v2.decay().begin()) }; + let mut __tmp_12 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_14.index())); - (__tmp_14).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_12.index())); + (__tmp_12).clone() }; { let mut i: i32 = 0; 'loop_: while (i < 4) { 'for_body: { { - let mut __tmp_15 = + let mut __tmp_13 = { >::from(v2.decay().begin().iter_add(1_isize)) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_15.index())); - (__tmp_15).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); + (__tmp_13).clone() }; } i.prefix_inc(); @@ -436,11 +435,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_16 = { (idx as usize) }; - if __tmp_16 >= (*v6.borrow()).len() { + let mut __tmp_14 = { (idx as usize) }; + if __tmp_14 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_16) as isize) + v6.decay().offset((__tmp_14) as isize) } .read()) == 2_f64) @@ -449,22 +448,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; - if __tmp_17 >= (*v6.borrow()).len() { + let mut __tmp_15 = { (s2).wrapping_sub(1_usize) }; + if __tmp_15 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_17) as isize) + v6.decay().offset((__tmp_15) as isize) } .read()) == 5_f64) }) ); let ref1: Ptr = { - let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; - if __tmp_18 >= (*v6.borrow()).len() { + let mut __tmp_16 = { (s2).wrapping_sub(1_usize) }; + if __tmp_16 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_18) as isize) + v6.decay().offset((__tmp_16) as isize) }; { ref1.with_mut(|__v| *__v = *__v + 1.5_f64) @@ -472,22 +471,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; - if __tmp_19 >= (*v6.borrow()).len() { + let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; + if __tmp_17 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_19) as isize) + v6.decay().offset((__tmp_17) as isize) } .read()) == 6.5_f64) }) ); let mut x1: f64 = ({ - let mut __tmp_20 = { (s2).wrapping_sub(1_usize) }; - if __tmp_20 >= (*v6.borrow()).len() { + let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; + if __tmp_18 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_20) as isize) + v6.decay().offset((__tmp_18) as isize) } .read()); assert!((x1 == 6.5_f64)); @@ -495,11 +494,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_21 = { (s2).wrapping_sub(1_usize) }; - if __tmp_21 >= (*v6.borrow()).len() { + let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; + if __tmp_19 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_21) as isize) + v6.decay().offset((__tmp_19) as isize) } .read()) == 6.5_f64) @@ -522,15 +521,15 @@ fn main_0() -> i32 { let pa: Value> = Rc::new(RefCell::new((a.as_pointer()))); let v8: Value>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_22: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); - MoveConstructible::push_moved(&v8.as_pointer(), __tmp_22.as_pointer()) + let __tmp_20: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); + MoveConstructible::push_moved(&v8.as_pointer(), __tmp_20.as_pointer()) }); assert!(({ (((*v8.borrow())[0_usize].read()).with(|__s| __s.x) == 1) })); let ppa: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); let v9: Value>>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_23: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); - MoveConstructible::push_moved(&v9.as_pointer(), __tmp_23.as_pointer()) + let __tmp_21: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); + MoveConstructible::push_moved(&v9.as_pointer(), __tmp_21.as_pointer()) }); field!((((*v9.borrow())[0_usize].read()).read()), x).write(2); assert!(({ (*a.borrow()).x } == 2)); @@ -547,24 +546,24 @@ fn main_0() -> i32 { ); object!(foo, Foo); ({ - let __tmp_24: Value = Rc::new(RefCell::new(5)); + let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), a).as_pointer(), - __tmp_24.as_pointer(), + __tmp_22.as_pointer(), ) }); ({ - let __tmp_25: Value = Rc::new(RefCell::new(6)); + let __tmp_23: Value = Rc::new(RefCell::new(6)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_25.as_pointer(), + __tmp_23.as_pointer(), ) }); ({ - let __tmp_26: Value = Rc::new(RefCell::new(7)); + let __tmp_24: Value = Rc::new(RefCell::new(7)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_26.as_pointer(), + __tmp_24.as_pointer(), ) }); field_ref!(foo.as_pointer(), a) @@ -660,21 +659,21 @@ fn main_0() -> i32 { let v16: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5, 6, 7, 8]))); let mut after_v16: Vec = Vec::from([0]); let inserted: Value> = Rc::new(RefCell::new({ - let mut __tmp_27 = + let mut __tmp_25 = { >::from(v16.decay().begin().iter_add(1_isize)) }; let __a2 = 7; - (*v16.borrow_mut()).insert(__tmp_27.index(), __a2); - (__tmp_27).clone() + (*v16.borrow_mut()).insert(__tmp_25.index(), __a2); + (__tmp_25).clone() })); { ({ (*inserted.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) }; let nine: Value = Rc::new(RefCell::new(9)); let inserted_copy: Value> = Rc::new(RefCell::new({ - let mut __tmp_28 = { >::from(v16.decay().begin()) }; + let mut __tmp_26 = { >::from(v16.decay().begin()) }; let __a2 = copy_constructed(nine.as_pointer()); - (*v16.borrow_mut()).insert(__tmp_28.index(), __a2); - (__tmp_28).clone() + (*v16.borrow_mut()).insert(__tmp_26.index(), __a2); + (__tmp_26).clone() })); { ({ (*inserted_copy.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) @@ -687,20 +686,20 @@ fn main_0() -> i32 { let ints: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); let longs: Value> = Rc::new(RefCell::new(Vec::from([10_i64, 20_i64]))); let pos: Value> = Rc::new(RefCell::new({ - let mut __tmp_29 = + let mut __tmp_27 = { >::from(longs.decay().begin().iter_add(1_isize)) }; - let mut __tmp_30 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_29.index(); + let start_idx = __tmp_27.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_30 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_29).clone() + (__tmp_27).clone() })); assert!( ({ @@ -712,39 +711,40 @@ fn main_0() -> i32 { ); let more: Value> = Rc::new(RefCell::new(Vec::from([4, 5]))); { - let mut __tmp_31 = { >::from(longs.decay().end()) }; - let mut __tmp_32 = { more.decay().begin() }; - let mut __tmp_33 = { more.decay().end() }; - let start_idx = __tmp_31.index(); + let mut __tmp_28 = { >::from(longs.decay().end()) }; + let start_idx = __tmp_28.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_32).clone(); - while __it != __tmp_33 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_31).clone() + (__tmp_28).clone() }; assert!( ({ ((*longs.borrow()).len() == 7_usize) && ({ (*longs.borrow())[6_usize] } == 5_i64) }) ); let doubles: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_34 = { >::from(doubles.decay().begin()) }; - let mut __tmp_35 = { ints.decay().offset((2) as isize) }; - let start_idx = __tmp_34.index(); + let mut __tmp_29 = { >::from(doubles.decay().begin()) }; + let start_idx = __tmp_29.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_35 { - temp_vec.push(((__it.iter_deref().read()) as f64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as f64)); + __it.borrow_mut().iter_inc(); } doubles.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_34).clone() + (__tmp_29).clone() }; assert!( ({ @@ -754,19 +754,21 @@ fn main_0() -> i32 { ); let wrapped: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_36 = { >::from(wrapped.decay().begin()) }; - let mut __tmp_37 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_36.index(); + let mut __tmp_30 = { >::from(wrapped.decay().begin()) }; + let start_idx = __tmp_30.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_37 { - temp_vec.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } wrapped.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_36).clone() + (__tmp_30).clone() }; assert!( ({ @@ -776,20 +778,21 @@ fn main_0() -> i32 { ); let same: Value> = Rc::new(RefCell::new(Vec::from([7]))); { - let mut __tmp_38 = { >::from(same.decay().begin()) }; - let mut __tmp_39 = { more.decay().begin() }; - let mut __tmp_40 = { more.decay().end() }; - let start_idx = __tmp_38.index(); + let mut __tmp_31 = { >::from(same.decay().begin()) }; + let start_idx = __tmp_31.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_39).clone(); - while __it != __tmp_40 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } same.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_38).clone() + (__tmp_31).clone() }; assert!( ({ diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 688722f1c7..939b203404 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -61,36 +61,36 @@ pub fn main() { fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v1: Vec = { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_0 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v1.len() == 3_usize)); assert!(((v1[0_usize] == 1_u32) && (v1[1_usize] == 2_u32)) && (v1[2_usize] == 3_u32)); let mut v2: Vec = { - let mut __tmp_1 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_1 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v2.len() == 3_usize)); assert!(((v2[0_usize] == 1_u64) && (v2[1_usize] == 2_u64)) && (v2[2_usize] == 3_u64)); let mut v3: Vec = { - let mut __tmp_2 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_2 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -98,12 +98,12 @@ fn main_0() -> i32 { assert!(((v3[0_usize] == 1) && (v3[1_usize] == 2)) && (v3[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v4: Vec = { - let mut __tmp_3 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -117,12 +117,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v5: Vec = { - let mut __tmp_4 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_4 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -130,40 +130,42 @@ fn main_0() -> i32 { assert!(((v5[0_usize] as i32) == 10) && ((v5[4_usize] as i32) == 50)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_5,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_6,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_7,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_2,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); let v6: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_8 = { + let mut __v = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_9 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let mut __v = Vec::new(); - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while , Value)>>::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { __v.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } __v })); @@ -181,34 +183,36 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_10 = { + let mut __tmp_3 = { , Value)>>::from( v6.decay().begin().iter_add(1_isize), ) }; - let mut __tmp_11 = { + let start_idx = __tmp_3.index(); + let mut temp_vec: Vec<(Value, Value)> = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_12 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let start_idx = __tmp_10.index(); - let mut temp_vec: Vec<(Value, Value)> = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while , Value)>>::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { temp_vec.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } v6.as_pointer() .with_mut(|v: &mut Vec<(Value, Value)>| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_10).clone() + (__tmp_3).clone() }; assert!(({ ((*v6.borrow()).len() == 6_usize) })); assert!( @@ -220,12 +224,14 @@ fn main_0() -> i32 { ); let ints: Value> = Rc::new(RefCell::new(Box::new([4, 5, 6]))); let mut v7: Vec = { - let mut __tmp_13 = { ints.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_13 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -235,12 +241,15 @@ fn main_0() -> i32 { Reading { raw_: 5 }, ]))); let mut v8: Vec = { - let mut __tmp_14 = { readings.decay().offset((2) as isize) }; let mut __v = Vec::new(); - let mut __it = readings.decay(); - while __it != __tmp_14 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(readings.decay())); + let __last: Value> = + Rc::new(RefCell::new(readings.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 140a20b210..6020baa986 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -398,36 +398,36 @@ fn main_0() -> i32 { ({ fn_1(v7.as_pointer(), copy_constructed(v8.as_pointer())) }); let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v9: Vec = { - let mut __tmp_22 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_22 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v9.len() == 3_usize)); assert!(((v9[0_usize] == 1_u32) && (v9[1_usize] == 2_u32)) && (v9[2_usize] == 3_u32)); let mut v10: Vec = { - let mut __tmp_23 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_23 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v10.len() == 3_usize)); assert!(((v10[0_usize] == 1_u64) && (v10[1_usize] == 2_u64)) && (v10[2_usize] == 3_u64)); let mut v11: Vec = { - let mut __tmp_24 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_24 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -435,12 +435,12 @@ fn main_0() -> i32 { assert!(((v11[0_usize] == 1) && (v11[1_usize] == 2)) && (v11[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v12: Vec = { - let mut __tmp_25 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_25 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -451,12 +451,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v13: Vec = { - let mut __tmp_26 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_26 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index 8bb913f0e5..a1be7efaff 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -92,17 +92,7 @@ impl Counter { (*(&raw const (*this).calls).cast_mut()).prefix_inc(); return (*this).v; } - pub unsafe fn operator_eq(this: *const Self, o: *const Counter) -> bool { - (*(&raw const (*this).calls).cast_mut()).prefix_inc(); - return (((*this).v) == ((*o).v)); - } -} -impl std::cmp::PartialEq for Counter { - fn eq(&self, other: &Self) -> bool { - unsafe { Counter::operator_eq(self, other as *const Counter) } - } } -impl std::cmp::Eq for Counter {} #[repr(C)] #[derive( Copy, @@ -180,8 +170,8 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Counter::Get(&raw const c1,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const c2,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const (*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, &c2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; @@ -194,4 +184,10 @@ unsafe fn main_0() -> i32 { assert!(((ct.calls) == (10))); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Counter { + unsafe fn equal(this: *const Self, o: *const Counter) -> bool { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index 3903828475..313f7890e5 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -32,7 +32,7 @@ pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut total: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { + 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { 'for_body: { total += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 0c83840e9f..3f21fe6fe3 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -384,7 +384,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { vec_.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(>::cpp_from( __it.iter_deref(), )); diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 6593f96610..8c01e80d11 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -26,12 +26,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { v.begin() }; let mut __tmp_3 = { v.end() }; let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 7 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) + { __it.iter_inc(); } __it }; - assert!(it != v.end()); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end())); assert!(((*it.iter_deref()) == (7))); { let mut __tmp_4 = { v.begin() }; diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index 7151a6602f..6547e096ea 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { (&mut (*alias))[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/emplace_receiver_order.rs b/tests/unit/out/unsafe/emplace_receiver_order.rs index 10824fecc1..d10debc89e 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -63,7 +63,8 @@ unsafe fn main_0() -> i32 { { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_3; - while __it != __tmp_4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) + { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 62eb6c3e8c..3861d5282c 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,17 +20,6 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl P { - pub unsafe fn operator_eq(this: *const Self, o: *const P) -> bool { - return (((*this).x) == ((*o).x)); - } -} -impl std::cmp::PartialEq for P { - fn eq(&self, other: &Self) -> bool { - unsafe { P::operator_eq(self, other as *const P) } - } -} -impl std::cmp::Eq for P {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -56,12 +45,14 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it }; - let mut v_result_true: bool = it != v.end(); + let mut v_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end()); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_4: i32; @@ -86,65 +77,87 @@ unsafe fn main_0() -> i32 { }; let mut m_begin: UnsafeBidirectionalIterator<(i32, f64)> = m.begin(); let mut m_end: UnsafeBidirectionalIterator<(i32, f64)> = m.end(); - let mut m_result_true: bool = m_begin != m_end; + let mut m_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&m_begin, &m_end); assert!( ((v_result_true) && (m_result_true)) - && ({ - let mut __tmp_7 = { v.begin() }; - let mut __tmp_8 = { v.begin() }; - let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != 2 { - __it.iter_inc(); - } - __it - } == v.begin()) + && (WeaklyEqualityComparableWithUnsafe::equal( + &{ + let mut __tmp_7 = { v.begin() }; + let mut __tmp_8 = { v.begin() }; + let mut __it = (__tmp_7).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { + __it.iter_inc(); + } + __it + }, + &v.begin() + )) ); let mut w: Vec = Vec::from([1, 2, 3, 4, 5]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != 4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) + { __it.iter_inc(); } __it - } == w.begin().iter_add(3_isize) - ); - assert!( - { + }, + &w.begin().iter_add(3_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 && *__it.iter_deref() != 1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_12) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) + { __it.iter_inc(); } __it - } == w.end() - ); - assert!( - { + }, + &w.end() + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while __it != __tmp_14 && *__it.iter_deref() != 5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) + { __it.iter_inc(); } __it - } == w.begin().iter_add(4_isize) - ); + }, + &w.begin().iter_add(4_isize) + )); let mut p: Vec

= Vec::from([P { x: 0 }, P { x: 1 }, P { x: 2 }]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while __it != __tmp_16 && *__it.iter_deref() != (P { x: 1 }) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) + { __it.iter_inc(); } __it - } == p.begin().iter_add(1_isize) - ); + }, + &p.begin().iter_add(1_isize) + )); return 0; } +impl WeaklyEqualityComparableWithUnsafe for P { + unsafe fn equal(this: *const Self, o: *const P) -> bool { + return (((*this).x) == ((*o).x)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index d1636d2ed8..54853b5c19 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -9,13 +9,10 @@ use std::rc::Rc; pub unsafe fn get_0(v: *const V) -> i32 { return (*v).x; } -pub unsafe fn operator_eq_1(a: *const V, b: *const V) -> bool { - return (((*a).x) == ((*b).x)); -} -pub unsafe fn scaled_2(v: *const V, mut k: i32) -> i32 { +pub unsafe fn scaled_1(v: *const V, mut k: i32) -> i32 { return (((*v).x) * (k)); } -pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { +pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { return (((*v).x as f64) * (k)); } #[repr(C)] @@ -32,13 +29,7 @@ pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { pub struct V { pub x: i32, } -impl std::cmp::PartialEq for V { - fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const V, other as *const V) } - } -} -impl std::cmp::Eq for V {} -pub unsafe fn get_4(w: *const W_int_) -> i32 { +pub unsafe fn get_3(w: *const W_int_) -> i32 { return (*w).x; } #[repr(C)] @@ -55,7 +46,7 @@ pub unsafe fn get_4(w: *const W_int_) -> i32 { pub struct W_int_ { pub x: i32, } -pub unsafe fn get_5(w: *const W_long_) -> i64 { +pub unsafe fn get_4(w: *const W_long_) -> i64 { return (*w).x; } #[repr(C)] @@ -86,7 +77,7 @@ pub struct W_long_ { pub struct D { pub x: i32, } -pub unsafe fn declared_then_defined_6(d: *const D) -> i32 { +pub unsafe fn declared_then_defined_5(d: *const D) -> i32 { return (((*d).x) + (1)); } pub fn main() { @@ -103,23 +94,28 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const V = &a; - operator_eq_1(_a, &b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &b) }) ); assert!( !(unsafe { let _a: *const V = &a; - operator_eq_1(_a, &c) + WeaklyEqualityComparableWithUnsafe::equal(_a, &c) }) ); - assert!(((unsafe { scaled_2(&c, 2,) }) == (8))); - assert!(((unsafe { scaled_3(&c, 1.5_f64,) }) == (6_f64))); + assert!(((unsafe { scaled_1(&c, 2,) }) == (8))); + assert!(((unsafe { scaled_2(&c, 1.5_f64,) }) == (6_f64))); let mut wi: W_int_ = W_int_ { x: 5 }; let mut wl: W_long_ = W_long_ { x: 6_i64 }; - assert!(((unsafe { get_4(&wi,) }) == (5))); - assert!(((unsafe { get_5(&wl,) }) == (6_i64))); + assert!(((unsafe { get_3(&wi,) }) == (5))); + assert!(((unsafe { get_4(&wl,) }) == (6_i64))); let mut d: D = D { x: 7 }; - assert!(((unsafe { declared_then_defined_6(&d,) }) == (8))); + assert!(((unsafe { declared_then_defined_5(&d,) }) == (8))); return 0; } +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn equal(a: *const V, b: *const V) -> bool { + return (((*a).x) == ((*b).x)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index b1c75afbca..bafffe08be 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -216,26 +216,31 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeBidirectionalIterator<(i16, u32)> = m.find(&1_i16); let mut const_it: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&10_i16)); - let mut x1: u32 = if it == end { + let mut x1: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &end) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x1) == (4_u32))); - let mut x2: u32 = if const_it == >::from((end).clone()) - { + let mut x2: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from((end).clone()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 }; assert!(((x2) == (0_u32))); - let mut x3: u32 = if it == m.end() { + let mut x3: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &m.end()) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x3) == (4_u32))); - let mut x4: u32 = if const_it == >::from(m.end()) { + let mut x4: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from(m.end()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 @@ -281,10 +286,16 @@ unsafe fn main_0() -> i32 { assert!((((*const_it4.iter_deref()).1) == (6_u32))); let r: *mut UnsafeMap = &mut m; assert!((((*r).len()) == (4_usize))); - assert!(m.find(&4_i16) != m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &m.find(&4_i16), + &m.end() + )); (*r).erase(&(it4).clone()); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&4_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&4_i16), + &m.end() + )); { let mut __tmp_21: i16; (*{ @@ -314,13 +325,19 @@ unsafe fn main_0() -> i32 { let mut cit: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&7_i16)); let mut next: UnsafeBidirectionalIterator<(i16, u32)> = m.erase(&(cit).clone()); - assert!(next == m.find(&8_i16)); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &next, + &m.find(&8_i16) + )); { next = m.erase(&(next).clone()); }; - assert!(next == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal(&next, &m.end())); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&8_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&8_i16), + &m.end() + )); let mut other_map: UnsafeMap<(i32, i64), ((i32, i64), f64)> = UnsafeMap::new(); assert!(((other_map.len()) == (0_usize))); let mut key0: (i32, i64) = (1, (1 as i64)); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3db77d5c8f..019299a70c 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -40,9 +40,9 @@ impl MoveConstructibleUnsafe for Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Key::operator_lt(self, other as *const Key) { + if Key::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Key::operator_lt(other, self as *const Key) { + } else if Key::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -58,8 +58,8 @@ impl std::cmp::PartialOrd for Key { impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { unsafe { - !(Key::operator_lt(self, other as *const Key)) - && !(Key::operator_lt(other, self as *const Key)) + !(Key::operator_lt((self as *const Self), (other as *const Self))) + && !(Key::operator_lt((other as *const Self), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 62f5ce6810..8d6e5b77e7 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -26,9 +26,9 @@ pub struct Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Key, other as *const Key) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Key, self as *const Key) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -43,16 +43,15 @@ impl std::cmp::PartialOrd for Key { } impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const Key, other as *const Key) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Key {} pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { return (((*a).order) < ((*b).order)); } -pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { - return (((*a).identity) == ((*b).identity)); -} #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] pub struct Mapped { @@ -94,7 +93,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); @@ -116,15 +115,21 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; - ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; - ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; - ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&a_it, &distinct.find(&distinct_a))) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.find(&distinct_b))) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&b_it, &distinct.end())) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct_count: usize = 0_usize; @@ -153,7 +158,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -173,10 +178,23 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (reused as i32)) != 0; ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&first_it, &equivalent.end())) + as i32)) + != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_b), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -197,7 +215,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let later_key: Key = Key { @@ -212,7 +230,12 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -249,7 +272,10 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_b))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; @@ -261,13 +287,21 @@ unsafe fn main_0() -> i32 { == ((before_matching) + (2))) as i32)) != 0; ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_a))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWithUnsafe for Key { + unsafe fn equal(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const default_constructions_0); } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 50b537fdfa..a752caad76 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -209,7 +209,11 @@ unsafe fn main_0() -> i32 { & ((((result.1) as i32) == (!(hit) as i32)) as i32)) != 0; - let mut found: bool = result.0 == m.find(&key); + let mut found: bool = + WeaklyEqualityComparableWithUnsafe::equal( + &result.0, + &m.find(&key), + ); ok = ((ok as i32) & (found as i32)) != 0; ok = ((ok as i32) & ((((*result.0.iter_deref()).0) == (key)) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 2418d926f2..2a504984cd 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -47,9 +47,9 @@ impl CopyConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -65,8 +65,8 @@ impl std::cmp::PartialOrd for Bag { impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_4(self as *const Bag, other as *const Bag)) - && !(operator_lt_4(other as *const Bag, self as *const Bag)) + !(operator_lt_4((self as *const Self), (other as *const Self))) + && !(operator_lt_4((other as *const Self), (self as *const Self))) } } } @@ -126,10 +126,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { values.as_mut_ptr() }; let mut __tmp_3 = { values.as_mut_ptr().offset((4) as isize) }; let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_2, &__tmp_3) { let mut __it = __tmp_2; __it.iter_inc(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 3ed17b1d67..466114ab9f 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,17 +21,6 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Eq) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } -} -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, @@ -63,13 +52,10 @@ impl Cmp { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Cmp) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -79,7 +65,10 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) == std::cmp::Ordering::Equal } + unsafe { + Cmp::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Cmp {} @@ -98,9 +87,6 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Both) -> bool { - return (((*this).a) == ((*_a0).a)); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Both) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -113,7 +99,7 @@ impl Both { } impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Both::operator_cmp(self, other as *const Both) } + unsafe { Both::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Both { @@ -123,7 +109,9 @@ impl std::cmp::PartialOrd for Both { } impl std::cmp::PartialEq for Both { fn eq(&self, other: &Self) -> bool { - unsafe { Both::operator_eq(self, other as *const Both) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Both {} @@ -154,7 +142,7 @@ impl OrdOnly { } impl std::cmp::Ord for OrdOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) } + unsafe { OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for OrdOnly { @@ -164,7 +152,10 @@ impl std::cmp::PartialOrd for OrdOnly { } impl std::cmp::PartialEq for OrdOnly { fn eq(&self, other: &Self) -> bool { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) == std::cmp::Ordering::Equal } + unsafe { + OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for OrdOnly {} @@ -192,13 +183,10 @@ impl Inner { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { - return (((*this).x) == ((*_a0).x)); - } } impl std::cmp::Ord for Inner { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Inner::operator_cmp(self, other as *const Inner) } + unsafe { Inner::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Inner { @@ -208,7 +196,10 @@ impl std::cmp::PartialOrd for Inner { } impl std::cmp::PartialEq for Inner { fn eq(&self, other: &Self) -> bool { - unsafe { Inner::operator_cmp(self, other as *const Inner) == std::cmp::Ordering::Equal } + unsafe { + Inner::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Inner {} @@ -246,16 +237,10 @@ impl Outer { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Outer) -> bool { - return (unsafe { - let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&raw const (*this).i, _arg0) - }) && (((*this).y) == ((*_a0).y)); - } } impl std::cmp::Ord for Outer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Outer::operator_cmp(self, other as *const Outer) } + unsafe { Outer::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Outer { @@ -265,7 +250,10 @@ impl std::cmp::PartialOrd for Outer { } impl std::cmp::PartialEq for Outer { fn eq(&self, other: &Self) -> bool { - unsafe { Outer::operator_cmp(self, other as *const Outer) == std::cmp::Ordering::Equal } + unsafe { + Outer::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Outer {} @@ -284,12 +272,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Secondary) -> bool { - return (((*this).a) == ((*_a0).a)); - } - pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&raw const (*this), _a0) }); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -310,7 +292,7 @@ impl Secondary { } impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Secondary::operator_cmp(self, other as *const Secondary) } + unsafe { Secondary::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Secondary { @@ -320,7 +302,9 @@ impl std::cmp::PartialOrd for Secondary { } impl std::cmp::PartialEq for Secondary { fn eq(&self, other: &Self) -> bool { - unsafe { Secondary::operator_eq(self, other as *const Secondary) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Secondary {} @@ -348,13 +332,10 @@ impl PtrMember { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { - return (((*this).p) == ((*_a0).p)); - } } impl std::cmp::Ord for PtrMember { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { PtrMember::operator_cmp(self, other as *const PtrMember) } + unsafe { PtrMember::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for PtrMember { @@ -365,7 +346,8 @@ impl std::cmp::PartialOrd for PtrMember { impl std::cmp::PartialEq for PtrMember { fn eq(&self, other: &Self) -> bool { unsafe { - PtrMember::operator_cmp(self, other as *const PtrMember) == std::cmp::Ordering::Equal + PtrMember::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal } } } @@ -380,8 +362,8 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&raw const e1, &e3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e2,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; @@ -391,7 +373,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&raw const c1, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, _arg0) }) ); assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); @@ -401,7 +383,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&raw const b2, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; @@ -424,13 +406,13 @@ unsafe fn main_0() -> i32 { y: 9, }; assert!((unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const x1, &x3,) })); assert!( (unsafe { Outer::operator_cmp(&raw const x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER ); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { Secondary::operator_ne(&raw const s1, &s2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_lt(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_ge(&raw const s2, &s1,) })); assert!(!(unsafe { Secondary::operator_lt(&raw const s2, &s1,) })); @@ -445,11 +427,52 @@ unsafe fn main_0() -> i32 { p: arr.as_mut_ptr(), }; assert!((unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const p1, &p3,) })); assert!( (unsafe { PtrMember::operator_cmp(&raw const p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Both { + unsafe fn equal(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, _a0: *const Cmp) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, _a0: *const Eq) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + unsafe fn equal(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + unsafe fn equal(this: *const Self, _a0: *const Outer) -> bool { + return (unsafe { + let _arg0: *const Inner = &(*_a0).i; + WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this).i, _arg0) + }) && (((*this).y) == ((*_a0).y)); + } +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + unsafe fn equal(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Secondary { + unsafe fn equal(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); + } + unsafe fn not_equal(this: *const Self, _a0: *const Secondary) -> bool { + return !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this), _a0) }); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 9d49a17880..17fad6efeb 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -23,9 +23,9 @@ pub struct S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const S, other as *const S) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const S, self as *const S) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,32 +40,28 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const S, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} -pub unsafe fn operator_eq_1(a: *const S, b: *const S) -> bool { - return (((*a).v) == ((*b).v)); -} -pub unsafe fn operator_ne_2(a: *const S, b: *const S) -> bool { - return (((*a).v) != ((*b).v)); -} pub unsafe fn operator_lt_0(a: *const S, b: *const S) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_gt_3(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_gt_1(a: *const S, b: *const S) -> bool { return (((*a).v) > ((*b).v)); } -pub unsafe fn operator_le_4(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_le_2(a: *const S, b: *const S) -> bool { return (((*a).v) <= ((*b).v)); } -pub unsafe fn operator_ge_5(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_ge_3(a: *const S, b: *const S) -> bool { return (((*a).v) >= ((*b).v)); } -pub unsafe fn operator_lt_6(a: *const S, mut b: i32) -> bool { +pub unsafe fn operator_lt_4(a: *const S, mut b: i32) -> bool { return (((*a).v) < (b)); } -pub unsafe fn operator_lt_7(mut a: i32, b: *const S) -> bool { +pub unsafe fn operator_lt_5(mut a: i32, b: *const S) -> bool { return ((a) < ((*b).v)); } #[repr(C)] @@ -85,9 +81,15 @@ pub struct V { impl std::cmp::Ord for V { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_8(self.clone(), other.clone()) { + if operator_lt_7( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ) { std::cmp::Ordering::Less - } else if operator_lt_8(other.clone(), self.clone()) { + } else if operator_lt_7( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -102,20 +104,25 @@ impl std::cmp::PartialOrd for V { } impl std::cmp::PartialEq for V { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_9(self.clone(), other.clone()) } + unsafe { + operator_eq_8( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ) + } } } impl std::cmp::Eq for V {} -pub unsafe fn operator_eq_9(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_eq_8(mut a: V, mut b: V) -> bool { return ((a.v) == (b.v)); } -pub unsafe fn operator_ne_10(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_ne_6(mut a: V, mut b: V) -> bool { return ((a.v) != (b.v)); } -pub unsafe fn operator_lt_8(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_lt_7(mut a: V, mut b: V) -> bool { return ((a.v) < (b.v)); } -pub unsafe fn operator_gt_11(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_gt_9(mut a: V, mut b: V) -> bool { return ((a.v) > (b.v)); } pub fn main() { @@ -131,31 +138,31 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: V = x; - operator_eq_9(_a, z) + operator_eq_8(_a, z) }) ); assert!( (unsafe { let _a: V = x; - operator_ne_10(_a, y) + operator_ne_6(_a, y) }) ); assert!( (unsafe { let _a: V = x; - operator_lt_8(_a, y) + operator_lt_7(_a, y) }) ); assert!( (unsafe { let _a: V = y; - operator_gt_11(_a, x) + operator_gt_9(_a, x) }) ); assert!( !(unsafe { let _a: V = y; - operator_lt_8(_a, x) + operator_lt_7(_a, x) }) ); let mut a: S = S { v: 1 }; @@ -164,13 +171,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_eq_1(_a, &c) + WeaklyEqualityComparableWithUnsafe::equal(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_ne_2(_a, &b) + WeaklyEqualityComparableWithUnsafe::not_equal(_a, &b) }) ); assert!( @@ -182,19 +189,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &b; - operator_gt_3(_a, &a) + operator_gt_1(_a, &a) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_le_4(_a, &c) + operator_le_2(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_ge_5(_a, &c) + operator_ge_3(_a, &c) }) ); assert!( @@ -206,10 +213,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_lt_6(_a, 5) + operator_lt_4(_a, 5) }) ); - assert!((unsafe { operator_lt_7(0, &a,) })); + assert!((unsafe { operator_lt_5(0, &a,) })); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(a: *const S, b: *const S) -> bool { + return (((*a).v) == ((*b).v)); + } + unsafe fn not_equal(a: *const S, b: *const S) -> bool { + return (((*a).v) != ((*b).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn not_equal(a: *const Self, b: *const Self) -> bool { + operator_ne_6((*a).clone(), (*b).clone()) + } + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + operator_eq_8((*a).clone(), (*b).clone()) + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8901e9a173..7ce9e42ed9 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,12 +21,6 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } - pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { - return (((*this).v) != ((*o).v)); - } pub unsafe fn operator_lt_3(this: *const Self, o: *const S) -> bool { return (((*this).v) < ((*o).v)); } @@ -46,9 +40,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if S::operator_lt_3(self, other as *const S) { + if S::operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if S::operator_lt_3(other, self as *const S) { + } else if S::operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -63,7 +57,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -77,8 +73,8 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&raw const a, &c,) })); - assert!((unsafe { S::operator_ne(&raw const a, &b,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &c,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const a, &b,) })); assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); assert!((unsafe { S::operator_gt(&raw const b, &a,) })); assert!((unsafe { S::operator_le(&raw const a, &c,) })); @@ -87,4 +83,12 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } + unsafe fn not_equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) != ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index dec785d640..215a3e07c6 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -23,9 +23,17 @@ pub struct X { impl std::cmp::Ord for X { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((operator_lt_0(self.clone(), other.clone())) != 0) { + if ((operator_lt_1( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Less - } else if ((operator_lt_0(other.clone(), self.clone())) != 0) { + } else if ((operator_lt_1( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,17 +48,22 @@ impl std::cmp::PartialOrd for X { } impl std::cmp::PartialEq for X { fn eq(&self, other: &Self) -> bool { - unsafe { ((operator_eq_1(self.clone(), other.clone())) != 0) } + unsafe { + ((operator_eq_2( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + } } } impl std::cmp::Eq for X {} -pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } -pub unsafe fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if ((a.v) != (b.v)) { 3 } else { 0 }; } -pub unsafe fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if ((a.v) < (b.v)) { 4 } else { 0 }; } pub unsafe fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -127,9 +140,9 @@ impl Mixed { impl std::cmp::Ord for Mixed { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((Mixed::operator_lt(self, other as *const Mixed)) != 0) { + if ((Mixed::operator_lt((self as *const Self), (other as *const Self))) != 0) { std::cmp::Ordering::Less - } else if ((Mixed::operator_lt(other, self as *const Mixed)) != 0) { + } else if ((Mixed::operator_lt((other as *const Self), (self as *const Self))) != 0) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -144,7 +157,7 @@ impl std::cmp::PartialOrd for Mixed { } impl std::cmp::PartialEq for Mixed { fn eq(&self, other: &Self) -> bool { - unsafe { ((Mixed::operator_eq(self, other as *const Mixed)) != 0) } + unsafe { ((Mixed::operator_eq((self as *const Self), (other as *const Self))) != 0) } } } impl std::cmp::Eq for Mixed {} @@ -190,13 +203,19 @@ impl std::cmp::Ord for Boolish { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { if { - let __cmp = operator_lt_6(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Less } else if { - let __cmp = operator_lt_6(other.clone(), self.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Greater } else { @@ -214,8 +233,11 @@ impl std::cmp::PartialEq for Boolish { fn eq(&self, other: &Self) -> bool { unsafe { { - let __cmp = operator_eq_7(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_eq_7( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } } } @@ -284,17 +306,6 @@ impl RefInt { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } -impl std::cmp::PartialEq for RefInt { - fn eq(&self, other: &Self) -> bool { - unsafe { - { - let __cmp = RefInt::operator_eq(self, other as *const RefInt); - RefBool::to_bool(&*__cmp) - } - } - } -} -impl std::cmp::Eq for RefInt {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -308,25 +319,25 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, c) + operator_eq_2(_a, c) }) == (2)) ); assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, b) + operator_eq_2(_a, b) }) == (0)) ); assert!( ((unsafe { let _a: X = a; - operator_ne_2(_a, b) + operator_ne_0(_a, b) }) == (3)) ); assert!( ((unsafe { let _a: X = a; - operator_lt_0(_a, b) + operator_lt_1(_a, b) }) == (4)) ); assert!( @@ -454,7 +465,9 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while __it != __tmp_3 && *__it.iter_deref() != ri2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) + { __it.iter_inc(); } __it @@ -462,6 +475,35 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Boolish { + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + { + let __cmp = operator_eq_7((*a).clone(), (*b).clone()); + MyBool::to_bool((&raw const __cmp)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for Mixed { + unsafe fn equal(this: *const Self, o: *const Self) -> bool { + ((Mixed::operator_eq(this, o)) != 0) + } +} +impl WeaklyEqualityComparableWithUnsafe for RefInt { + unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { + { + let __cmp = RefInt::operator_eq(this, _a0); + RefBool::to_bool((__cmp as *const _)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for X { + unsafe fn not_equal(a: *const Self, b: *const Self) -> bool { + ((operator_ne_0((*a).clone(), (*b).clone())) != 0) + } + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + ((operator_eq_2((*a).clone(), (*b).clone())) != 0) + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ref_true_8); } diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 8da1438508..50da53cb5e 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,10 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).data_) == ((*y).data_)); -} -pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } #[repr(C)] @@ -34,9 +31,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const S, other as *const S) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const S, self as *const S) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -51,7 +48,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const S, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -68,21 +67,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &a; - operator_eq_0(_x, &c) + WeaklyEqualityComparableWithUnsafe::equal(_x, &c) }) ); assert!( (unsafe { let _x: *const S = &a; - operator_lt_1(_x, &b) + operator_lt_0(_x, &b) }) ); assert!( !(unsafe { let _x: *const S = &b; - operator_lt_1(_x, &a) + operator_lt_0(_x, &a) }) ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).data_) == ((*y).data_)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index f87c82e9c5..d8a6e88031 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -6,9 +6,6 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { - return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); -} #[repr(C)] #[derive( Copy, @@ -24,13 +21,7 @@ pub struct Defaulted { pub a: i32, pub b: i32, } -impl std::cmp::PartialEq for Defaulted { - fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const Defaulted, other as *const Defaulted) } - } -} -impl std::cmp::Eq for Defaulted {} -pub unsafe fn operator_cmp_1( +pub unsafe fn operator_cmp_0( _a0: *const DefaultedOrd, _a1: *const DefaultedOrd, ) -> std::cmp::Ordering { @@ -42,9 +33,6 @@ pub unsafe fn operator_cmp_1( } return libcc2rs::STRONG_ORDERING_EQUAL; } -pub unsafe fn operator_eq_2(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { - return (((*_a0).a) == ((*_a1).a)); -} #[repr(C)] #[derive( Copy, @@ -61,7 +49,7 @@ pub struct DefaultedOrd { } impl std::cmp::Ord for DefaultedOrd { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { operator_cmp_1(self as *const DefaultedOrd, other as *const DefaultedOrd) } + unsafe { operator_cmp_0((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for DefaultedOrd { @@ -71,17 +59,16 @@ impl std::cmp::PartialOrd for DefaultedOrd { } impl std::cmp::PartialEq for DefaultedOrd { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const DefaultedOrd, other as *const DefaultedOrd) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for DefaultedOrd {} -pub unsafe fn operator_eq_3(x: *const Inline, y: *const Inline) -> bool { - return (((*x).a) == ((*y).a)); -} -pub unsafe fn operator_lt_4(x: *const Inline, y: *const Inline) -> bool { +pub unsafe fn operator_lt_1(x: *const Inline, y: *const Inline) -> bool { return (((*x).a) < ((*y).a)); } -pub unsafe fn operator_add_5(x: *const Inline, y: *const Inline) -> Inline { +pub unsafe fn operator_add_2(x: *const Inline, y: *const Inline) -> Inline { return Inline { a: (((*x).a) + ((*y).a)), }; @@ -103,9 +90,9 @@ pub struct Inline { impl std::cmp::Ord for Inline { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Inline, other as *const Inline) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Inline, self as *const Inline) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -120,7 +107,9 @@ impl std::cmp::PartialOrd for Inline { } impl std::cmp::PartialEq for Inline { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_3(self as *const Inline, other as *const Inline) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Inline {} @@ -138,30 +127,9 @@ impl std::cmp::Eq for Inline {} pub struct OutOfLine { pub a: i32, } -impl std::cmp::PartialEq for OutOfLine { - fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_6(self as *const OutOfLine, other as *const OutOfLine) } - } -} -impl std::cmp::Eq for OutOfLine {} -pub unsafe fn operator_eq_6(x: *const OutOfLine, y: *const OutOfLine) -> bool { - return (((*x).a) == ((*y).a)); -} -pub unsafe fn operator_ne_7(x: *const OutOfLine, y: *const OutOfLine) -> bool { - return !(unsafe { - let _x: *const OutOfLine = x; - operator_eq_6(_x, y) - }); -} -pub unsafe fn operator_eq_8(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { - return (((*x).v) == ((*y).v)); -} -pub unsafe fn operator_lt_9(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { +pub unsafe fn operator_lt_3(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) < ((*y).v)); } -pub unsafe fn operator_eq_10(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { - return (((*x).v as i64) == ((*y).v)); -} #[repr(C)] #[derive( Copy, @@ -179,9 +147,9 @@ pub struct Tmpl_int_ { impl std::cmp::Ord for Tmpl_int_ { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_9(self as *const Tmpl_int_, other as *const Tmpl_int_) { + if operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_9(other as *const Tmpl_int_, self as *const Tmpl_int_) { + } else if operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -196,7 +164,9 @@ impl std::cmp::PartialOrd for Tmpl_int_ { } impl std::cmp::PartialEq for Tmpl_int_ { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_8(self as *const Tmpl_int_, other as *const Tmpl_int_) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Tmpl_int_ {} @@ -214,12 +184,6 @@ impl std::cmp::Eq for Tmpl_int_ {} pub struct Tmpl_long_ { pub v: i64, } -pub unsafe fn operator_eq_11( - _a0: *const TmplDefaulted_int_, - _a1: *const TmplDefaulted_int_, -) -> bool { - return (((*_a0).v) == ((*_a1).v)); -} #[repr(C)] #[derive( Copy, @@ -234,17 +198,6 @@ pub unsafe fn operator_eq_11( pub struct TmplDefaulted_int_ { pub v: i32, } -impl std::cmp::PartialEq for TmplDefaulted_int_ { - fn eq(&self, other: &Self) -> bool { - unsafe { - operator_eq_11( - self as *const TmplDefaulted_int_, - other as *const TmplDefaulted_int_, - ) - } - } -} -impl std::cmp::Eq for TmplDefaulted_int_ {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -258,19 +211,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d2) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d2) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) }) ); let mut o1: DefaultedOrd = DefaultedOrd { a: 1 }; @@ -278,26 +231,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; - operator_cmp_1(_arg0, &o2) + operator_cmp_0(_arg0, &o2) }) == std::cmp::Ordering::Less ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o2; - operator_cmp_1(_arg0, &o1) + operator_cmp_0(_arg0, &o1) }) == std::cmp::Ordering::Greater ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; let _arg1: *const DefaultedOrd = &o1; - operator_eq_2(_arg0, _arg1) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, _arg1) }) ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; - operator_cmp_1(_arg0, &o2) + operator_cmp_0(_arg0, &o2) }) == libcc2rs::STRONG_ORDERING_LESS ); let mut i1: Inline = Inline { a: 1 }; @@ -306,35 +259,35 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Inline = &i1; - operator_eq_3(_x, &i3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &i3) }) ); assert!( !(unsafe { let _x: *const Inline = &i1; - operator_eq_3(_x, &i2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &i2) }) ); assert!( (unsafe { let _x: *const Inline = &i1; - operator_lt_4(_x, &i2) + operator_lt_1(_x, &i2) }) ); assert!( !(unsafe { let _x: *const Inline = &i2; - operator_lt_4(_x, &i1) + operator_lt_1(_x, &i1) }) ); assert!( (unsafe { let mut _x: Inline = (unsafe { let _x: *const Inline = &i1; - operator_add_5(_x, &i2) + operator_add_2(_x, &i2) }); let mut _y: Inline = Inline { a: 3 }; - operator_eq_3(&mut _x, &mut _y) + WeaklyEqualityComparableWithUnsafe::equal(&mut _x, &mut _y) }) ); let mut f1: OutOfLine = OutOfLine { a: 4 }; @@ -343,19 +296,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const OutOfLine = &f1; - operator_eq_6(_x, &f2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &f2) }) ); assert!( (unsafe { let _x: *const OutOfLine = &f1; - operator_ne_7(_x, &f3) + WeaklyEqualityComparableWithUnsafe::not_equal(_x, &f3) }) ); assert!( !(unsafe { let _x: *const OutOfLine = &f1; - operator_eq_6(_x, &f3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &f3) }) ); let mut t1: Tmpl_int_ = Tmpl_int_ { v: 1 }; @@ -364,19 +317,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_8(_x, &t3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &t3) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_8(_x, &t2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &t2) }) ); assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_lt_9(_x, &t2) + operator_lt_3(_x, &t2) }) ); let mut u1: Tmpl_long_ = Tmpl_long_ { v: 1_i64 }; @@ -384,13 +337,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_10(_x, &u1) + WeaklyEqualityComparableWithUnsafe::equal(_x, &u1) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_10(_x, &u2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &u2) }) ); let mut v1: TmplDefaulted_int_ = TmplDefaulted_int_ { v: 7 }; @@ -399,21 +352,67 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v2) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v2) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) }) ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Defaulted { + unsafe fn equal(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { + return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { + unsafe fn equal(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { + return (((*_a0).a) == ((*_a1).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Inline { + unsafe fn equal(x: *const Inline, y: *const Inline) -> bool { + return (((*x).a) == ((*y).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for OutOfLine { + unsafe fn equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { + return (((*x).a) == ((*y).a)); + } + unsafe fn not_equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { + return !(unsafe { + let _x: *const OutOfLine = x; + WeaklyEqualityComparableWithUnsafe::equal(_x, y) + }); + } +} +impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { + unsafe fn equal(_a0: *const TmplDefaulted_int_, _a1: *const TmplDefaulted_int_) -> bool { + return (((*_a0).v) == ((*_a1).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { + return (((*x).v) == ((*y).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_long_ { + unsafe fn equal(lhs: *const Self, rhs: *const Tmpl_int_) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { + return (((*x).v as i64) == ((*y).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 5bf2faffa5..54ee1f8bf2 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -30,9 +30,9 @@ impl Pair { impl std::cmp::Ord for Pair { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair) { + if Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self)) { std::cmp::Ordering::Less - } else if Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair) { + } else if Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -48,8 +48,8 @@ impl std::cmp::PartialOrd for Pair { impl std::cmp::PartialEq for Pair { fn eq(&self, other: &Self) -> bool { unsafe { - !(Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair)) - && !(Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair)) + !(Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self))) + && !(Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 001ceea13f..3511bdd32b 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -30,13 +30,10 @@ impl S { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } } impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { S::operator_cmp(self, other as *const S) } + unsafe { S::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for S { @@ -46,7 +43,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -63,8 +62,13 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) == std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) != std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &b,) })); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index c5e3127926..da0b07ce0f 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -28,9 +28,9 @@ impl Lt { impl std::cmp::Ord for Lt { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Lt::operator_lt(self, other as *const Lt) { + if Lt::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Lt::operator_lt(other, self as *const Lt) { + } else if Lt::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -46,8 +46,8 @@ impl std::cmp::PartialOrd for Lt { impl std::cmp::PartialEq for Lt { fn eq(&self, other: &Self) -> bool { unsafe { - !(Lt::operator_lt(self, other as *const Lt)) - && !(Lt::operator_lt(other, self as *const Lt)) + !(Lt::operator_lt((self as *const Self), (other as *const Self))) + && !(Lt::operator_lt((other as *const Self), (self as *const Self))) } } } @@ -66,17 +66,6 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, o: *const Eq) -> bool { - return (((*this).v) == ((*o).v)); - } -} -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, @@ -95,13 +84,10 @@ impl Cmp { pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } - pub unsafe fn operator_eq(this: *const Self, o: *const Cmp) -> bool { - return (((*this).v) == ((*o).v)); - } } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -111,7 +97,9 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_eq(self, other as *const Cmp) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Cmp {} @@ -132,9 +120,9 @@ pub struct Free { impl std::cmp::Ord for Free { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const Free, other as *const Free) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const Free, self as *const Free) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -149,16 +137,15 @@ impl std::cmp::PartialOrd for Free { } impl std::cmp::PartialEq for Free { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const Free, other as *const Free) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Free {} pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { - return (((*a).v) == ((*b).v)); -} #[repr(C)] #[derive( Copy, @@ -207,7 +194,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && *__it.iter_deref() != two { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) + { __it.iter_inc(); } __it @@ -215,17 +204,20 @@ unsafe fn main_0() -> i32 { .iter_deref()) .v) == (2)) ); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && *__it.iter_deref() != nine { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) + { __it.iter_inc(); } __it - } == eqs.end() - ); + }, + &eqs.end() + )); let mut cmps: Vec = Vec::from([Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }]); { let mut __tmp_5 = { cmps.begin() }; @@ -247,7 +239,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && *__it.iter_deref() != three { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_7) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) + { __it.iter_inc(); } __it @@ -276,7 +270,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != ftwo { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) + { __it.iter_inc(); } __it @@ -311,4 +307,19 @@ unsafe fn main_0() -> i32 { }; return 0; } +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, o: *const Cmp) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, o: *const Eq) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Free { + unsafe fn equal(a: *const Free, b: *const Free) -> bool { + return (((*a).v) == ((*b).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index a95c33594e..9e7ad99b5f 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -75,7 +75,7 @@ pub unsafe fn push_local_from_field_1(mut jpg: *mut JPEGData, mut cond: bool) { let mut __tmp_2 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -103,7 +103,7 @@ pub unsafe fn emplace_local_from_field_4(mut jpg: *mut JPEGData, mut cond: bool) let mut __tmp_3 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -251,7 +251,7 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut __tmp_4 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -318,7 +318,7 @@ pub unsafe fn emplace_from_sibling_18(mut s: *mut Bytes) { let mut __tmp_5 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs index 7b912f27aa..3e97994247 100644 --- a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs +++ b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs @@ -9,7 +9,10 @@ use std::rc::Rc; pub unsafe fn sink_0(mut it: UnsafeBidirectionalIterator<(i32, i32)>) -> i32 { let mut cit: UnsafeBidirectionalIterator<(i32, i32)> = >::from((it).clone()); - return if cit == >::from((it).clone()) { + return if WeaklyEqualityComparableWithUnsafe::equal( + &cit, + &>::from((it).clone()), + ) { (*it.iter_deref()).1 } else { 0 @@ -34,20 +37,30 @@ unsafe fn main_0() -> i32 { let mut it0: UnsafeBidirectionalIterator<(i32, i32)> = m.find(&0); let mut const_it: UnsafeBidirectionalIterator<(i32, i32)> = >::from((it0).clone()); - let mut r: i32 = if const_it == >::from((end).clone()) { + let mut r: i32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from((end).clone()), + ) { 0 } else { 1 }; r += (unsafe { sink_0((it0).clone()) }); - r += if end == end { 0 } else { 1 }; + r += if WeaklyEqualityComparableWithUnsafe::equal(&end, &end) { + 0 + } else { + 1 + }; assert!(((r) == (2))); let mut values: Vec = Vec::from([7_u32, 8_u32, 9_u32]); let mut middle: UnsafeRandomAccessIterator = values.begin().iter_add(1_isize); let mut const_middle: UnsafeRandomAccessIterator = >::from((middle).clone()); assert!(((*const_middle.iter_deref()) == (8_u32))); - assert!(const_middle == middle); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &const_middle, + &middle + )); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index bda3ad0366..766192a706 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -36,7 +36,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __first = src.as_mut_ptr(); let mut __out = (dst.as_mut_ptr() as *mut usize).cast::(); - while __first != __tmp_0 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { *__out.iter_deref() = ((*__first.iter_deref()) as u64); __first.iter_inc(); __out.iter_inc(); @@ -75,7 +75,10 @@ pub unsafe fn size_t_in_rules_3() { |__k| cpp_move_unsafe!(__k), || 0_u64, )) = 4_u64; - assert!(m.find(&1_u64) != m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &m.find(&1_u64), + &m.end() + )); assert!((((*m.begin().iter_deref()).0) == (1_u64))); let mut m2: UnsafeMap = std::mem::take(&mut m); assert!(((m2.len()) == (2_usize))); @@ -138,7 +141,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_5 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -155,7 +158,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) { *__it.iter_deref() = Clone::clone(&(k as u64)); __it.iter_inc(); } @@ -217,17 +220,20 @@ pub unsafe fn size_t_in_rules_3() { v3.push(__a2) } }; - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &{ let mut __tmp_12 = { v3.begin() }; let mut __tmp_13 = { v3.end() }; let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 && *__it.iter_deref() != (k as u64) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(k as u64)) + { __it.iter_inc(); } __it - } != v3.end() - ); + }, + &v3.end() + )); assert!((((v3.len()) == (5_usize)) && ((big) >= (k))) && (((pk.1) as usize) == (k))); let mut ci: UnsafeRandomAccessIterator = >::from(v.begin()); diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 3ec644d0cc..13a3f86ea0 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -52,9 +52,9 @@ impl MoveAssignableUnsafe for Tracked { impl std::cmp::Ord for Tracked { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Tracked, other as *const Tracked) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Tracked, self as *const Tracked) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -70,8 +70,8 @@ impl std::cmp::PartialOrd for Tracked { impl std::cmp::PartialEq for Tracked { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_1(self as *const Tracked, other as *const Tracked)) - && !(operator_lt_1(other as *const Tracked, self as *const Tracked)) + !(operator_lt_1((self as *const Self), (other as *const Self))) + && !(operator_lt_1((other as *const Self), (self as *const Self))) } } } @@ -116,9 +116,9 @@ impl MoveOnly { impl std::cmp::Ord for MoveOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_3(self as *const MoveOnly, other as *const MoveOnly) { + if operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_3(other as *const MoveOnly, self as *const MoveOnly) { + } else if operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -134,8 +134,8 @@ impl std::cmp::PartialOrd for MoveOnly { impl std::cmp::PartialEq for MoveOnly { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_3(self as *const MoveOnly, other as *const MoveOnly)) - && !(operator_lt_3(other as *const MoveOnly, self as *const MoveOnly)) + !(operator_lt_3((self as *const Self), (other as *const Self))) + && !(operator_lt_3((other as *const Self), (self as *const Self))) } } } @@ -164,9 +164,9 @@ impl DefaultConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -181,16 +181,15 @@ impl std::cmp::PartialOrd for Bag { } impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_5(self as *const Bag, other as *const Bag) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).items.len()) < ((*b).items.len())); } -pub unsafe fn operator_eq_5(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) == ((*b).items.len())); -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -465,26 +464,32 @@ unsafe fn main_0() -> i32 { && ((bag_vec[(2_usize)].items[(1_usize)].v) == (5)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != bags[(1) as usize] { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &bags[(1) as usize], + ) + { __it.iter_inc(); } __it - } == bag_vec.begin().iter_add(1_isize) - ); - assert!( - { + }, + &bag_vec.begin().iter_add(1_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { bag_vec.begin() }; let mut __tmp_10 = { bag_vec.end() }; let mut __best = __tmp_9.clone(); - if __tmp_9 != __tmp_10 { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_9, &__tmp_10) { let mut __it = (__tmp_9).clone(); __it.iter_inc(); - while __it != __tmp_10 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -492,8 +497,9 @@ unsafe fn main_0() -> i32 { } } __best - } == bag_vec.begin().iter_add(2_isize) - ); + }, + &bag_vec.begin().iter_add(2_isize) + )); assert!( (({ let __a: *const _ = &mut bags[(0) as usize]; @@ -521,7 +527,10 @@ unsafe fn main_0() -> i32 { || 0_i32, )) = 0; assert!((((*bag_map.find(&bags[(2) as usize]).iter_deref()).1) == (2))); - assert!(bag_map.find(&bags[(1) as usize]) == bag_map.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &bag_map.find(&bags[(1) as usize]), + &bag_map.end() + )); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut moves: Vec = Vec::new(); moves.push_mut({ @@ -601,6 +610,11 @@ unsafe fn main_0() -> i32 { ); return (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); } +impl WeaklyEqualityComparableWithUnsafe for Bag { + unsafe fn equal(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) == ((*b).items.len())); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copies_0); } diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index dc8489328d..1e589a8c48 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = output.as_mut_ptr(); - while __first != __tmp_0 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { *__out.iter_deref() = (*__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = widened.begin(); - while __first != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_1) { *__out.iter_deref() = ((*__first.iter_deref()) as i64); __first.iter_inc(); __out.iter_inc(); @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_4 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = constructed.begin(); - while __first != __tmp_4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_4) { *__out.iter_deref() = >::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -88,7 +88,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { wide.as_mut_ptr().offset((2) as isize) }; let mut __first = wide.as_mut_ptr(); let mut __out = floating.begin(); - while __first != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_5) { *__out.iter_deref() = ((*__first.iter_deref()) as f64); __first.iter_inc(); __out.iter_inc(); diff --git a/tests/unit/out/unsafe/stdcopy_ostream.rs b/tests/unit/out/unsafe/stdcopy_ostream.rs index 019a2d0a6c..de2abdc633 100644 --- a/tests/unit/out/unsafe/stdcopy_ostream.rs +++ b/tests/unit/out/unsafe/stdcopy_ostream.rs @@ -37,7 +37,7 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_0).clone(); let __out = &mut ofs; let mut __bytes: Vec = Vec::new(); - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index ac00d71ea8..48dfc6485f 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -55,12 +55,20 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) let mut __tmp_0 = { items.begin() }; let mut __tmp_1 = { items.end() }; let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 && *__it.iter_deref() != (*sigma.offset((i) as isize)) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &(*sigma.offset((i) as isize)), + ) + { __it.iter_inc(); } __it }; - assert!(it != items.end()); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &it, + &items.end() + )); (*code.offset((i) as isize)) = ((it.iter_distance(&items.begin())) as u32); { let mut __tmp_2 = { >::from((it).clone()) }; @@ -79,7 +87,7 @@ pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut s: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { + 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { 'for_body: { s += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 1e1283e461..9a5c15a49f 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -185,7 +185,7 @@ unsafe fn main_0() -> i32 { __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { __tmp.push((*__it.iter_deref())); __it.iter_inc(); } @@ -509,7 +509,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_20 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -530,7 +530,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_22).clone(); - while __it != __tmp_23 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -547,7 +547,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_25 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { __tmp.push(((*__it.iter_deref()) as f64)); __it.iter_inc(); } @@ -564,7 +564,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_27 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { __tmp.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -581,7 +581,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_29).clone(); - while __it != __tmp_30 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { __tmp.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 02864261d4..70957875b5 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_0 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -75,7 +75,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -90,7 +90,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -103,7 +103,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -127,7 +127,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -162,7 +162,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_10 = { m.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { __v.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -182,7 +182,7 @@ unsafe fn main_0() -> i32 { __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { __tmp.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -200,7 +200,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_14 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -212,7 +212,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; let mut __v = Vec::new(); let mut __it = readings.as_mut_ptr(); - while __it != __tmp_15 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 34293aab10..fce95b321f 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -317,7 +317,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_16 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_17 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -347,7 +347,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_18 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -360,7 +360,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_19 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -378,7 +378,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_20 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __v.push((*__it.iter_deref())); __it.iter_inc(); }