diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fa688b9c02..f01a94a7c9 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -75,42 +75,6 @@ Converter::DeferredBlock &Converter::DeferredImpl(std::string header) { return it->second; } -void Converter::AddComparisonTraitMethod(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) { - ComparisonTraitImpl(trait, name, "").body += method; - if (&trait == &kWeaklyEqualityComparableWith) { - converted_record_traits_.emplace(name, trait.refcount.name); - } - return; - } - auto other = GetUnboxedTypeAsString(rhs); - ComparisonTraitImpl(trait, name, other).body += method; - if (&trait != &kWeaklyEqualityComparableWith || - FindComparisonOperator(ctx_, rhs, lhs, clang::OO_EqualEqual)) { - return; - } - ComparisonTraitImpl(trait, other, name).body += - std::format("{} {{ <{} as {}<{}>>::{}(rhs, lhs) }}\n", - GetComparisonTraitSignature(trait, "lhs", "rhs", name), name, - GetRecordTraitSpelling(trait).name, other, trait.method); -} - -Converter::DeferredBlock & -Converter::ComparisonTraitImpl(const RecordTrait &trait, std::string_view self, - std::string_view other) { - const char *name = GetRecordTraitSpelling(trait).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_) { @@ -119,13 +83,6 @@ 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", @@ -138,16 +95,8 @@ 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 *comparison = GetComparisonTrait(method); - comparison && HasDeferredComparisonImpl(*comparison)) { - if (IsEqualityComparableTrait(*comparison) && - IsSameTypeComparison(method, decl)) { - traits.emplace(kWeaklyEqualityComparableWith.refcount.name, - &kWeaklyEqualityComparableWith); - } - } else if (auto *trait = GetRecordTrait(method); - trait && trait != &kThreeWayComparable && - !IsDerivedCopyOrMove(method)) { + if (auto *trait = GetRecordTrait(method); + trait && !IsDerivedCopyOrMove(method)) { traits.emplace(trait->refcount.name, trait); } } @@ -557,10 +506,6 @@ 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. @@ -584,44 +529,6 @@ 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(); - } - if (HasDeferredComparisonImpl(trait)) { - AddComparisonTraitMethod(decl, trait, method); - return; - } - auto record_name = GetRecordName(GetComparisonRecord(decl)); - converted_record_traits_.emplace(record_name, trait.refcount.name); - StrCat(keyword::kImpl, GetRecordTraitSpelling(trait).name, "for", - record_name); - PushBrace impl_brace(*this); - if (&trait == &kThreeWayComparable) { - StrCat(GetComparisonCategory(decl)); - } - StrCat(method); -} - -std::string Converter::GetComparisonCategory(const clang::FunctionDecl *op) { - return std::format("type Category = {};", - GetUnboxedTypeAsString(op->getReturnType())); -} - void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { for (auto *child : body->body()) { if (auto *decl_stmt = clang::dyn_cast(child)) { @@ -1161,7 +1068,7 @@ void Converter::EmitRustStructOrUnion(clang::RecordDecl *decl) { if (auto *cxx = clang::dyn_cast(decl)) { ConvertCXXRecordMethods(cxx); ConvertVirtualMethods(cxx); - AddOrdTrait(cxx); + EmitComparisonTraits(cxx); DeclareRecordTraits(cxx); AddAssignmentTraits(cxx); } @@ -1265,18 +1172,11 @@ void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, if (body.empty()) { return; } - if (HasDeferredComparisonImpl(trait)) { - AddComparisonTraitMethod(method, trait, body); - return; - } converted_record_traits_.emplace(GetRecordName(method->getParent()), trait.refcount.name); StrCat(keyword::kImpl, GetCopyOrMoveTraitName(trait), "for", GetRecordName(method->getParent())); PushBrace brace(*this); - if (&trait == &kThreeWayComparable) { - StrCat(GetComparisonCategory(method)); - } StrCat(body); } @@ -1298,27 +1198,11 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { } void Converter::EmitDerives(const clang::RecordDecl *decl) { - auto *cxx = clang::dyn_cast(decl); - auto *three_way = cxx ? GetDerivingThreeWayOperator(ctx_, cxx) : nullptr; StrCat("#[derive("); for (auto *attr : GetStructAttributes(decl)) { StrCat(attr, ','); } - if (three_way) { - StrCat(GetCopyOrMoveTraitName(kPartiallyOrderedWith), ','); - } StrCat(")]"); - if (auto *method = clang::dyn_cast_or_null(three_way)) { - StrCat(std::format("#[three_way({}::{})]", GetUFCSName(method), - GetMethodName(method))); - } else if (auto *trait = - three_way ? GetComparisonTrait(three_way) : nullptr) { - StrCat(std::format("#[three_way({}::{})]", GetCopyOrMoveTraitName(*trait), - trait->method)); - } else if (three_way) { - StrCat(std::format("#[three_way({})]", - GetNamedDeclAsString(three_way->getCanonicalDecl()))); - } if (auto methods = GetDerivedCopyOrMoves(decl); !methods.empty()) { StrCat("#[memberwise("); for (auto *method : methods) { @@ -1763,18 +1647,7 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ScopedValue return_value(return_value_, stmt->getRetValue()); auto return_type = curr_function_->getReturnType(); if (auto *value = stmt->getRetValue(); value && UsesReturnSlot(return_type)) { - std::string_view slot = "__return"; - if (auto *construct = GetPlacementInitializer(value)) { - ConstructInPlace(value, construct, GetReturnSlotReceiver(slot)); - } else { - HoistMaterializedTempBindings hoist_temps(*this); - StrCat(slot, ".write"); - { - PushParen paren(*this); - ConvertVarInit(return_type, value); - } - StrCat(token::kSemiColon); - } + InitializeReturnSlot(return_type, value); StrCat(keyword::kReturn, token::kSemiColon); return false; } @@ -1789,6 +1662,25 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { return false; } +void Converter::InitializeReturnSlot(clang::QualType type, clang::Expr *value) { + std::string_view slot = "__return"; + if (auto *construct = GetPlacementInitializer(value)) { + ConstructInPlace(value, construct, GetReturnSlotReceiver(slot)); + return; + } + HoistMaterializedTempBindings hoist_temps(*this); + StrCat(slot, ".write"); + { + PushParen paren(*this); + if (type->isReferenceType()) { + StrCat(GetReferenceMarker(type->isRValueReferenceType()), "::bind"); + } + PushParen bind(*this, type->isReferenceType()); + ConvertVarInit(type, value); + } + StrCat(token::kSemiColon); +} + bool Converter::VisitGotoStmt(clang::GotoStmt *stmt) { StrCat(std::format("goto!('{})", stmt->getLabel()->getName().str())); return false; @@ -2804,7 +2696,7 @@ void Converter::EmitCall(CallInfo &&info) { auto *direct_callee = info.expr->getDirectCallee(); assert(direct_callee); StrCat("libc::", direct_callee->getName()); - } else if (!EmitComparisonTraitCallee(info)) { + } else { PushExprKind push(*this, ExprKind::Callee); Convert(GetCallee(info.expr)); } @@ -2812,19 +2704,6 @@ 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_); @@ -2868,7 +2747,7 @@ void Converter::ConvertUserOperatorCall(clang::CXXOperatorCallExpr *expr) { SetUFCSReceiver(expr->getArg(0), false, method); } StrCat(GetUFCSName(method), token::kDoubleColon, GetMethodName(method)); - } else if (!EmitComparisonTraitCallee(info)) { + } else { StrCat(GetNamedDeclAsString(callee->getCanonicalDecl())); } EmitArgList(info); @@ -5998,239 +5877,104 @@ bool Converter::ConvertOutOfLineVirtualMethod(clang::CXXMethodDecl *decl) { return emitted; } -std::string Converter::GetComparisonCall(const clang::FunctionDecl *op, - const clang::CXXRecordDecl *decl, - std::string_view lhs, - std::string_view rhs) { - if (const auto *method = clang::dyn_cast(op)) { - return std::format("{}::{}({}, {})", GetUFCSName(method), - GetMethodName(method), - 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)); -} - -std::string Converter::GetComparisonBool(const clang::FunctionDecl *op, - const clang::CXXRecordDecl *decl, - std::string_view lhs, - std::string_view rhs) { - auto call = GetComparisonCall(op, decl, lhs, rhs); - auto ret = op->getReturnType(); - if (ret->isBooleanType()) { - return call; - } - if (ret->isIntegerType()) { - return std::format("(({}) != 0)", call); - } - bool returns_ref = ret->isReferenceType(); - const auto *record = ret.getNonReferenceType()->getAsCXXRecordDecl(); - assert(record && "unsupported comparison operator return type"); - for (const auto *found : record->getVisibleConversionFunctions()) { - const auto *conversion = clang::dyn_cast(found); - if (conversion && conversion->getConversionType()->isBooleanType()) { - return std::format( - "{{ let __cmp = {}; {}::{}({}) }}", call, GetUFCSName(conversion), - GetMethodName(conversion), - GetComparisonResultReceiver(conversion, returns_ref, "__cmp")); - } - } - assert(0 && "comparison operator result has no conversion to bool"); - return call; -} - -std::string Converter::GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *, - std::string_view value) { - auto type = param->getType(); - if (!type->isReferenceType()) { - return std::format("(*{}).clone()", value); - } - if (type.getNonReferenceType().isConstQualified()) { - return std::string(value); - } - return std::format("{}.cast_mut()", value); -} - -std::string -Converter::GetComparisonResultReceiver(const clang::CXXMethodDecl *method, - bool returns_ref, - std::string_view result) { - return GetComparisonReceiver( - 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) { - bool is_mut = MethodNeedsMutableReceiver(method); - if (!IsMethodOnPtr(method)) { - return is_mut ? std::format("&mut *{}.cast_mut()", lhs) - : std::format("&*{}", lhs); - } - return is_mut ? std::format("{}.cast_mut()", lhs) : std::string(lhs); -} - -void Converter::ConvertComparisonTraitWrappers(const clang::CXXRecordDecl *decl, - const clang::FunctionDecl *eq, - const clang::FunctionDecl *lt, - const clang::FunctionDecl *cmp) { - if (auto *op = lt ? lt : cmp; op && !(lt && GetComparisonTrait(lt))) { - const auto &trait = kLessThanComparable; - auto [lhs, rhs] = GetComparisonOperandNames(op); - StrCat(keyword::kImpl, GetRecordTraitSpelling(trait).name, "for", - GetRecordName(decl)); - PushBrace impl_brace(*this); - StrCat(GetComparisonTraitSignature(trait, lhs, rhs, "Self")); - PushBrace body(*this); - if (lt) { - StrCat(GetComparisonBool(lt, decl, lhs, rhs)); - } else { - StrCat(std::format("libcc2rs::is_lt({})", - GetComparisonCall(cmp, decl, lhs, rhs))); +void Converter::EmitComparisonTraits(const clang::CXXRecordDecl *decl) { + ScopedValue no_function(curr_function_, nullptr); + const auto &comparisons = GetRecordComparisons(GetSema(), decl); + for (const auto *trait : + {&kCpp17EqualityComparable, &kWeaklyEqualityComparableWith, + &kLessThanComparable, &kPartiallyOrderedWith}) { + if (SatisfiesComparisonTrait(*trait, comparisons.self, comparisons.self)) { + EmitComparisonTrait(*trait, comparisons.self); + } + } + if (auto *three_way = comparisons.self.exprs.at(clang::BO_Cmp); + three_way && three_way->isPRValue() && + ctx_.CompCategories.lookupInfoForType(three_way->getType()) && + comparisons.self.Has(kWeaklyEqualityComparableWith) && + comparisons.self.Has(kPartiallyOrderedWith)) { + EmitComparisonTrait(kThreeWayComparable, comparisons.self); + } + clang::QualType self = ctx_.getCanonicalTagType(decl); + for (const auto &[other, forward, reverse] : comparisons.others) { + auto *other_record = other->getAsCXXRecordDecl(); + bool other_emits_reverse = + other_record && IsUserDefinedDecl(other_record) && + llvm::is_contained(GetComparisonOperandTypes(other_record), self); + for (const auto *trait : kHeterogeneousComparisonTraits) { + if (SatisfiesComparisonTrait(*trait, forward, reverse)) { + EmitComparisonTrait(*trait, forward); + } + if (!other_emits_reverse && + SatisfiesComparisonTrait(*trait, reverse, forward)) { + EmitComparisonTrait(*trait, reverse); + } } } - if (eq && !GetComparisonTrait(eq)) { - ConvertEqualityComparableImpl(decl, eq); - } } -void Converter::ConvertPartiallyOrderedWithImpl( - const clang::CXXRecordDecl *decl) { - if (!IsPartiallyOrdered(ctx_, decl) || - GetDerivingThreeWayOperator(ctx_, decl)) { - return; +void Converter::EmitComparisonTrait(const ComparisonTrait &trait, + const Comparisons &comparisons) { + std::string name = GetRecordTraitSpelling(trait.trait).name; + if (comparisons.rhs_type != comparisons.lhs_type) { + name += std::format("<{}>", GetUnboxedTypeAsString(comparisons.rhs_type)); } - clang::QualType type = ctx_.getCanonicalTagType(decl); - auto *cmp = FindComparisonOperator(ctx_, type, type, clang::OO_Spaceship); - auto add = [&](const RecordTrait &trait, const std::string &body) { - ComparisonTraitImpl(trait, GetRecordName(decl), "").body += std::format( - "{} {{ {} }}\n", - GetComparisonTraitSignature(trait, "lhs", "rhs", "Self"), body); - }; - add(kPartiallyOrderedWith, - std::format("::{}(lhs, rhs)", - GetRecordTraitSpelling(kLessThanComparable).name, - kLessThanComparable.method)); - const std::pair relations[] = { - {clang::OO_Greater, "is_gt"}, - {clang::OO_LessEqual, "is_lteq"}, - {clang::OO_GreaterEqual, "is_gteq"}}; - for (auto [kind, from_three_way] : relations) { - const auto &trait = GetPartiallyOrderedWithTrait(kind); - auto *op = FindComparisonOperator(ctx_, type, type, kind); - if (!op) { - add(trait, std::format("libcc2rs::{}({})", from_three_way, - GetComparisonCall(cmp, decl, "lhs", "rhs"))); - } else if (!GetComparisonTrait(op)) { - add(trait, GetComparisonBool(op, decl, "lhs", "rhs")); + StrCat(std::format("impl {} for {}", name, + GetUnboxedTypeAsString(comparisons.lhs_type))); + PushBrace impl_brace(*this); + for (const auto &relation : trait.relations) { + EmitComparisonMethod(name, relation, comparisons); + } +} + +void Converter::EmitComparisonMethod(std::string_view trait, + const ComparisonRelation &relation, + const Comparisons &comparisons) { + auto *expr = comparisons.exprs.at(relation.op); + auto type = ctx_.getReferenceQualifiedType(expr); + auto operands = std::format("|{}, {}|", GetNamedDeclAsString(comparisons.lhs), + GetNamedDeclAsString(comparisons.rhs)); + StrCat(GetComparisonMacro(), token::kOpenParen, trait, token::kComma, + relation.method, token::kComma); + if (relation.test_method) { + StrCat(relation.test_method, token::kComma); + } + StrCat(relation.result, "=", + type->isReferenceType() + ? GetReferenceMarkerAsString(type) + : GetUnboxedTypeAsString(type.getUnqualifiedType()), + token::kComma); + if (!relation.test_method) { + assert(!type->isReferenceType() && !UsesReturnSlot(type)); + StrCat(operands); + EmitComparisonBody([&] { + HoistMaterializedTempBindings hoist_temps(*this); + ConvertVarInit(type, expr); + }); + } else { + StrCat(GetUnboxedTypeAsString(comparisons.rhs_type), token::kComma); + if (!type->isBooleanType()) { + StrCat("|__return,", operands.substr(1)); + EmitComparisonBody([&] { InitializeReturnSlot(type, expr); }); + StrCat(token::kComma, operands); + } else { + StrCat(operands); } + EmitComparisonBody([&] { + HoistMaterializedTempBindings hoist_temps(*this); + ConvertVarInit(ctx_.BoolTy, comparisons.tests.at(relation.op)); + }); } + StrCat(token::kCloseParen, token::kSemiColon); } -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); - AddComparisonTraitMethod( - 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) { - if (!fn || fn->isImplicit() || fn->isDeleted() || !fn->hasBody() || - fn->getDescribedFunctionTemplate() || !IsSameTypeComparison(fn, decl)) { - return; - } - if (fn->getOverloadedOperator() == clang::OO_Spaceship && - !ctx_.CompCategories.lookupInfoForType(fn->getReturnType())) { - return; - } - switch (fn->getOverloadedOperator()) { - case clang::OO_EqualEqual: - eq = fn; - break; - case clang::OO_ExclaimEqual: - ne = fn; - break; - case clang::OO_Less: - lt = fn; - break; - case clang::OO_Spaceship: - cmp = fn; - break; - default: - break; - } - }; - auto consider_decl = [&](const clang::NamedDecl *found) { - if (const auto *tmpl = - clang::dyn_cast(found)) { - for (const auto *spec : tmpl->specializations()) { - consider(spec); - } - return; - } - consider(clang::dyn_cast(found)); - }; - for (const auto *method : decl->methods()) { - consider(method); - } - 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); - } - } - for (const auto *friend_decl : decl->friends()) { - if (const auto *found = friend_decl->getFriendDecl()) { - consider_decl(found); - } - } - - if (eq && ne && !GetComparisonTrait(ne)) { - ConvertEqualityComparableImpl(decl, ne); - } - ConvertPartiallyOrderedWithImpl(decl); - - if (!eq && !lt && !cmp) { - return; - } +void Converter::EmitComparisonBody(llvm::function_ref body) { + PushBrace brace(*this); + PushExprKind push(*this, ExprKind::Void); + ConvertFullExpression(body); +} - ConvertComparisonTraitWrappers(decl, eq, lt, cmp); +const char *Converter::GetComparisonMacro() const { + return "comparison_unsafe!"; } void Converter::AddSpecialMemberDerives(const clang::RecordDecl *decl, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 44dbc79de1..ab8429a521 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -313,6 +314,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetReturnSlotArg(std::string_view receiver) const; + void InitializeReturnSlot(clang::QualType type, clang::Expr *value); + std::string GetReturnSlotParam(clang::QualType type); virtual bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl); @@ -504,25 +507,18 @@ 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; + void EmitComparisonTraits(const clang::CXXRecordDecl *decl); - std::pair - GetComparisonOperandNames(const clang::FunctionDecl *op); + void EmitComparisonTrait(const ComparisonTrait &trait, + const Comparisons &comparisons); - void ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, - const clang::FunctionDecl *op); + void EmitComparisonMethod(std::string_view trait, + const ComparisonRelation &relation, + const Comparisons &comparisons); - void ConvertPartiallyOrderedWithImpl(const clang::CXXRecordDecl *decl); + void EmitComparisonBody(llvm::function_ref body); - std::string GetComparisonCategory(const clang::FunctionDecl *op); + virtual const char *GetComparisonMacro() const; void ConvertParamTy(clang::QualType param_type, clang::Expr *expr); @@ -989,34 +985,6 @@ class Converter : public clang::RecursiveASTVisitor { bool ConvertOutOfLineVirtualMethod(clang::CXXMethodDecl *decl); - void AddOrdTrait(const clang::CXXRecordDecl *decl); - - void ConvertComparisonTraitWrappers(const clang::CXXRecordDecl *decl, - const clang::FunctionDecl *eq, - const clang::FunctionDecl *lt, - const clang::FunctionDecl *cmp); - - std::string GetComparisonCall(const clang::FunctionDecl *op, - const clang::CXXRecordDecl *decl, - std::string_view lhs, std::string_view rhs); - - std::string GetComparisonBool(const clang::FunctionDecl *op, - const clang::CXXRecordDecl *decl, - std::string_view lhs, std::string_view rhs); - - // The argument for param of a comparison operator of decl, from an operand - // of the comparison. - virtual std::string GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *decl, - std::string_view value); - - virtual std::string - GetComparisonResultReceiver(const clang::CXXMethodDecl *method, - bool returns_ref, std::string_view result); - - virtual std::string GetComparisonReceiver(const clang::CXXMethodDecl *method, - std::string_view lhs); - virtual bool RecordImplementsClone(const clang::RecordDecl *decl); bool RecordDerivesTriviallyCopyable(const clang::RecordDecl *decl); @@ -1411,13 +1379,6 @@ class Converter : public clang::RecursiveASTVisitor { static DeferredBlock &DeferredImpl(std::string header); - DeferredBlock &ComparisonTraitImpl(const RecordTrait &trait, - std::string_view self, - std::string_view other); - - void AddComparisonTraitMethod(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 88fc850a5f..df2120e58a 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -681,190 +681,44 @@ clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn) { .getCanonicalType(); } -const clang::FunctionDecl * -FindComparisonOperator(clang::ASTContext &ctx, clang::QualType lhs, - clang::QualType rhs, clang::OverloadedOperatorKind op) { - auto same = [](clang::QualType type, clang::QualType expected) { - return type.getNonReferenceType().getUnqualifiedType().getCanonicalType() == - expected; - }; - auto as_operator = - [&](const clang::NamedDecl *found) -> const clang::FunctionDecl * { +std::vector +GetComparisonOperandTypes(const clang::CXXRecordDecl *decl) { + auto &ctx = decl->getASTContext(); + clang::QualType self = ctx.getCanonicalTagType(decl); + std::vector types; + auto add = [&](const clang::NamedDecl *found) { auto *fn = clang::dyn_cast_or_null(found); - if (!fn || fn->getOverloadedOperator() != op || fn->isDeleted()) { - return nullptr; - } - 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) - ? fn - : nullptr; - } - return fn->getNumParams() == 2 && - same(fn->getParamDecl(0)->getType(), lhs) && - same(fn->getParamDecl(1)->getType(), rhs) - ? fn - : nullptr; - }; - auto name = ctx.DeclarationNames.getCXXOperatorName(op); - for (auto type : {lhs, rhs}) { - auto *record = type->getAsCXXRecordDecl(); - if (!record || !record->hasDefinition()) { - continue; - } - for (auto *method : record->methods()) { - if (auto *fn = as_operator(method)) { - return fn; - } + if (!fn || !IsComparisonOperator(fn) || fn->isDeleted()) { + return; } - for (auto *found : record->getDeclContext()->lookup(name)) { - if (auto *fn = as_operator(found)) { - return fn; - } + auto *record = GetComparisonRecord(fn); + if (!record || record->getCanonicalDecl() != decl->getCanonicalDecl()) { + return; } - for (auto *friend_decl : record->friends()) { - if (auto *fn = as_operator(friend_decl->getFriendDecl())) { - return fn; - } + if (auto rhs = GetComparisonRhsType(fn); + rhs != self && !llvm::is_contained(types, rhs)) { + types.push_back(rhs); } + }; + for (auto *method : decl->methods()) { + add(method); } - return nullptr; -} - -const RecordTrait & -GetPartiallyOrderedWithTrait(clang::OverloadedOperatorKind op) { - switch (op) { - case clang::OO_Less: - return kPartiallyOrderedWith; - case clang::OO_Greater: - return kPartiallyOrderedWithGreater; - case clang::OO_LessEqual: - return kPartiallyOrderedWithLessEqual; - case clang::OO_GreaterEqual: - return kPartiallyOrderedWithGreaterEqual; - default: - llvm_unreachable("not a relational operator"); - } -} - -bool IsPartiallyOrderedWithTrait(const RecordTrait &trait) { - return &trait == &kPartiallyOrderedWith || - &trait == &kPartiallyOrderedWithGreater || - &trait == &kPartiallyOrderedWithLessEqual || - &trait == &kPartiallyOrderedWithGreaterEqual; -} - -bool HasDeferredComparisonImpl(const RecordTrait &trait) { - return IsEqualityComparableTrait(trait) || IsPartiallyOrderedWithTrait(trait); -} - -bool IsPartiallyOrdered(clang::ASTContext &ctx, - const clang::CXXRecordDecl *record) { - clang::QualType type = ctx.getCanonicalTagType(record); - auto *cmp = FindComparisonOperator(ctx, type, type, clang::OO_Spaceship); - if (cmp && ctx.CompCategories.lookupInfoForType(cmp->getReturnType())) { - return true; - } - return llvm::all_of(std::array{clang::OO_Less, clang::OO_Greater, - clang::OO_LessEqual, clang::OO_GreaterEqual}, - [&](clang::OverloadedOperatorKind op) { - return FindComparisonOperator(ctx, type, type, op); - }); -} - -static bool TakesConstReferenceOperands(const clang::FunctionDecl *fn) { - if (auto *method = clang::dyn_cast(fn); - method && (method->isVirtual() || !method->isConst() || - !method->isImplicitObjectMemberFunction() || - method->getRefQualifier() == clang::RQ_RValue)) { - return false; - } - return llvm::all_of(fn->parameters(), [](const clang::ParmVarDecl *param) { - auto type = param->getType(); - return type->isLValueReferenceType() && - type.getNonReferenceType().isConstQualified(); - }); -} - -const clang::FunctionDecl * -GetDerivingThreeWayOperator(clang::ASTContext &ctx, - const clang::CXXRecordDecl *record) { - clang::QualType type = ctx.getCanonicalTagType(record); - auto *cmp = FindComparisonOperator(ctx, type, type, clang::OO_Spaceship); - if (!cmp || !ctx.CompCategories.lookupInfoForType(cmp->getReturnType()) || - !TakesConstReferenceOperands(cmp)) { - return nullptr; + for (auto *friend_decl : decl->friends()) { + add(friend_decl->getFriendDecl()); } - for (auto op : - {clang::OO_Greater, clang::OO_LessEqual, clang::OO_GreaterEqual}) { - if (FindComparisonOperator(ctx, type, type, op)) { - return nullptr; + for (auto op : {clang::OO_EqualEqual, clang::OO_ExclaimEqual, clang::OO_Less, + clang::OO_Greater, clang::OO_LessEqual, + clang::OO_GreaterEqual, clang::OO_Spaceship}) { + for (auto *found : decl->getEnclosingNamespaceContext()->lookup( + ctx.DeclarationNames.getCXXOperatorName(op))) { + add(found); } } - return cmp; -} - -const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { - auto op = fn->getOverloadedOperator(); - bool is_relational = op == clang::OO_Greater || op == clang::OO_LessEqual || - op == clang::OO_GreaterEqual; - bool is_three_way = op == clang::OO_Spaceship; - if (op != clang::OO_EqualEqual && op != clang::OO_ExclaimEqual && - op != clang::OO_Less && !is_relational && !is_three_way) { - return nullptr; - } - auto *record = GetComparisonRecord(fn); - if (!record || !IsUserDefinedDecl(record) || fn->isDeleted() || - fn->getDescribedFunctionTemplate()) { - return nullptr; - } - auto &ctx = fn->getASTContext(); - if (is_three_way ? !ctx.CompCategories.lookupInfoForType(fn->getReturnType()) - : !fn->getReturnType()->isBooleanType()) { - return nullptr; - } - if (auto *method = clang::dyn_cast(fn); - method ? method->getNumParams() != 1 : fn->getNumParams() != 2) { - return nullptr; - } - if (!TakesConstReferenceOperands(fn)) { - return nullptr; - } - if (op == clang::OO_Less) { - return IsSameTypeComparison(fn, record) ? &kLessThanComparable : nullptr; - } - if (is_three_way) { - clang::QualType type = ctx.getCanonicalTagType(record); - return IsSameTypeComparison(fn, record) && - FindComparisonOperator(ctx, type, type, clang::OO_EqualEqual) - ? &kThreeWayComparable - : nullptr; - } - if (is_relational) { - return IsSameTypeComparison(fn, record) && IsPartiallyOrdered(ctx, record) - ? &GetPartiallyOrderedWithTrait(op) - : nullptr; - } - if (op == clang::OO_EqualEqual) { - return &kWeaklyEqualityComparableWith; - } - return FindComparisonOperator(ctx, ctx.getCanonicalTagType(record), - GetComparisonRhsType(fn), clang::OO_EqualEqual) - ? &kWeaklyEqualityComparableWithNotEqual - : nullptr; -} - -bool IsEqualityComparableTrait(const RecordTrait &trait) { - return &trait == &kWeaklyEqualityComparableWith || - &trait == &kWeaklyEqualityComparableWithNotEqual; + return types; } 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 @@ -923,8 +777,7 @@ bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { ctor && ctor->isDefaultConstructor()) { return false; } - return !method->isUserProvided() && !GetComparisonTrait(method) && - GetRecordTrait(method); + return !method->isUserProvided() && GetRecordTrait(method); } std::vector GetDerivedCopyOrMoves(const clang::RecordDecl *decl) { @@ -2088,21 +1941,6 @@ const char *GetOverloadedOperator(const clang::FunctionDecl *decl) { } } -bool IsSameTypeComparison(const clang::FunctionDecl *fn, - const clang::CXXRecordDecl *record) { - auto record_type = fn->getASTContext().getCanonicalTagType(record); - auto is_record = [&](clang::QualType type) { - return type.getNonReferenceType().getUnqualifiedType().getCanonicalType() == - record_type; - }; - if (const auto *method = clang::dyn_cast(fn)) { - return method->isInstance() && method->getNumParams() == 1 && - is_record(method->getParamDecl(0)->getType()); - } - return fn->getNumParams() == 2 && is_record(fn->getParamDecl(0)->getType()) && - is_record(fn->getParamDecl(1)->getType()); -} - bool IsImplicitAssignmentCall(const clang::CallExpr *expr) { const auto *call = clang::dyn_cast(expr); if (!call) { @@ -2458,11 +2296,134 @@ bool IsComparisonOperator(const clang::FunctionDecl *fn) { } } +namespace { +class TranslationUnitScope { +public: + explicit TranslationUnitScope(clang::Sema &sema) + : sema_(sema), + scope_(nullptr, clang::Scope::DeclScope, sema.getDiagnostics()) { + scope_.setEntity(sema.Context.getTranslationUnitDecl()); + saved_ = std::exchange(sema.TUScope, &scope_); + } + + ~TranslationUnitScope() { sema_.TUScope = saved_; } + + TranslationUnitScope(const TranslationUnitScope &) = delete; + + TranslationUnitScope &operator=(const TranslationUnitScope &) = delete; + + clang::Scope *get() { return &scope_; } + +private: + clang::Sema &sema_; + clang::Scope scope_; + clang::Scope *saved_; +}; +} // namespace + +static clang::Expr *BuildComparison(clang::Sema &sema, + clang::BinaryOperatorKind op, + clang::Expr *lhs, clang::Expr *rhs, + bool is_test) { + TranslationUnitScope tu_scope(sema); + RuleDecls::Trial trial(sema); + clang::ExprResult result; + { + clang::Sema::GlobalEagerInstantiationScope instantiations( + sema, /*Enabled=*/true, /*AtEndOfTU=*/false); + result = sema.BuildBinOp(tu_scope.get(), lhs->getExprLoc(), op, lhs, rhs); + if (is_test && result.isUsable()) { + result = sema.PerformContextuallyConvertToBool(result.get()); + } + if (result.isUsable()) { + result = sema.ActOnFinishFullExpr(result.get(), /*DiscardedValue=*/false); + } + instantiations.perform(); + } + return result.isUsable() && !trial.failed() ? result.get() : nullptr; +} + +bool Comparisons::Has(const ComparisonTrait &trait) const { + return llvm::all_of(trait.relations, + [&](const ComparisonRelation &relation) { + return exprs.at(relation.op) && + (!relation.test_method || tests.at(relation.op)); + }) && + (!trait.supertrait || Has(*trait.supertrait)); +} + +bool SatisfiesComparisonTrait(const ComparisonTrait &trait, + const Comparisons &forward, + const Comparisons &reverse) { + return forward.Has(trait) && (!trait.is_symmetric || reverse.Has(trait)); +} + +static Comparisons +BuildComparisons(clang::Sema &sema, clang::BlockDecl *context, + clang::QualType lhs, clang::QualType rhs, + std::span traits) { + auto &ctx = sema.getASTContext(); + auto loc = context->getCaretLocation(); + auto operand = [&](llvm::StringRef name, clang::QualType type) { + auto reference = ctx.getLValueReferenceType(type.withConst()); + return clang::VarDecl::Create( + ctx, context, loc, loc, &ctx.Idents.get(name), reference, + ctx.getTrivialTypeSourceInfo(reference, loc), clang::SC_None); + }; + Comparisons comparisons{ + lhs, rhs, operand("__lhs", lhs), operand("__rhs", rhs), {}}; + auto refer = [&](clang::VarDecl *var) -> clang::Expr * { + return clang::DeclRefExpr::Create(ctx, {}, {}, var, false, loc, + var->getType().getNonReferenceType(), + clang::VK_LValue); + }; + for (const auto *trait : traits) { + for (const auto &relation : trait->relations) { + if (comparisons.exprs.contains(relation.op)) { + continue; + } + auto *result = BuildComparison(sema, relation.op, refer(comparisons.lhs), + refer(comparisons.rhs), false); + comparisons.exprs.emplace(relation.op, result); + if (result && relation.test_method) { + comparisons.tests.emplace( + relation.op, + BuildComparison(sema, relation.op, refer(comparisons.lhs), + refer(comparisons.rhs), true)); + } + } + } + return comparisons; +} + +const RecordComparisons & +GetRecordComparisons(clang::Sema &sema, const clang::CXXRecordDecl *decl) { + static std::unordered_map + built; + decl = decl->getCanonicalDecl(); + if (auto it = built.find(decl); it != built.end()) { + return it->second; + } + auto &ctx = sema.getASTContext(); + auto *context = clang::BlockDecl::Create(ctx, ctx.getTranslationUnitDecl(), + decl->getLocation()); + clang::QualType self = ctx.getCanonicalTagType(decl); + RecordComparisons comparisons{ + BuildComparisons(sema, context, self, self, kHomogeneousComparisonTraits), + {}}; + for (auto other : GetComparisonOperandTypes(decl)) { + comparisons.others.push_back( + {other, + BuildComparisons(sema, context, self, other, + kHeterogeneousComparisonTraits), + BuildComparisons(sema, context, other, self, + kHeterogeneousComparisonTraits)}); + } + return built.emplace(decl, std::move(comparisons)).first->second; +} + void DefineImplicitMembers(clang::Sema &sema, clang::CXXRecordDecl *decl) { - clang::Scope tu_scope(nullptr, clang::Scope::DeclScope, - sema.getDiagnostics()); - tu_scope.setEntity(sema.Context.getTranslationUnitDecl()); - auto *saved_tu_scope = std::exchange(sema.TUScope, &tu_scope); + TranslationUnitScope tu_scope(sema); sema.ForceDeclarationOfImplicitMembers(decl); for (auto *field : decl->fields()) { if (field->hasInClassInitializer() && !field->getInClassInitializer()) { @@ -2549,7 +2510,6 @@ void DefineImplicitMembers(clang::Sema &sema, clang::CXXRecordDecl *decl) { define_defaulted_comparison(clang::dyn_cast_or_null( friend_decl->getFriendDecl())); } - sema.TUScope = saved_tu_scope; } bool IsEmittableMethod(clang::CXXMethodDecl *method) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 51b08bcb1c..5eab57aab1 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -14,9 +14,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -169,59 +171,6 @@ 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 kLessThanComparable{ - "less", - {"LessThanComparable", "fn less(this: Ptr, _: Ptr) -> bool", - "this.clone()"}, - {"LessThanComparableUnsafe", - "unsafe fn less(this: *const Self, _: *const Self) -> bool", "this"}}; -inline constexpr RecordTrait kPartiallyOrderedWith{ - "less", - {"PartiallyOrderedWith", "fn less(this: Ptr, _: Ptr) -> bool", - "this.clone()"}, - {"PartiallyOrderedWithUnsafe", - "unsafe fn less(this: *const Self, _: *const Self) -> bool", "this"}}; -inline constexpr RecordTrait kPartiallyOrderedWithGreater{ - "greater", - {"PartiallyOrderedWith", - "fn greater(this: Ptr, _: Ptr) -> bool", "this.clone()"}, - {"PartiallyOrderedWithUnsafe", - "unsafe fn greater(this: *const Self, _: *const Self) -> bool", "this"}}; -inline constexpr RecordTrait kPartiallyOrderedWithLessEqual{ - "less_equal", - {"PartiallyOrderedWith", - "fn less_equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, - {"PartiallyOrderedWithUnsafe", - "unsafe fn less_equal(this: *const Self, _: *const Self) -> bool", - "this"}}; -inline constexpr RecordTrait kPartiallyOrderedWithGreaterEqual{ - "greater_equal", - {"PartiallyOrderedWith", - "fn greater_equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, - {"PartiallyOrderedWithUnsafe", - "unsafe fn greater_equal(this: *const Self, _: *const Self) -> bool", - "this"}}; -inline constexpr RecordTrait kThreeWayComparable{ - "three_way", - {"ThreeWayComparable", - "fn three_way(this: Ptr, _: Ptr) -> Self::Category", - "this.clone()"}, - {"ThreeWayComparableUnsafe", - "unsafe fn three_way(this: *const Self, _: *const Self) -> " - "Self::Category", - "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, @@ -244,31 +193,98 @@ bool IsConstructibleFromConstructor(const clang::FunctionDecl *decl); const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl); -const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); +struct ComparisonRelation { + clang::BinaryOperatorKind op; + const char *method; + const char *test_method; + const char *result; +}; -bool IsEqualityComparableTrait(const RecordTrait &trait); +struct ComparisonTrait { + RecordTrait trait; + std::span relations; + const ComparisonTrait *supertrait = nullptr; + bool is_symmetric = false; +}; -bool IsPartiallyOrderedWithTrait(const RecordTrait &trait); +inline constexpr ComparisonRelation kEqualRelations[] = { + {clang::BO_EQ, "equal", "is_equal", "EqualResult"}}; +inline constexpr ComparisonRelation kNotEqualRelations[] = { + {clang::BO_NE, "not_equal", "is_not_equal", "NotEqualResult"}}; +inline constexpr ComparisonRelation kLessThanRelations[] = { + {clang::BO_LT, "less", "is_less", "Result"}}; +inline constexpr ComparisonRelation kOrderingRelations[] = { + {clang::BO_GT, "greater", "is_greater", "GreaterResult"}, + {clang::BO_LE, "less_equal", "is_less_equal", "LessEqualResult"}, + {clang::BO_GE, "greater_equal", "is_greater_equal", "GreaterEqualResult"}}; +inline constexpr ComparisonRelation kThreeWayRelations[] = { + {clang::BO_Cmp, "three_way", nullptr, "Category"}}; + +inline constexpr ComparisonTrait kCpp17EqualityComparable{ + {nullptr, {"Cpp17EqualityComparable"}, {"Cpp17EqualityComparableUnsafe"}}, + kEqualRelations}; +inline constexpr ComparisonTrait kWeaklyEqualityComparableWith{ + {nullptr, + {"WeaklyEqualityComparableWith"}, + {"WeaklyEqualityComparableWithUnsafe"}}, + kNotEqualRelations, + &kCpp17EqualityComparable, + true}; +inline constexpr ComparisonTrait kLessThanComparable{ + {nullptr, {"LessThanComparable"}, {"LessThanComparableUnsafe"}}, + kLessThanRelations}; +inline constexpr ComparisonTrait kPartiallyOrderedWith{ + {nullptr, {"PartiallyOrderedWith"}, {"PartiallyOrderedWithUnsafe"}}, + kOrderingRelations, + &kLessThanComparable, + true}; +inline constexpr ComparisonTrait kThreeWayComparable{ + {nullptr, {"ThreeWayComparable"}, {"ThreeWayComparableUnsafe"}}, + kThreeWayRelations}; -bool HasDeferredComparisonImpl(const RecordTrait &trait); +clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn); -const RecordTrait & -GetPartiallyOrderedWithTrait(clang::OverloadedOperatorKind op); +const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn); -bool IsPartiallyOrdered(clang::ASTContext &ctx, - const clang::CXXRecordDecl *record); +std::vector +GetComparisonOperandTypes(const clang::CXXRecordDecl *decl); -const clang::FunctionDecl * -GetDerivingThreeWayOperator(clang::ASTContext &ctx, - const clang::CXXRecordDecl *record); +struct Comparisons { + clang::QualType lhs_type; + clang::QualType rhs_type; + clang::VarDecl *lhs; + clang::VarDecl *rhs; + std::unordered_map exprs; + std::unordered_map tests; -clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn); + bool Has(const ComparisonTrait &trait) const; +}; -const clang::FunctionDecl * -FindComparisonOperator(clang::ASTContext &ctx, clang::QualType lhs, - clang::QualType rhs, clang::OverloadedOperatorKind op); +struct HeterogeneousComparisons { + clang::QualType other; + Comparisons forward; + Comparisons reverse; +}; -const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn); +struct RecordComparisons { + Comparisons self; + std::vector others; +}; + +inline constexpr const ComparisonTrait *kHomogeneousComparisonTraits[] = { + &kCpp17EqualityComparable, &kWeaklyEqualityComparableWith, + &kLessThanComparable, &kPartiallyOrderedWith, &kThreeWayComparable}; + +inline constexpr const ComparisonTrait *kHeterogeneousComparisonTraits[] = { + &kCpp17EqualityComparable, &kWeaklyEqualityComparableWith, + &kLessThanComparable, &kPartiallyOrderedWith}; + +bool SatisfiesComparisonTrait(const ComparisonTrait &trait, + const Comparisons &forward, + const Comparisons &reverse); + +const RecordComparisons &GetRecordComparisons(clang::Sema &sema, + const clang::CXXRecordDecl *decl); // 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. @@ -507,9 +523,6 @@ clang::QualType GetDeclRefType(const clang::FunctionDecl *fn, const clang::Expr *expr, const clang::ValueDecl *decl); -bool IsSameTypeComparison(const clang::FunctionDecl *fn, - const clang::CXXRecordDecl *record); - clang::CXXDestructorDecl * GetUserDefinedDestructor(const clang::CXXRecordDecl *decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3435b57a9b..5bae07984e 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -646,46 +646,6 @@ bool ConverterRefCount::VisitOffsetOfExpr(clang::OffsetOfExpr *expr) { return false; } -// The operands of comparison operators are pointers to the values (&Ptr). -std::string -ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *decl, - std::string_view value) { - if (param->getType()->isReferenceType()) { - return std::format("{}.clone()", value); - } - if (IsTriviallyCopyable(decl)) { - return std::format("{}.read()", value); - } - auto record = GetRecordName(decl); - return std::format("{{ {} <{} as CopyConstructible>::copy_constructor({}, " - "LvalueRef::bind({}.clone())); {} }}", - CreatePlacementStorage(record), record, - GetPlacementReceiver(), value, TakePlacementValue()); -} - -std::string ConverterRefCount::GetComparisonResultReceiver( - const clang::CXXMethodDecl *, bool returns_ref, std::string_view result) { - if (returns_ref) { - return std::format("{}.clone()", result); - } - PushConversionKind push(*this, ConversionKind::FullRefCount); - return std::format("{}.as_pointer()", BoxValue(std::string(result))); -} - -std::string -ConverterRefCount::GetComparisonReceiver(const clang::CXXMethodDecl *, - std::string_view lhs) { - return std::format("{}.clone()", lhs); -} - -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. static bool IsClonedShallowly(const clang::RecordDecl *decl) { return decl->isUnion() || (HasDefaultedCopyConstructor(decl) && @@ -3624,6 +3584,10 @@ ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { const char *ConverterRefCount::GetObjectMacro() const { return "object!"; } +const char *ConverterRefCount::GetComparisonMacro() const { + return "comparison!"; +} + std::string ConverterRefCount::GetStorageReceiver(std::string_view name) const { return std::format("{}.clone()", name); } diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index b65cd7cfbd..568475720e 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -52,22 +52,6 @@ class ConverterRefCount final : public Converter { const char *CharRustType() const override { return "i8"; } - std::string GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *decl, - std::string_view value) override; - - std::string GetComparisonResultReceiver(const clang::CXXMethodDecl *method, - bool returns_ref, - std::string_view result) override; - - std::string GetComparisonReceiver(const clang::CXXMethodDecl *method, - std::string_view lhs) 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); @@ -91,6 +75,8 @@ class ConverterRefCount final : public Converter { const char *GetObjectMacro() const override; + const char *GetComparisonMacro() const override; + std::string GetStorageReceiver(std::string_view name) const override; const char *GetAssignMacro() const override; diff --git a/cpp2rust/converter/rules/rules_loader.cpp b/cpp2rust/converter/rules/rules_loader.cpp index f969e9168f..b6f09835f8 100644 --- a/cpp2rust/converter/rules/rules_loader.cpp +++ b/cpp2rust/converter/rules/rules_loader.cpp @@ -53,14 +53,35 @@ class RuleUsageCollector } bool VisitCXXRecordDecl(clang::CXXRecordDecl *decl) { + if (auto *spec = + clang::dyn_cast(decl); + spec && IsLibraryOnlySpecialization(spec)) { + return true; + } if (decl->isThisDeclarationADefinition() && !decl->isDependentType() && IsConvertibleCXXRecordDecl(decl) && (decl->isStruct() || decl->isClass()) && !decl->isAbstract()) { DefineImplicitMembers(sema_, decl); + const auto &comparisons = GetRecordComparisons(sema_, decl); + TraverseComparisons(comparisons.self); + for (const auto &other : comparisons.others) { + TraverseComparisons(other.forward); + TraverseComparisons(other.reverse); + } } return true; } + void TraverseComparisons(const Comparisons &comparisons) { + for (const auto *exprs : {&comparisons.exprs, &comparisons.tests}) { + for (const auto &[op, expr] : *exprs) { + if (expr) { + TraverseStmt(expr); + } + } + } + } + bool VisitExpr(clang::Expr *expr) { if (expr->isTypeDependent() || expr->isValueDependent()) { return true; diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 4c2bebaf7f..bac10e9491 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -12,7 +12,6 @@ mod fn_ptr_arg; mod goto; mod initialization; mod lambda; -mod partially_ordered; mod record; mod state_machine; mod switch; @@ -360,13 +359,3 @@ pub fn derive_destructible(input: TokenStream) -> TokenStream { pub fn derive_destructible_unsafe(input: TokenStream) -> TokenStream { destructor::expand(input, true) } - -#[proc_macro_derive(PartiallyOrderedWith, attributes(three_way))] -pub fn derive_partially_ordered_with(input: TokenStream) -> TokenStream { - partially_ordered::expand(input, false) -} - -#[proc_macro_derive(PartiallyOrderedWithUnsafe, attributes(three_way))] -pub fn derive_partially_ordered_with_unsafe(input: TokenStream) -> TokenStream { - partially_ordered::expand(input, true) -} diff --git a/libcc2rs-macros/src/partially_ordered.rs b/libcc2rs-macros/src/partially_ordered.rs deleted file mode 100644 index 0028da1311..0000000000 --- a/libcc2rs-macros/src/partially_ordered.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - -use proc_macro::TokenStream; -use quote::quote; -use syn::{DeriveInput, parse_macro_input}; - -pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - let name = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let three_way: syn::Path = input - .attrs - .iter() - .find(|attr| attr.path().is_ident("three_way")) - .expect("three_way(path) names the operator<=> of the type") - .parse_args() - .expect("three_way(path)"); - let relations = [ - (quote!(greater), quote!(is_gt)), - (quote!(less_equal), quote!(is_lteq)), - (quote!(greater_equal), quote!(is_gteq)), - ]; - if is_unsafe { - let methods = relations.iter().map(|(method, relation)| { - quote! { - unsafe fn #method(this: *const Self, rhs: *const Self) -> bool { - ::libcc2rs::#relation(unsafe { #three_way(this, rhs) }) - } - } - }); - return quote! { - impl #impl_generics ::libcc2rs::PartiallyOrderedWithUnsafe for #name #ty_generics #where_clause { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - unsafe { ::less(this, rhs) } - } - #(#methods)* - } - } - .into(); - } - let methods = relations.iter().map(|(method, relation)| { - quote! { - fn #method(this: ::libcc2rs::Ptr, rhs: ::libcc2rs::Ptr) -> bool { - ::libcc2rs::#relation(#three_way(this, rhs)) - } - } - }); - quote! { - impl #impl_generics ::libcc2rs::PartiallyOrderedWith for #name #ty_generics #where_clause { - fn less(this: ::libcc2rs::Ptr, rhs: ::libcc2rs::Ptr) -> bool { - ::less(this, rhs) - } - #(#methods)* - } - } - .into() -} diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index c6875abcf7..f7c802bb2a 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -6,43 +6,94 @@ use std::cmp::Ordering; +use crate::overload::{ConvertibleTo, ConvertibleToUnsafe}; use crate::rc::{AsPointer, Ptr, Value}; +use crate::reference::{Const, LvalueRef, LvalueRefUnsafe}; use crate::reinterpret::ByteRepr; -pub trait LessThanComparable: Sized { - fn less(this: Ptr, rhs: Ptr) -> bool; +pub trait BooleanTestable: ConvertibleTo {} + +impl> BooleanTestable for T {} + +pub trait BooleanTestableUnsafe: ConvertibleToUnsafe {} + +impl> BooleanTestableUnsafe for T {} + +pub trait LessThanComparable: ByteRepr + Sized { + type Result: BooleanTestable; + + fn less(__return: Ptr, a: LvalueRef>, b: LvalueRef>); + fn is_less(a: LvalueRef>, b: LvalueRef>) -> bool; } -pub trait LessThanComparableUnsafe: Sized { +pub trait LessThanComparableUnsafe: Sized { + type Result: BooleanTestableUnsafe; + + /// # Safety + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn less( + __return: *mut Self::Result, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn less(this: *const Self, rhs: *const Self) -> bool; + /// `a` and `b` must refer to live values. + unsafe fn is_less(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool; +} + +pub trait Cpp17EqualityComparable: ByteRepr + Sized { + type EqualResult: BooleanTestable; + + fn equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>); + fn is_equal(a: LvalueRef>, b: LvalueRef>) -> bool; +} + +pub trait Cpp17EqualityComparableUnsafe: Sized { + type EqualResult: BooleanTestableUnsafe; + + /// # Safety + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn equal( + __return: *mut Self::EqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); + /// # Safety + /// `a` and `b` must refer to live values. + unsafe fn is_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool; } -// TODO: equal and not_equal return a boolean-testable type in C++ -// ([concept.booleantestable]); replace bool with BooleanTestable. pub trait WeaklyEqualityComparableWith = Self>: - Sized + Cpp17EqualityComparable { - fn equal(this: Ptr, rhs: Ptr) -> bool; - - fn not_equal(this: Ptr, rhs: Ptr) -> bool { - !Self::equal(this, rhs) - } + type NotEqualResult: BooleanTestable; + + fn not_equal( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ); + fn is_not_equal(a: LvalueRef>, b: LvalueRef>) -> bool; } pub trait WeaklyEqualityComparableWithUnsafe = Self>: - Sized + Cpp17EqualityComparableUnsafe { - /// # Safety - /// `rhs` must point to a live value. - unsafe fn equal(this: *const Self, rhs: *const U) -> bool; + type NotEqualResult: BooleanTestableUnsafe; /// # 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) } - } + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn not_equal( + __return: *mut Self::NotEqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); + /// # Safety + /// `a` and `b` must refer to live values. + unsafe fn is_not_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool; } pub trait EqualityComparable: WeaklyEqualityComparableWith {} @@ -84,8 +135,21 @@ macro_rules! impl_less_than_comparable { where $ty: PartialOrd + $crate::ByteRepr, { - fn less(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a < b)) + type Result = bool; + + fn less( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_less(a, b)); + } + + fn is_less( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().with(|b| a < b)) } } )*}; @@ -97,8 +161,23 @@ macro_rules! impl_less_than_comparable_unsafe { where $ty: PartialOrd, { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this < *rhs } + type Result = bool; + + unsafe fn less( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write(::is_less(a, b)); + } + } + + unsafe fn is_less( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() < *b.as_const_ptr() } } } )*}; @@ -116,15 +195,27 @@ impl_less_than_comparable_unsafe!( *mut T, *const T, ); -impl LessThanComparable for Vec { - fn less(this: Ptr, rhs: Ptr) -> bool { - let (m, n) = (this.with(Vec::len), rhs.with(Vec::len)); - let (a, b) = (this.decay(), rhs.decay()); +impl LessThanComparable for Vec +where + Self: ByteRepr, +{ + type Result = bool; + + fn less(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_less(a, b)); + } + + fn is_less(a: LvalueRef>, b: LvalueRef>) -> bool { + let (a, b) = (a.as_pointer(), b.as_pointer()); + let (m, n) = (a.with(Vec::len), b.with(Vec::len)); + let (a, b) = (a.decay(), b.decay()); for i in 0..m.min(n) { - if T::less(a.offset(i), b.offset(i)) { + let (x, y) = (LvalueRef::bind(a.offset(i)), LvalueRef::bind(b.offset(i))); + if T::is_less(x, y) { return true; } - if T::less(b.offset(i), a.offset(i)) { + let (x, y) = (LvalueRef::bind(b.offset(i)), LvalueRef::bind(a.offset(i))); + if T::is_less(x, y) { return false; } } @@ -132,18 +223,24 @@ impl LessThanComparable for Vec { } } -impl LessThanComparable for Box<[T]> { - fn less(this: Ptr, rhs: Ptr) -> bool { - let (m, n) = ( - this.with(|elems| elems.len()), - rhs.with(|elems| elems.len()), - ); - let (a, b) = (this.decay(), rhs.decay()); +impl LessThanComparable for Box<[T]> { + type Result = bool; + + fn less(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_less(a, b)); + } + + fn is_less(a: LvalueRef>, b: LvalueRef>) -> bool { + let (a, b) = (a.as_pointer(), b.as_pointer()); + let (m, n) = (a.with(|elems| elems.len()), b.with(|elems| elems.len())); + let (a, b) = (a.decay(), b.decay()); for i in 0..m.min(n) { - if T::less(a.offset(i), b.offset(i)) { + let (x, y) = (LvalueRef::bind(a.offset(i)), LvalueRef::bind(b.offset(i))); + if T::is_less(x, y) { return true; } - if T::less(b.offset(i), a.offset(i)) { + let (x, y) = (LvalueRef::bind(b.offset(i)), LvalueRef::bind(a.offset(i))); + if T::is_less(x, y) { return false; } } @@ -155,29 +252,61 @@ impl LessThanComparable for (Value where Self: ByteRepr, { - fn less(this: Ptr, rhs: Ptr) -> bool { + type Result = bool; + + fn less(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_less(a, b)); + } + + fn is_less(a: LvalueRef>, b: LvalueRef>) -> 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::less(a0.clone(), b0.clone()) || (!A::less(b0, a0) && B::less(a1, b1)) + let (a0, a1) = a.as_pointer().with(pointers); + let (b0, b1) = b.as_pointer().with(pointers); + let (x, y) = (LvalueRef::bind(a0.clone()), LvalueRef::bind(b0.clone())); + if A::is_less(x, y) { + return true; + } + if A::is_less(LvalueRef::bind(b0), LvalueRef::bind(a0)) { + return false; + } + B::is_less(LvalueRef::bind(a1), LvalueRef::bind(b1)) } } impl LessThanComparableUnsafe for Vec { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { + type Result = bool; + + unsafe fn less( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_less(a, b)) } + } + + unsafe fn is_less(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool { unsafe { - let (m, n) = ((*this).len(), (*rhs).len()); - let (a, b) = ((*this).as_ptr(), (*rhs).as_ptr()); + let (a, b) = (a.as_const_ptr(), b.as_const_ptr()); + let (m, n) = ((*a).len(), (*b).len()); + let (a, b) = ((*a).as_ptr(), (*b).as_ptr()); for i in 0..m.min(n) { - if T::less(a.add(i), b.add(i)) { + let (x, y) = ( + LvalueRefUnsafe::bind(a.add(i)), + LvalueRefUnsafe::bind(b.add(i)), + ); + if T::is_less(x, y) { return true; } - if T::less(b.add(i), a.add(i)) { + let (x, y) = ( + LvalueRefUnsafe::bind(b.add(i)), + LvalueRefUnsafe::bind(a.add(i)), + ); + if T::is_less(x, y) { return false; } } @@ -187,14 +316,32 @@ impl LessThanComparableUnsafe for Vec { } impl LessThanComparableUnsafe for [T; N] { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - let (a, b) = (this as *const T, rhs as *const T); + type Result = bool; + + unsafe fn less( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_less(a, b)) } + } + + unsafe fn is_less(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool { + let (a, b) = (a.as_const_ptr().cast::(), b.as_const_ptr().cast::()); for i in 0..N { unsafe { - if T::less(a.add(i), b.add(i)) { + let (x, y) = ( + LvalueRefUnsafe::bind(a.add(i)), + LvalueRefUnsafe::bind(b.add(i)), + ); + if T::is_less(x, y) { return true; } - if T::less(b.add(i), a.add(i)) { + let (x, y) = ( + LvalueRefUnsafe::bind(b.add(i)), + LvalueRefUnsafe::bind(a.add(i)), + ); + if T::is_less(x, y) { return false; } } @@ -204,23 +351,110 @@ impl LessThanComparableUnsafe for [ } impl LessThanComparableUnsafe for (A, B) { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { + type Result = bool; + + unsafe fn less( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_less(a, b)) } + } + + unsafe fn is_less(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool { unsafe { - A::less(&raw const (*this).0, &raw const (*rhs).0) - || (!A::less(&raw const (*rhs).0, &raw const (*this).0) - && B::less(&raw const (*this).1, &raw const (*rhs).1)) + let (a, b) = (a.as_const_ptr(), b.as_const_ptr()); + let (a0, b0) = (&raw const (*a).0, &raw const (*b).0); + let (a1, b1) = (&raw const (*a).1, &raw const (*b).1); + let (x, y) = (LvalueRefUnsafe::bind(a0), LvalueRefUnsafe::bind(b0)); + if A::is_less(x, y) { + return true; + } + let (x, y) = (LvalueRefUnsafe::bind(b0), LvalueRefUnsafe::bind(a0)); + if A::is_less(x, y) { + return false; + } + let (x, y) = (LvalueRefUnsafe::bind(a1), LvalueRefUnsafe::bind(b1)); + B::is_less(x, y) } } } +macro_rules! impl_cpp17_equality_comparable { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::Cpp17EqualityComparable for $ty + where + $ty: PartialEq + $crate::ByteRepr, + { + type EqualResult = bool; + + fn equal( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_equal(a, b)); + } + + fn is_equal( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().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)) + type NotEqualResult = bool; + + fn not_equal( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_not_equal(a, b)); + } + + fn is_not_equal( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().with(|b| a != b)) + } + } + )*}; +} + +macro_rules! impl_cpp17_equality_comparable_unsafe { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::Cpp17EqualityComparableUnsafe for $ty + where + $ty: PartialEq, + { + type EqualResult = bool; + + unsafe fn equal( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write(::is_equal(a, b)); + } + } + + unsafe fn is_equal( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() == *b.as_const_ptr() } } } )*}; @@ -232,106 +466,386 @@ macro_rules! impl_weakly_equality_comparable_with_unsafe { where $ty: PartialEq, { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this == *rhs } + type NotEqualResult = bool; + + unsafe fn not_equal( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write( + ::is_not_equal(a, b), + ); + } + } + + unsafe fn is_not_equal( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() != *b.as_const_ptr() } } } )*}; } +impl_cpp17_equality_comparable!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + Ptr, Option, +); + 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 Cpp17EqualityComparable for Vec +where + Self: ByteRepr, +{ + type EqualResult = bool; + + fn equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_equal(a, b)); + } + + fn is_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + let (a, b) = (a.as_pointer(), b.as_pointer()); + let len = a.with(Vec::len); + if len != b.with(Vec::len) { + return false; + } + let (a, b) = (a.decay(), b.decay()); + (0..len).all(|i| { + let (x, y) = (LvalueRef::bind(a.offset(i)), LvalueRef::bind(b.offset(i))); + T::is_equal(x, y) + }) + } +} + +impl WeaklyEqualityComparableWith for Vec +where + Self: ByteRepr, +{ + type NotEqualResult = bool; + + fn not_equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_not_equal(a, b)); + } + + fn is_not_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + !Self::is_equal(a, b) } } -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 Cpp17EqualityComparable for Box<[T]> { + type EqualResult = bool; + + fn equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_equal(a, b)); + } + + fn is_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + let (a, b) = (a.as_pointer(), b.as_pointer()); + let len = a.with(|elems| elems.len()); + if len != b.with(|elems| elems.len()) { + return false; + } + let (a, b) = (a.decay(), b.decay()); + (0..len).all(|i| { + let (x, y) = (LvalueRef::bind(a.offset(i)), LvalueRef::bind(b.offset(i))); + T::is_equal(x, y) + }) } } -impl WeaklyEqualityComparableWith +impl WeaklyEqualityComparableWith for Box<[T]> { + type NotEqualResult = bool; + + fn not_equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_not_equal(a, b)); + } + + fn is_not_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + !Self::is_equal(a, b) + } +} + +impl Cpp17EqualityComparable for (Value, Value) where Self: ByteRepr, { - fn equal(this: Ptr, rhs: Ptr) -> bool { + type EqualResult = bool; + + fn equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_equal(a, b)); + } + + fn is_equal(a: LvalueRef>, b: LvalueRef>) -> 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) + let (a0, a1) = a.as_pointer().with(pointers); + let (b0, b1) = b.as_pointer().with(pointers); + let (x, y) = (LvalueRef::bind(a0), LvalueRef::bind(b0)); + if !A::is_equal(x, y) { + return false; + } + B::is_equal(LvalueRef::bind(a1), LvalueRef::bind(b1)) + } +} + +impl WeaklyEqualityComparableWith + for (Value, Value) +where + Self: ByteRepr, +{ + type NotEqualResult = bool; + + fn not_equal(__return: Ptr, a: LvalueRef>, b: LvalueRef>) { + __return.write(Self::is_not_equal(a, b)); + } + + fn is_not_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + !Self::is_equal(a, b) } } +impl_cpp17_equality_comparable_unsafe!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + *mut T, *const T, Option, +); + 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 { +impl Cpp17EqualityComparableUnsafe for Vec { + type EqualResult = bool; + + unsafe fn equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_equal(a, b)) } + } + + unsafe fn is_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> 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))) + let (a, b) = (a.as_const_ptr(), b.as_const_ptr()); + let len = (*a).len(); + if len != (*b).len() { + return false; + } + let (a, b) = ((*a).as_ptr(), (*b).as_ptr()); + (0..len).all(|i| { + let (x, y) = ( + LvalueRefUnsafe::bind(a.add(i)), + LvalueRefUnsafe::bind(b.add(i)), + ); + T::is_equal(x, y) + }) } } } -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 Vec { + type NotEqualResult = bool; + + unsafe fn not_equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_not_equal(a, b)) } + } + + unsafe fn is_not_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { !Self::is_equal(a, b) } + } +} + +impl Cpp17EqualityComparableUnsafe for [T; N] { + type EqualResult = bool; + + unsafe fn equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_equal(a, b)) } + } + + unsafe fn is_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool { + let (a, b) = (a.as_const_ptr().cast::(), b.as_const_ptr().cast::()); + (0..N).all(|i| unsafe { + let (x, y) = ( + LvalueRefUnsafe::bind(a.add(i)), + LvalueRefUnsafe::bind(b.add(i)), + ); + T::is_equal(x, y) + }) } } -impl WeaklyEqualityComparableWithUnsafe - for (A, B) +impl WeaklyEqualityComparableWithUnsafe + for [T; N] { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + type NotEqualResult = bool; + + unsafe fn not_equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_not_equal(a, b)) } + } + + unsafe fn is_not_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { !Self::is_equal(a, b) } + } +} + +impl + Cpp17EqualityComparableUnsafe for (A, B) +{ + type EqualResult = bool; + + unsafe fn equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_equal(a, b)) } + } + + unsafe fn is_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool { unsafe { - A::equal(&raw const (*this).0, &raw const (*rhs).0) - && B::equal(&raw const (*this).1, &raw const (*rhs).1) + let (a, b) = (a.as_const_ptr(), b.as_const_ptr()); + let (x, y) = ( + LvalueRefUnsafe::bind(&raw const (*a).0), + LvalueRefUnsafe::bind(&raw const (*b).0), + ); + if !A::is_equal(x, y) { + return false; + } + let (x, y) = ( + LvalueRefUnsafe::bind(&raw const (*a).1), + LvalueRefUnsafe::bind(&raw const (*b).1), + ); + B::is_equal(x, y) } } } -pub trait PartiallyOrderedWith = Self>: Sized { - fn less(this: Ptr, rhs: Ptr) -> bool; - fn greater(this: Ptr, rhs: Ptr) -> bool; - fn less_equal(this: Ptr, rhs: Ptr) -> bool; - fn greater_equal(this: Ptr, rhs: Ptr) -> bool; +impl + WeaklyEqualityComparableWithUnsafe for (A, B) +{ + type NotEqualResult = bool; + + unsafe fn not_equal( + __return: *mut bool, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_not_equal(a, b)) } + } + + unsafe fn is_not_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { !Self::is_equal(a, b) } + } +} + +pub trait PartiallyOrderedWith = Self>: + LessThanComparable + ByteRepr + Sized +{ + type GreaterResult: BooleanTestable; + type LessEqualResult: BooleanTestable; + type GreaterEqualResult: BooleanTestable; + + fn greater( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ); + fn is_greater(a: LvalueRef>, b: LvalueRef>) -> bool; + fn less_equal( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ); + fn is_less_equal(a: LvalueRef>, b: LvalueRef>) -> bool; + fn greater_equal( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ); + fn is_greater_equal(a: LvalueRef>, b: LvalueRef>) -> bool; } -pub trait PartiallyOrderedWithUnsafe = Self>: Sized { +pub trait PartiallyOrderedWithUnsafe = Self>: + LessThanComparableUnsafe + Sized +{ + type GreaterResult: BooleanTestableUnsafe; + type LessEqualResult: BooleanTestableUnsafe; + type GreaterEqualResult: BooleanTestableUnsafe; + + /// # Safety + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn greater( + __return: *mut Self::GreaterResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn less(this: *const Self, rhs: *const U) -> bool; + /// `a` and `b` must refer to live values. + unsafe fn is_greater(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool; /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn greater(this: *const Self, rhs: *const U) -> bool; + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn less_equal( + __return: *mut Self::LessEqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn less_equal(this: *const Self, rhs: *const U) -> bool; + /// `a` and `b` must refer to live values. + unsafe fn is_less_equal(a: LvalueRefUnsafe>, b: LvalueRefUnsafe>) -> bool; /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn greater_equal(this: *const Self, rhs: *const U) -> bool; + /// `__return` must point to writable storage for the result, and `a` and `b` must refer to + /// live values. + unsafe fn greater_equal( + __return: *mut Self::GreaterEqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ); + /// # Safety + /// `a` and `b` must refer to live values. + unsafe fn is_greater_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool; } pub trait TotallyOrdered: EqualityComparable + PartiallyOrderedWith {} @@ -379,17 +893,53 @@ macro_rules! impl_partially_ordered_with { where $ty: PartialOrd + $crate::ByteRepr, { - fn less(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a < b)) + type GreaterResult = bool; + type LessEqualResult = bool; + type GreaterEqualResult = bool; + + fn greater( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_greater(a, b)); + } + + fn is_greater( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().with(|b| a > b)) } - fn greater(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a > b)) + + fn less_equal( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_less_equal(a, b)); + } + + fn is_less_equal( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().with(|b| a <= b)) } - fn less_equal(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a <= b)) + + fn greater_equal( + __return: $crate::Ptr, + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) { + __return.write(::is_greater_equal(a, b)); } - fn greater_equal(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a >= b)) + + fn is_greater_equal( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> bool { + a.as_pointer().with(|a| b.as_pointer().with(|b| a >= b)) } } )*}; @@ -401,17 +951,63 @@ macro_rules! impl_partially_ordered_with_unsafe { where $ty: PartialOrd, { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this < *rhs } + type GreaterResult = bool; + type LessEqualResult = bool; + type GreaterEqualResult = bool; + + unsafe fn greater( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write(::is_greater(a, b)); + } } - unsafe fn greater(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this > *rhs } + + unsafe fn is_greater( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() > *b.as_const_ptr() } + } + + unsafe fn less_equal( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write( + ::is_less_equal(a, b), + ); + } + } + + unsafe fn is_less_equal( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() <= *b.as_const_ptr() } } - unsafe fn less_equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this <= *rhs } + + unsafe fn greater_equal( + __return: *mut bool, + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) { + unsafe { + __return.write( + ::is_greater_equal(a, b), + ); + } } - unsafe fn greater_equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this >= *rhs } + + unsafe fn is_greater_equal( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> bool { + unsafe { *a.as_const_ptr() >= *b.as_const_ptr() } } } )*}; @@ -432,7 +1028,7 @@ impl_partially_ordered_with_unsafe!( pub trait ThreeWayComparable: EqualityComparable + PartiallyOrderedWith { type Category: Into; - fn three_way(this: Ptr, rhs: Ptr) -> Self::Category; + fn three_way(a: LvalueRef>, b: LvalueRef>) -> Self::Category; } pub trait ThreeWayComparableUnsafe: @@ -441,8 +1037,11 @@ pub trait ThreeWayComparableUnsafe: type Category: Into; /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn three_way(this: *const Self, rhs: *const Self) -> Self::Category; + /// `a` and `b` must refer to live values. + unsafe fn three_way( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> Self::Category; } pub trait ThreeWayComparableWith< @@ -454,7 +1053,7 @@ pub trait ThreeWayComparableWith< { type CategoryWith: Into; - fn three_way_with(this: Ptr, rhs: Ptr) -> Self::CategoryWith; + fn three_way_with(a: LvalueRef>, b: LvalueRef>) -> Self::CategoryWith; } pub trait ThreeWayComparableWithUnsafe< @@ -468,23 +1067,29 @@ pub trait ThreeWayComparableWithUnsafe< type CategoryWith: Into; /// # Safety - /// `this` and `rhs` must point to live values. - unsafe fn three_way_with(this: *const Self, rhs: *const U) -> Self::CategoryWith; + /// `a` and `b` must refer to live values. + unsafe fn three_way_with( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> Self::CategoryWith; } impl ThreeWayComparableWith for T { type CategoryWith = T::Category; - fn three_way_with(this: Ptr, rhs: Ptr) -> Self::CategoryWith { - T::three_way(this, rhs) + fn three_way_with(a: LvalueRef>, b: LvalueRef>) -> Self::CategoryWith { + T::three_way(a, b) } } impl ThreeWayComparableWithUnsafe for T { type CategoryWith = T::Category; - unsafe fn three_way_with(this: *const Self, rhs: *const Self) -> Self::CategoryWith { - unsafe { T::three_way(this, rhs) } + unsafe fn three_way_with( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> Self::CategoryWith { + unsafe { T::three_way(a, b) } } } @@ -499,8 +1104,12 @@ macro_rules! impl_three_way_comparable { { type Category = $crate::$category; - fn three_way(this: $crate::Ptr, rhs: $crate::Ptr) -> Self::Category { - this.with(|a| rhs.with(|b| $crate::$category::from($order::$compare(a, b)))) + fn three_way( + a: $crate::LvalueRef<$crate::Const>, + b: $crate::LvalueRef<$crate::Const>, + ) -> Self::Category { + let (a, b) = (a.as_pointer(), b.as_pointer()); + a.with(|a| b.with(|b| $crate::$category::from($order::$compare(a, b)))) } } )*}; @@ -514,8 +1123,12 @@ macro_rules! impl_three_way_comparable_unsafe { { type Category = $crate::$category; - unsafe fn three_way(this: *const Self, rhs: *const Self) -> Self::Category { - unsafe { $crate::$category::from($order::$compare(&*this, &*rhs)) } + unsafe fn three_way( + a: $crate::LvalueRefUnsafe<$crate::Const>, + b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> Self::Category { + let (a, b) = (a.as_const_ptr(), b.as_const_ptr()); + unsafe { $crate::$category::from($order::$compare(&*a, &*b)) } } } )*}; @@ -541,11 +1154,126 @@ impl_three_way_comparable_unsafe!(PartialOrdering, PartialOrd::partial_cmp, <> f // The order of two values that std::sort and std::map derive from operator<. pub fn cpp_cmp(lhs: &Ptr, rhs: &Ptr) -> Ordering { - if T::less(lhs.clone(), rhs.clone()) { - Ordering::Less - } else if T::less(rhs.clone(), lhs.clone()) { + let (x, y) = (LvalueRef::bind(lhs.clone()), LvalueRef::bind(rhs.clone())); + if T::is_less(x, y) { + return Ordering::Less; + } + let (x, y) = (LvalueRef::bind(rhs.clone()), LvalueRef::bind(lhs.clone())); + if T::is_less(x, y) { Ordering::Greater } else { Ordering::Equal } } + +#[macro_export] +macro_rules! comparison { + ($trait:path, $method:ident, $test:ident, $result:ident = bool, $rhs:ty, + |$a:ident, $b:ident| $body:block) => { + type $result = bool; + fn $method( + __return: $crate::Ptr, + $a: $crate::LvalueRef<$crate::Const>, + $b: $crate::LvalueRef<$crate::Const<$rhs>>, + ) { + __return.write(::$test($a, $b)); + } + fn $test( + $a: $crate::LvalueRef<$crate::Const>, + $b: $crate::LvalueRef<$crate::Const<$rhs>>, + ) -> bool { + let $a = $a.as_pointer(); + let $b = $b.as_pointer(); + $body + } + }; + ($trait:path, $method:ident, $test:ident, $result:ident = $ty:ty, $rhs:ty, + |$slot:ident, $a:ident, $b:ident| $slot_body:block, + |$c:ident, $d:ident| $test_body:block) => { + type $result = $ty; + fn $method( + $slot: $crate::Ptr<$ty>, + $a: $crate::LvalueRef<$crate::Const>, + $b: $crate::LvalueRef<$crate::Const<$rhs>>, + ) { + let $a = $a.as_pointer(); + let $b = $b.as_pointer(); + $slot_body + } + fn $test( + $c: $crate::LvalueRef<$crate::Const>, + $d: $crate::LvalueRef<$crate::Const<$rhs>>, + ) -> bool { + let $c = $c.as_pointer(); + let $d = $d.as_pointer(); + $test_body + } + }; + ($trait:path, $method:ident, $result:ident = $ty:ty, |$a:ident, $b:ident| $body:block) => { + type $result = $ty; + fn $method( + $a: $crate::LvalueRef<$crate::Const>, + $b: $crate::LvalueRef<$crate::Const>, + ) -> $ty { + let $a = $a.as_pointer(); + let $b = $b.as_pointer(); + $body + } + }; +} + +#[macro_export] +macro_rules! comparison_unsafe { + ($trait:path, $method:ident, $test:ident, $result:ident = bool, $rhs:ty, + |$a:ident, $b:ident| $body:block) => { + type $result = bool; + unsafe fn $method( + __return: *mut bool, + $a: $crate::LvalueRefUnsafe<$crate::Const>, + $b: $crate::LvalueRefUnsafe<$crate::Const<$rhs>>, + ) { + unsafe { __return.write(::$test($a, $b)) } + } + unsafe fn $test( + $a: $crate::LvalueRefUnsafe<$crate::Const>, + $b: $crate::LvalueRefUnsafe<$crate::Const<$rhs>>, + ) -> bool { + let $a = $a.as_ptr() as *const Self; + let $b = $b.as_ptr() as *const $rhs; + $body + } + }; + ($trait:path, $method:ident, $test:ident, $result:ident = $ty:ty, $rhs:ty, + |$slot:ident, $a:ident, $b:ident| $slot_body:block, + |$c:ident, $d:ident| $test_body:block) => { + type $result = $ty; + unsafe fn $method( + $slot: *mut $ty, + $a: $crate::LvalueRefUnsafe<$crate::Const>, + $b: $crate::LvalueRefUnsafe<$crate::Const<$rhs>>, + ) { + let $a = $a.as_ptr() as *const Self; + let $b = $b.as_ptr() as *const $rhs; + $slot_body + } + unsafe fn $test( + $c: $crate::LvalueRefUnsafe<$crate::Const>, + $d: $crate::LvalueRefUnsafe<$crate::Const<$rhs>>, + ) -> bool { + let $c = $c.as_ptr() as *const Self; + let $d = $d.as_ptr() as *const $rhs; + $test_body + } + }; + ($trait:path, $method:ident, $result:ident = $ty:ty, |$a:ident, $b:ident| $body:block) => { + type $result = $ty; + unsafe fn $method( + $a: $crate::LvalueRefUnsafe<$crate::Const>, + $b: $crate::LvalueRefUnsafe<$crate::Const>, + ) -> $ty { + let $a = $a.as_ptr() as *const Self; + let $b = $b.as_ptr() as *const Self; + $body + } + }; +} diff --git a/libcc2rs/src/fn_ptr.rs b/libcc2rs/src/fn_ptr.rs index c149582224..c9161e1772 100644 --- a/libcc2rs/src/fn_ptr.rs +++ b/libcc2rs/src/fn_ptr.rs @@ -493,15 +493,89 @@ impl PartialEq for FnPtr { impl Eq for FnPtr {} +impl crate::Cpp17EqualityComparable for FnPtr { + type EqualResult = bool; + + fn equal( + __return: crate::Ptr, + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) { + __return.write(::is_equal(a, b)); + } + + fn is_equal( + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) -> bool { + a.as_pointer() + .with(|a| b.as_pointer().with(|b| a.addr == b.addr)) + } +} + impl crate::WeaklyEqualityComparableWith for FnPtr { - fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| a.addr == b.addr)) + type NotEqualResult = bool; + + fn not_equal( + __return: crate::Ptr, + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) { + __return.write(::is_not_equal( + a, b, + )); + } + + fn is_not_equal( + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) -> bool { + a.as_pointer() + .with(|a| b.as_pointer().with(|b| a.addr != b.addr)) + } +} + +impl crate::Cpp17EqualityComparableUnsafe for FnPtr { + type EqualResult = bool; + + unsafe fn equal( + __return: *mut bool, + a: crate::LvalueRefUnsafe>, + b: crate::LvalueRefUnsafe>, + ) { + unsafe { + __return.write(::is_equal( + a, b, + )) + } + } + + unsafe fn is_equal( + a: crate::LvalueRefUnsafe>, + b: crate::LvalueRefUnsafe>, + ) -> bool { + unsafe { (*a.as_const_ptr()).addr == (*b.as_const_ptr()).addr } } } impl crate::WeaklyEqualityComparableWithUnsafe for FnPtr { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { (*this).addr == (*rhs).addr } + type NotEqualResult = bool; + + unsafe fn not_equal( + __return: *mut bool, + a: crate::LvalueRefUnsafe>, + b: crate::LvalueRefUnsafe>, + ) { + unsafe { + __return.write(::is_not_equal(a, b)) + } + } + + unsafe fn is_not_equal( + a: crate::LvalueRefUnsafe>, + b: crate::LvalueRefUnsafe>, + ) -> bool { + unsafe { (*a.as_const_ptr()).addr != (*b.as_const_ptr()).addr } } } diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index 171a021a11..3531679c1b 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -141,9 +141,9 @@ pub use libcc2rs_macros::{ CopyConstructible, CopyConstructibleUnsafe, Copyable, CopyableUnsafe, DefaultConstructible, DefaultConstructibleUnsafe, DefaultInitializable, DefaultInitializableUnsafe, Destructible, DestructibleUnsafe, FnPtrArg, Memberwise, MemberwiseUnsafe, Movable, MovableUnsafe, - MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, - PartiallyOrderedWith, PartiallyOrderedWithUnsafe, Record, Swappable, SwappableUnsafe, - TriviallyCopyable, TriviallyCopyableUnsafe, TriviallyDefaultConstructible, - TriviallyDefaultConstructibleUnsafe, VaArg, ZeroInitialization, ZeroInitializationUnsafe, - assign, assign_unsafe, goto, goto_block, lambda, lambda_unsafe, switch, + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Record, + Swappable, SwappableUnsafe, TriviallyCopyable, TriviallyCopyableUnsafe, + TriviallyDefaultConstructible, TriviallyDefaultConstructibleUnsafe, VaArg, ZeroInitialization, + ZeroInitializationUnsafe, assign, assign_unsafe, goto, goto_block, lambda, lambda_unsafe, + switch, }; diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index 64ec858b70..1f182a91e7 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -112,17 +112,28 @@ pub trait ConstructibleFrom: Sized { impl ConstructibleFrom for T { fn construct(this: Ptr, args: Args) { - initialize(&T::table(), this.to_any(), &args.as_args(), true); + initialize(&T::table(), this.to_any(), &args.into_args(), true); } } pub trait ConvertibleTo: Sized { fn convert(self, to: Ptr); + + fn convert_value(self) -> To + where + To: crate::TriviallyCopyable + crate::ZeroInitialization, + { + let to: crate::rc::Value = std::rc::Rc::new(std::cell::RefCell::new( + ::zero_init(), + )); + self.convert(crate::rc::AsPointer::::as_pointer(&to)); + crate::rc::AsPointer::::as_pointer(&to).read() + } } impl ConvertibleTo for From { fn convert(self, to: Ptr) { - initialize(&To::table(), to.to_any(), &[self.as_arg()], false); + initialize(&To::table(), to.to_any(), &[self.into_arg()], false); } } @@ -134,7 +145,7 @@ pub trait ConstructibleFromUnsafe: Sized { impl ConstructibleFromUnsafe for T { unsafe fn construct(this: *mut T, args: Args) { - initialize(&T::table(), this.cast(), &args.as_args(), true); + initialize(&T::table(), this.cast(), &args.into_args(), true); } } @@ -142,54 +153,89 @@ pub trait ConvertibleToUnsafe: Sized { /// # Safety /// `to` is storage for an object, and `self` refers to a live object. unsafe fn convert(self, to: *mut To); + + /// # Safety + /// `self` refers to a live object. + unsafe fn convert_value(self) -> To + where + To: crate::TriviallyCopyableUnsafe + crate::ZeroInitializationUnsafe, + { + unsafe { + let mut to = ::zero_init(); + self.convert(&raw mut to); + to + } + } } impl ConvertibleToUnsafe for From { unsafe fn convert(self, to: *mut To) { - initialize(&To::table(), to.cast(), &[self.as_arg()], false); + initialize(&To::table(), to.cast(), &[self.into_arg()], false); } } pub trait AsArg { - fn as_arg(&self) -> Arg; + fn into_arg(self) -> Arg; +} + +impl AsArg for T { + fn into_arg(self) -> Arg { + let object: crate::rc::Value = std::rc::Rc::new(std::cell::RefCell::new(self)); + let ptr = crate::rc::AsPointer::::as_pointer(&object); + Arg { + owner: Some(Box::new(object)), + ..Arg::rvalue(ptr) + } + } } impl AsArg for LvalueRef { - fn as_arg(&self) -> Arg { + fn into_arg(self) -> Arg { Arg::lvalue(self.as_pointer()) } } impl AsArg for LvalueRef> { - fn as_arg(&self) -> Arg { + fn into_arg(self) -> Arg { Arg::const_lvalue(self.as_pointer()) } } impl AsArg for RvalueRef { - fn as_arg(&self) -> Arg { + fn into_arg(self) -> Arg { Arg::rvalue(self.as_pointer()) } } pub trait AsArgUnsafe { - fn as_arg(&self) -> Arg<*mut c_void>; + fn into_arg(self) -> Arg<*mut c_void>; +} + +impl AsArgUnsafe for T { + fn into_arg(self) -> Arg<*mut c_void> { + let mut object = Box::new(self); + let ptr: *mut T = &raw mut *object; + Arg { + owner: Some(object), + ..Arg::rvalue_unsafe(ptr) + } + } } impl AsArgUnsafe for LvalueRefUnsafe { - fn as_arg(&self) -> Arg<*mut c_void> { + fn into_arg(self) -> Arg<*mut c_void> { Arg::lvalue_unsafe(self.as_ptr()) } } impl AsArgUnsafe for LvalueRefUnsafe> { - fn as_arg(&self) -> Arg<*mut c_void> { + fn into_arg(self) -> Arg<*mut c_void> { Arg::const_lvalue_unsafe(self.as_const_ptr()) } } impl AsArgUnsafe for RvalueRefUnsafe { - fn as_arg(&self) -> Arg<*mut c_void> { + fn into_arg(self) -> Arg<*mut c_void> { Arg::rvalue_unsafe(self.as_ptr()) } } @@ -435,28 +481,28 @@ impl ParameterUnsafe for RvalueRefUnsafe> { } pub trait ArgList { - fn as_args(&self) -> Vec>; + fn into_args(self) -> Vec>; } pub trait ArgListUnsafe { - fn as_args(&self) -> Vec>; + fn into_args(self) -> Vec>; } macro_rules! arg_list { ($($name:ident),*) => { impl<$($name: AsArg),*> ArgList for ($($name,)*) { #[allow(non_snake_case, clippy::vec_init_then_push)] - fn as_args(&self) -> Vec> { + fn into_args(self) -> Vec> { let ($($name,)*) = self; - vec![$($name.as_arg()),*] + vec![$($name.into_arg()),*] } } impl<$($name: AsArgUnsafe),*> ArgListUnsafe for ($($name,)*) { #[allow(non_snake_case, clippy::vec_init_then_push)] - fn as_args(&self) -> Vec> { + fn into_args(self) -> Vec> { let ($($name,)*) = self; - vec![$($name.as_arg()),*] + vec![$($name.into_arg()),*] } } }; @@ -474,6 +520,7 @@ pub struct Arg

{ pub table: fn() -> Table

, pub category: Category, pub ptr: P, + pub owner: Option>, } impl Arg<*mut c_void> { @@ -494,6 +541,7 @@ impl Arg<*mut c_void> { table: T::table, category, ptr: ptr.cast(), + owner: None, } } } @@ -516,6 +564,7 @@ impl Arg { table: T::table, category, ptr: ptr.to_any(), + owner: None, } } } diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 182e238984..ac5e3d2f5f 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -121,14 +121,55 @@ macro_rules! reference { } } + impl crate::Cpp17EqualityComparable for $name + where + T::Object: crate::Cpp17EqualityComparable + ByteRepr, + { + type EqualResult = ::EqualResult; + + fn equal( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ) { + ::equal( + __return, + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), + ); + } + + fn is_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + ::is_equal( + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), + ) + } + } + impl crate::WeaklyEqualityComparableWith for $name where T::Object: crate::WeaklyEqualityComparableWith + ByteRepr, { - fn equal(this: Ptr, rhs: Ptr) -> bool { - ::equal( - this.with(|r| r.0.clone()), - rhs.with(|r| r.0.clone()), + type NotEqualResult = + ::NotEqualResult; + + fn not_equal( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ) { + ::not_equal( + __return, + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), + ); + } + + fn is_not_equal(a: LvalueRef>, b: LvalueRef>) -> bool { + ::is_not_equal( + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), ) } } @@ -137,10 +178,24 @@ macro_rules! reference { where T::Object: crate::LessThanComparable + ByteRepr, { - fn less(this: Ptr, rhs: Ptr) -> bool { + type Result = ::Result; + + fn less( + __return: Ptr, + a: LvalueRef>, + b: LvalueRef>, + ) { ::less( - this.with(|r| r.0.clone()), - rhs.with(|r| r.0.clone()), + __return, + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), + ); + } + + fn is_less(a: LvalueRef>, b: LvalueRef>) -> bool { + ::is_less( + LvalueRef::bind(a.as_pointer().with(|r| r.0.clone())), + LvalueRef::bind(b.as_pointer().with(|r| r.0.clone())), ) } } @@ -268,33 +323,193 @@ macro_rules! reference_unsafe { } } + impl crate::Cpp17EqualityComparableUnsafe + for $name + { + type EqualResult = T::EqualResult; + + unsafe fn equal( + __return: *mut Self::EqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::equal( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_equal( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + } + impl crate::WeaklyEqualityComparableWithUnsafe for $name { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { T::equal((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + type NotEqualResult = T::NotEqualResult; + + unsafe fn not_equal( + __return: *mut Self::NotEqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::not_equal( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_not_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_not_equal( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + } + + impl crate::Cpp17EqualityComparableUnsafe + for $name> + { + type EqualResult = T::EqualResult; + + unsafe fn equal( + __return: *mut Self::EqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::equal( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_equal( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } } } impl crate::WeaklyEqualityComparableWithUnsafe for $name> { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { T::equal((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + type NotEqualResult = T::NotEqualResult; + + unsafe fn not_equal( + __return: *mut Self::NotEqualResult, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::not_equal( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_not_equal( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_not_equal( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } } } impl crate::LessThanComparableUnsafe for $name { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - unsafe { T::less((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + type Result = T::Result; + + unsafe fn less( + __return: *mut Self::Result, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::less( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_less( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_less( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } } } impl crate::LessThanComparableUnsafe for $name> { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { - unsafe { T::less((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + type Result = T::Result; + + unsafe fn less( + __return: *mut Self::Result, + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) { + unsafe { + T::less( + __return, + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } + } + + unsafe fn is_less( + a: LvalueRefUnsafe>, + b: LvalueRefUnsafe>, + ) -> bool { + unsafe { + T::is_less( + LvalueRefUnsafe::bind((*a.as_const_ptr()).as_ptr().cast::()), + LvalueRefUnsafe::bind((*b.as_const_ptr()).as_ptr().cast::()), + ) + } } } }; diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index e5dba00b77..6ccae5b82a 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -148,9 +148,43 @@ impl PartialEq for AnyPtr { } } +impl crate::Cpp17EqualityComparable for AnyPtr { + type EqualResult = bool; + + fn equal( + __return: crate::Ptr, + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) { + __return.write(Self::is_equal(a, b)); + } + + fn is_equal( + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) -> bool { + a.as_pointer() + .with(|a| b.as_pointer().with(|b| *a.ptr == *b.ptr)) + } +} + impl crate::WeaklyEqualityComparableWith for AnyPtr { - fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { - this.with(|a| rhs.with(|b| *a.ptr == *b.ptr)) + type NotEqualResult = bool; + + fn not_equal( + __return: crate::Ptr, + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) { + __return.write(Self::is_not_equal(a, b)); + } + + fn is_not_equal( + a: crate::LvalueRef>, + b: crate::LvalueRef>, + ) -> bool { + a.as_pointer() + .with(|a| b.as_pointer().with(|b| *a.ptr != *b.ptr)) } } diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index a3bd5599ab..86272020bd 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -385,6 +385,13 @@ impl<'a> FragmentCtx<'a> { return None; } let segment = path.segment()?; + if segment + .syntax() + .descendants_with_tokens() + .any(|element| element.kind() == SyntaxKind::AS_KW) + { + return None; + } let name = match segment.name_ref() { Some(name_ref) => name_ref.text().to_string(), None => segment diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index f5fde68c92..ec06e69d34 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -9,6 +9,7 @@ use std::rc::Rc; fn f1, T2: LessThanComparable + Clone + ByteRepr>(a0: T1, a1: T1) { let __n = a1.iter_distance(&a0); let mut __order: Vec = (0..__n).collect(); + // TODO: C++ sort calls operator< once per comparison; this calls it twice. __order.sort_by(|&__x, &__y| cpp_cmp(&a0.iter_at(__x), &a0.iter_at(__y))); reorder(__order, |__i| a0.iter_at(__i)); } @@ -29,8 +30,10 @@ where let __first: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while ::not_equal(__first.as_pointer(), __last.as_pointer()) - { + while ::is_not_equal( + LvalueRef::>::bind(__first.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { object!(__value, T4, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this @@ -45,20 +48,20 @@ where __out } -fn f3< - T1: CppInputIterator, - T2: WeaklyEqualityComparableWith, - T3: WeaklyEqualityComparableWith, ->( +fn f3, T2: ByteRepr, T3: Cpp17EqualityComparable>( 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()) - { + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(a2.clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -88,13 +91,19 @@ fn f8, T2: LessThanComparable>(a0: T1, a1: T1) -> T1 { 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()) { + if ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { __it.borrow_mut().iter_inc(); - while ::not_equal( - __it.as_pointer(), - __last.as_pointer(), + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), ) { - if LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { + if ::is_less( + LvalueRef::>::bind(__best.iter_deref()), + LvalueRef::>::bind(__it.borrow().iter_deref()), + ) { __best = __it.borrow().clone(); } __it.borrow_mut().iter_inc(); @@ -107,27 +116,27 @@ fn f9(a0: Ptr, a1: Ptr) { Swappable::swap(a0, a1) } -fn f10< - T1: CppInputIterator, - T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr, ->( +fn f10, T2: Cpp17EqualityComparable + TriviallyCopyable + ByteRepr>( a0: T1, a1: T1, ) -> T1 { let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); - if ::equal(__it.as_pointer(), __last.as_pointer()) { + if ::is_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { __last.borrow().clone() } else { let mut __write = __it.borrow().clone(); __it.borrow_mut().iter_inc(); - while ::not_equal( - __it.as_pointer(), - __last.as_pointer(), + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), ) { - if !WeaklyEqualityComparableWith::equal( - __write.iter_deref(), - __it.borrow().iter_deref(), + if !::is_equal( + LvalueRef::>::bind(__write.iter_deref()), + LvalueRef::>::bind(__it.borrow().iter_deref()), ) { __write.iter_inc(); __write @@ -144,7 +153,10 @@ fn f10< fn f12, T2: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) { 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()) { + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { __it.borrow().iter_deref().write(Clone::clone(&a2)); __it.borrow_mut().iter_inc(); } @@ -155,7 +167,10 @@ fn f13>(a0: T1, a1: T1, a2: &mut ::std::fs::File) -> :: let __last: Value = Rc::new(RefCell::new(a1)); let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { __bytes.push(__it.borrow().iter_deref().read() as u8); __it.borrow_mut().iter_inc(); } @@ -184,7 +199,10 @@ where } fn f16(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a1.clone(), a0.clone()) { + if ::is_less( + LvalueRef::>::bind(a1.clone()), + LvalueRef::>::bind(a0.clone()), + ) { a1 } else { a0 @@ -192,7 +210,10 @@ fn f16(a0: Ptr, a1: Ptr) -> Ptr { } fn f17(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a0.clone(), a1.clone()) { + if ::is_less( + LvalueRef::>::bind(a0.clone()), + LvalueRef::>::bind(a1.clone()), + ) { a1 } else { a0 diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 9eee9d415a..ccd60599a9 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -7,12 +7,19 @@ use std::io::{Seek, Write}; unsafe fn f1, T2: LessThanComparableUnsafe>(a0: T1, a1: T1) { let __n = a1.iter_distance(&a0); let mut __order: Vec = (0..__n).collect(); + // TODO: C++ sort calls operator< once per comparison; this calls it twice. __order.sort_by(|&__x, &__y| { - let __a = a0.iter_at(__x) as *const _; - let __b = a0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = a0.iter_at(__x) as *const T2; + let __b = a0.iter_at(__y) as *const T2; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -42,7 +49,10 @@ where { let mut __first = a0; let mut __out = a2; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&a1), + ) { object_unsafe!(__value, T4, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this @@ -57,19 +67,19 @@ where __out } -unsafe fn f3< - T1: UnsafeCppInputIterator, - T2: WeaklyEqualityComparableWithUnsafe, - T3: WeaklyEqualityComparableWithUnsafe, ->( +unsafe fn f3, T2, T3: Cpp17EqualityComparableUnsafe>( a0: T1, a1: T1, a2: T2, ) -> T1 { let mut __it = a0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) - { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) && !>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&a2), + ) { __it.iter_inc(); } __it @@ -103,13 +113,19 @@ where unsafe fn f8, T2: LessThanComparableUnsafe>(a0: T1, a1: T1) -> T1 { let mut __best = a0.clone(); - if WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) { + if ::is_not_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) { let mut __it = a0; __it.iter_inc(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if LessThanComparableUnsafe::less( - __best.iter_deref() as *const _, - __it.iter_deref() as *const _, + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) { + if ::is_less( + LvalueRefUnsafe::>::bind(__best.iter_deref()), + LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __best = __it.clone(); } @@ -125,22 +141,27 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { SwappableUnsafe::swap(&mut *__a, __b) } -unsafe fn f10< - T1: UnsafeCppInputIterator, - T2: WeaklyEqualityComparableWithUnsafe + Clone, ->( +unsafe fn f10, T2: Cpp17EqualityComparableUnsafe + Clone>( a0: T1, a1: T1, ) -> T1 { - if WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { + if ::is_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) { a1 } else { let mut __write = a0.clone(); let mut __it = a0; __it.iter_inc(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) - { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) { + if !::is_equal( + LvalueRefUnsafe::>::bind(__write.iter_deref()), + LvalueRefUnsafe::>::bind(__it.iter_deref()), + ) { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); } @@ -153,7 +174,10 @@ unsafe fn f10< unsafe fn f12, T2: Clone>(a0: T1, a1: T1, a2: T2) { let mut __it = a0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) { *__it.iter_deref() = Clone::clone(&a2); __it.iter_inc(); } @@ -167,7 +191,10 @@ unsafe fn f13>( let mut __it = a0; let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } @@ -194,7 +221,10 @@ where unsafe fn f16(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -204,7 +234,10 @@ unsafe fn f16(a0: *const T1, a1: *const T1) -> *co unsafe fn f17(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 4f15125eb3..0af1db9488 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, EqualityComparable, EqualityComparableUnsafe, MapNode, PartiallyOrderedWith, + ByteRepr, Const, EqualityComparable, EqualityComparableUnsafe, LessThanComparable, + LessThanComparableUnsafe, LvalueRef, LvalueRefUnsafe, MapNode, PartiallyOrderedWith, PartiallyOrderedWithUnsafe, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, TotallyOrdered, TotallyOrderedUnsafe, UnsafeMapNode, Value, }; @@ -173,15 +174,79 @@ macro_rules! uninhabited_iterator { impl ByteRepr for $name {} + impl crate::Cpp17EqualityComparable for $name { + type EqualResult = bool; + fn equal( + __return: Ptr, + this: LvalueRef>, + rhs: LvalueRef>, + ) { + __return.write(::is_equal( + this, rhs, + )); + } + fn is_equal(this: LvalueRef>, _: LvalueRef>) -> bool { + this.as_pointer().with(|it| it.never()) + } + } + impl crate::WeaklyEqualityComparableWith for $name { - fn equal(this: Ptr, _: Ptr) -> bool { - this.with(|it| it.never()) + type NotEqualResult = bool; + fn not_equal( + __return: Ptr, + this: LvalueRef>, + rhs: LvalueRef>, + ) { + __return.write(::is_not_equal( + this, rhs, + )); + } + fn is_not_equal(this: LvalueRef>, _: LvalueRef>) -> bool { + this.as_pointer().with(|it| it.never()) + } + } + + impl crate::Cpp17EqualityComparableUnsafe for $name { + type EqualResult = bool; + unsafe fn equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { + __return.write(::is_equal( + this, rhs, + )) + } + } + unsafe fn is_equal( + this: LvalueRefUnsafe>, + _: LvalueRefUnsafe>, + ) -> bool { + unsafe { (*this.as_const_ptr()).never() } } } impl crate::WeaklyEqualityComparableWithUnsafe for $name { - unsafe fn equal(this: *const Self, _: *const Self) -> bool { - unsafe { (*this).never() } + type NotEqualResult = bool; + unsafe fn not_equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { + __return.write( + ::is_not_equal( + this, rhs, + ), + ) + } + } + unsafe fn is_not_equal( + this: LvalueRefUnsafe>, + _: LvalueRefUnsafe>, + ) -> bool { + unsafe { (*this.as_const_ptr()).never() } } } @@ -191,8 +256,8 @@ macro_rules! uninhabited_iterator { } } - impl crate::Constructor<(crate::LvalueRef>,)> for $name { - fn constructor(_: Ptr, (src,): (crate::LvalueRef>,)) { + impl crate::Constructor<(LvalueRef>,)> for $name { + fn constructor(_: Ptr, (src,): (LvalueRef>,)) { src.as_pointer().with(|it| it.never()) } } @@ -203,13 +268,8 @@ macro_rules! uninhabited_iterator { } } - impl crate::ConstructorUnsafe<(crate::LvalueRefUnsafe>,)> - for $name - { - unsafe fn constructor( - _: *mut Self, - (src,): (crate::LvalueRefUnsafe>,), - ) { + impl crate::ConstructorUnsafe<(LvalueRefUnsafe>,)> for $name { + unsafe fn constructor(_: *mut Self, (src,): (LvalueRefUnsafe>,)) { unsafe { (*src.as_const_ptr()).never() } } } @@ -285,16 +345,34 @@ impl Clone for BidirectionalIterator { impl ByteRepr for BidirectionalIterator {} -impl crate::WeaklyEqualityComparableWith for BidirectionalIterator { - fn equal(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { +impl crate::Cpp17EqualityComparable for BidirectionalIterator { + type EqualResult = bool; + fn equal(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_equal(this, rhs)); + } + fn is_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Map(a), Self::Map(b)) => Rc::ptr_eq(a, b), }) }) } } +impl crate::WeaklyEqualityComparableWith for BidirectionalIterator { + type NotEqualResult = bool; + fn not_equal(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_not_equal(this, rhs)); + } + fn is_not_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { + (Self::Map(a), Self::Map(b)) => !Rc::ptr_eq(a, b), + }) + }) + } +} + impl CppIterator for BidirectionalIterator { fn iter_deref(&self) -> Ptr { match self { @@ -348,16 +426,48 @@ impl Clone for UnsafeBidirectionalIterator { } } -impl crate::WeaklyEqualityComparableWithUnsafe for UnsafeBidirectionalIterator { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { +impl crate::Cpp17EqualityComparableUnsafe for UnsafeBidirectionalIterator { + type EqualResult = bool; + unsafe fn equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_equal(this, rhs)) } + } + unsafe fn is_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Map(a), Self::Map(b)) => a == b, } } } } +impl crate::WeaklyEqualityComparableWithUnsafe for UnsafeBidirectionalIterator { + type NotEqualResult = bool; + unsafe fn not_equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_not_equal(this, rhs)) } + } + unsafe fn is_not_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { + unsafe { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { + (Self::Map(a), Self::Map(b)) => a != b, + } + } + } +} + impl UnsafeCppIterator for UnsafeBidirectionalIterator { fn iter_deref(&self) -> *mut T { match self { @@ -535,82 +645,202 @@ crate::constructor::impl_trivial_copy_move!( UnsafeBidirectionalIterator, UnsafeRandomAccessIterator, ); -impl crate::WeaklyEqualityComparableWith for RandomAccessIterator { - fn equal(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { +impl crate::Cpp17EqualityComparable for RandomAccessIterator { + type EqualResult = bool; + fn equal(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_equal(this, rhs)); + } + fn is_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Vec(a), Self::Vec(b)) => a == b, }) }) } } -impl PartiallyOrderedWith for RandomAccessIterator { - fn less(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { +impl crate::WeaklyEqualityComparableWith for RandomAccessIterator { + type NotEqualResult = bool; + fn not_equal(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_not_equal(this, rhs)); + } + fn is_not_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { + (Self::Vec(a), Self::Vec(b)) => a != b, + }) + }) + } +} + +impl LessThanComparable for RandomAccessIterator { + type Result = bool; + fn less(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_less(this, rhs)); + } + fn is_less(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Vec(a), Self::Vec(b)) => a < b, }) }) } - fn greater(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { +} + +impl PartiallyOrderedWith for RandomAccessIterator { + type GreaterResult = bool; + type LessEqualResult = bool; + type GreaterEqualResult = bool; + fn greater(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_greater(this, rhs)); + } + fn is_greater(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Vec(a), Self::Vec(b)) => a > b, }) }) } - fn less_equal(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { + fn less_equal(__return: Ptr, this: LvalueRef>, rhs: LvalueRef>) { + __return.write(Self::is_less_equal(this, rhs)); + } + fn is_less_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Vec(a), Self::Vec(b)) => a <= b, }) }) } - fn greater_equal(this: Ptr, rhs: Ptr) -> bool { - this.with(|a| { - rhs.with(|b| match (a, b) { + fn greater_equal( + __return: Ptr, + this: LvalueRef>, + rhs: LvalueRef>, + ) { + __return.write(Self::is_greater_equal(this, rhs)); + } + fn is_greater_equal(this: LvalueRef>, rhs: LvalueRef>) -> bool { + this.as_pointer().with(|a| { + rhs.as_pointer().with(|b| match (a, b) { (Self::Vec(a), Self::Vec(b)) => a >= b, }) }) } } -impl crate::WeaklyEqualityComparableWithUnsafe for UnsafeRandomAccessIterator { - unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { +impl crate::Cpp17EqualityComparableUnsafe for UnsafeRandomAccessIterator { + type EqualResult = bool; + unsafe fn equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_equal(this, rhs)) } + } + unsafe fn is_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Vec(a), Self::Vec(b)) => a == b, } } } } -impl PartiallyOrderedWithUnsafe for UnsafeRandomAccessIterator { - unsafe fn less(this: *const Self, rhs: *const Self) -> bool { +impl crate::WeaklyEqualityComparableWithUnsafe for UnsafeRandomAccessIterator { + type NotEqualResult = bool; + unsafe fn not_equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_not_equal(this, rhs)) } + } + unsafe fn is_not_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { + unsafe { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { + (Self::Vec(a), Self::Vec(b)) => a != b, + } + } + } +} + +impl LessThanComparableUnsafe for UnsafeRandomAccessIterator { + type Result = bool; + unsafe fn less( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_less(this, rhs)) } + } + unsafe fn is_less( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Vec(a), Self::Vec(b)) => a < b, } } } - unsafe fn greater(this: *const Self, rhs: *const Self) -> bool { +} + +impl PartiallyOrderedWithUnsafe for UnsafeRandomAccessIterator { + type GreaterResult = bool; + type LessEqualResult = bool; + type GreaterEqualResult = bool; + unsafe fn greater( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_greater(this, rhs)) } + } + unsafe fn is_greater( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Vec(a), Self::Vec(b)) => a > b, } } } - unsafe fn less_equal(this: *const Self, rhs: *const Self) -> bool { + unsafe fn less_equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_less_equal(this, rhs)) } + } + unsafe fn is_less_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Vec(a), Self::Vec(b)) => a <= b, } } } - unsafe fn greater_equal(this: *const Self, rhs: *const Self) -> bool { + unsafe fn greater_equal( + __return: *mut bool, + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) { + unsafe { __return.write(Self::is_greater_equal(this, rhs)) } + } + unsafe fn is_greater_equal( + this: LvalueRefUnsafe>, + rhs: LvalueRefUnsafe>, + ) -> bool { unsafe { - match (&*this, &*rhs) { + match (&*this.as_const_ptr(), &*rhs.as_const_ptr()) { (Self::Vec(a), Self::Vec(b)) => a >= b, } } @@ -635,9 +865,9 @@ macro_rules! iter_step { Rc::new(RefCell::new(self)) } fn iter_not_equal(cur: &Self::Var, end: &Self::Var) -> bool { - ::not_equal( - crate::AsPointer::::as_pointer(cur), - crate::AsPointer::::as_pointer(end), + ::is_not_equal( + LvalueRef::>::bind(crate::AsPointer::::as_pointer(cur)), + LvalueRef::>::bind(crate::AsPointer::::as_pointer(end)), ) } fn iter_next(cur: &mut Self::Var) -> Self { @@ -658,7 +888,12 @@ macro_rules! iter_step_unsafe { self } fn iter_not_equal(cur: &Self::Var, end: &Self::Var) -> bool { - unsafe { ::not_equal(cur, end) } + unsafe { + ::is_not_equal( + LvalueRefUnsafe::>::bind(&raw const *cur), + LvalueRefUnsafe::>::bind(&raw const *end), + ) + } } fn iter_next(cur: &mut Self::Var) -> Self { UnsafeCppIterator::::iter_post_inc(cur) diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index 71e13deeba..6945244326 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -59,11 +59,17 @@ fn f8, T2>(a0: T1) -> Ptr { } fn f9, T2>(a0: Ptr, a1: Ptr) -> bool { - WeaklyEqualityComparableWith::equal(a0, a1) + Cpp17EqualityComparable::is_equal( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f10, T2>(a0: Ptr, a1: Ptr) -> bool { - WeaklyEqualityComparableWith::not_equal(a0, a1) + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -106,19 +112,31 @@ fn f19, T2>(a0: T1, a1: isize) -> Ptr { } fn f20, T2>(a0: Ptr, a1: Ptr) -> bool { - PartiallyOrderedWith::less(a0, a1) + LessThanComparable::is_less( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f21, T2>(a0: Ptr, a1: Ptr) -> bool { - PartiallyOrderedWith::greater(a0, a1) + PartiallyOrderedWith::is_greater( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f22, T2>(a0: Ptr, a1: Ptr) -> bool { - PartiallyOrderedWith::less_equal(a0, a1) + PartiallyOrderedWith::is_less_equal( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f23, T2>(a0: Ptr, a1: Ptr) -> bool { - PartiallyOrderedWith::greater_equal(a0, a1) + PartiallyOrderedWith::is_greater_equal( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } fn f24, T2>(a0: T2) -> T1 { @@ -135,13 +153,12 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27< - T1: CppInputIterator + WeaklyEqualityComparableWith, - T2: CppInputIterator + WeaklyEqualityComparableWith, - T3, ->( +fn f27 + Cpp17EqualityComparable, T2: CppInputIterator, T3>( a0: Ptr, a1: Ptr, ) -> bool { - WeaklyEqualityComparableWith::equal(a0, a1) + Cpp17EqualityComparable::is_equal( + LvalueRef::>::bind(a0), + LvalueRef::>::bind(a1), + ) } diff --git a/rules/iterator_category/tgt_unsafe.rs b/rules/iterator_category/tgt_unsafe.rs index aadacbf262..d36f1aba9e 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -59,11 +59,17 @@ fn f8, T2>(a0: T1) -> *mut T2 { } unsafe fn f9, T2>(a0: T1, a1: T1) -> bool { - WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) + Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } unsafe fn f10, T2>(a0: T1, a1: T1) -> bool { - WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) + WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -106,19 +112,31 @@ fn f19, T2>(a0: T1, a1: isize) -> *mut T2 } unsafe fn f20, T2>(a0: T1, a1: T1) -> bool { - PartiallyOrderedWithUnsafe::less(&a0, &a1) + LessThanComparableUnsafe::is_less( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } unsafe fn f21, T2>(a0: T1, a1: T1) -> bool { - PartiallyOrderedWithUnsafe::greater(&a0, &a1) + PartiallyOrderedWithUnsafe::is_greater( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } unsafe fn f22, T2>(a0: T1, a1: T1) -> bool { - PartiallyOrderedWithUnsafe::less_equal(&a0, &a1) + PartiallyOrderedWithUnsafe::is_less_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } unsafe fn f23, T2>(a0: T1, a1: T1) -> bool { - PartiallyOrderedWithUnsafe::greater_equal(&a0, &a1) + PartiallyOrderedWithUnsafe::is_greater_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } fn f24, T2>(a0: T2) -> T1 { @@ -136,12 +154,15 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { } unsafe fn f27< - T1: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, - T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, + T1: UnsafeCppInputIterator + Cpp17EqualityComparableUnsafe, + T2: UnsafeCppInputIterator, T3, >( a0: T1, a1: T2, ) -> bool { - WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) + Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } diff --git a/rules/map/shim.rs b/rules/map/shim.rs index e77027f1dc..25d1cfbaee 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -407,9 +407,15 @@ struct UnsafeMapKey(*const K); impl Ord for UnsafeMapKey { fn cmp(&self, other: &Self) -> Ordering { unsafe { - if K::less(self.0, other.0) { + if K::is_less( + LvalueRefUnsafe::>::bind(self.0), + LvalueRefUnsafe::>::bind(other.0), + ) { Ordering::Less - } else if K::less(other.0, self.0) { + } else if K::is_less( + LvalueRefUnsafe::>::bind(other.0), + LvalueRefUnsafe::>::bind(self.0), + ) { Ordering::Greater } else { Ordering::Equal diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 1cbd23af3e..8ff7c913d7 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -214,12 +214,17 @@ where a0.get_value::().as_pointer() } -fn f28, T2: WeaklyEqualityComparableWith>( +fn f28, T2: Cpp17EqualityComparable>( 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())) + !(::is_equal( + LvalueRef::>::bind(a0.0.as_pointer()), + LvalueRef::>::bind(a1.0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind(a0.1.as_pointer()), + LvalueRef::>::bind(a1.1.as_pointer()), + )) } fn f34< @@ -248,34 +253,51 @@ fn f29( a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>, ) -> bool { - LessThanComparable::less(a0, a1) + <(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a0), + LvalueRef::, Value)>>::bind(a1), + ) } fn f30( a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>, ) -> bool { - !LessThanComparable::less(a1, a0) + !<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a1), + LvalueRef::, Value)>>::bind(a0), + ) } fn f31( a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>, ) -> bool { - LessThanComparable::less(a1, a0) + <(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a1), + LvalueRef::, Value)>>::bind(a0), + ) } fn f32( a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>, ) -> bool { - !LessThanComparable::less(a0, a1) + !<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a0), + LvalueRef::, Value)>>::bind(a1), + ) } -fn f33, T2: WeaklyEqualityComparableWith>( +fn f33, T2: Cpp17EqualityComparable>( 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()) + ::is_equal( + LvalueRef::>::bind(a0.0.as_pointer()), + LvalueRef::>::bind(a1.0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind(a0.1.as_pointer()), + LvalueRef::>::bind(a1.1.as_pointer()), + ) } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 0a41887c0e..adf634df77 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -203,54 +203,70 @@ where &*a0.get::() } -unsafe fn f28< - T1: WeaklyEqualityComparableWithUnsafe, - T2: WeaklyEqualityComparableWithUnsafe, ->( +unsafe fn f28, T2: Cpp17EqualityComparableUnsafe>( a0: (T1, T2), a1: (T1, T2), ) -> bool { - !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) - && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) + !(::is_equal( + LvalueRefUnsafe::>::bind(&a0.0), + LvalueRefUnsafe::>::bind(&a1.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&a0.1), + LvalueRefUnsafe::>::bind(&a1.1), + )) } unsafe fn f29( a0: (T1, T2), a1: (T1, T2), ) -> bool { - LessThanComparableUnsafe::less(&a0, &a1) + <(T1, T2) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } unsafe fn f30( a0: (T1, T2), a1: (T1, T2), ) -> bool { - !LessThanComparableUnsafe::less(&a1, &a0) + !<(T1, T2) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a1), + LvalueRefUnsafe::>::bind(&a0), + ) } unsafe fn f31( a0: (T1, T2), a1: (T1, T2), ) -> bool { - LessThanComparableUnsafe::less(&a1, &a0) + <(T1, T2) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a1), + LvalueRefUnsafe::>::bind(&a0), + ) } unsafe fn f32( a0: (T1, T2), a1: (T1, T2), ) -> bool { - !LessThanComparableUnsafe::less(&a0, &a1) + !<(T1, T2) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a0), + LvalueRefUnsafe::>::bind(&a1), + ) } -unsafe fn f33< - T1: WeaklyEqualityComparableWithUnsafe, - T2: WeaklyEqualityComparableWithUnsafe, ->( +unsafe fn f33, T2: Cpp17EqualityComparableUnsafe>( a0: (T1, T2), a1: (T1, T2), ) -> bool { - WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) - && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) + ::is_equal( + LvalueRefUnsafe::>::bind(&a0.0), + LvalueRefUnsafe::>::bind(&a1.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&a0.1), + LvalueRefUnsafe::>::bind(&a1.1), + ) } unsafe fn f34< diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index 57fb717d39..3e081cd864 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -110,7 +110,10 @@ fn f92< let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -165,7 +168,10 @@ fn f101< let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while ::is_not_equal( + LvalueRef::>::bind(__it.as_pointer()), + LvalueRef::>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 505f41b0b7..300bc098da 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -168,7 +168,10 @@ unsafe fn f92< ) -> Vec { let mut __v: Vec = Vec::new(); let mut __it = a0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a1), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -218,7 +221,10 @@ unsafe fn f101< let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; let mut __tmp: Vec = Vec::new(); let mut __it = a2; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a3) { + while ::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&a3), + ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), 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 1b1ac0deb3..7763eecc3d 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -27,6 +27,36 @@ pub struct S { #[offset(4)] pub b: i32, } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ne_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -35,39 +65,35 @@ 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!(({ 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!(({ LessThanComparable::less(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ LessThanComparable::less(s3.as_pointer(), s1.as_pointer(),) })); - assert!((({ compare_0(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); - assert!((({ compare_0(s3.as_pointer(), s1.as_pointer(),) }) == 1)); - assert!((({ compare_0(s1.as_pointer(), s2.as_pointer(),) }) == 0)); + 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)); return 0; } -impl LessThanComparable for S { - fn less(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 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 compare_0(x: Ptr, y: Ptr) -> i32 { - if ({ LessThanComparable::less((x).clone(), (y).clone()) }) { +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 { + 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()) }) { return -1_i32; } - if ({ LessThanComparable::less((y).clone(), (x).clone()) }) { + if ({ operator_lt_2((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 9b135af2e2..ec9f8e67fe 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -23,6 +23,51 @@ pub struct S { pub a: i32, pub b: i32, } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _x: *const S = __lhs; + operator_eq_0(_x, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _x: *const S = __lhs; + operator_ne_1(_x, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _x: *const S = __lhs; + operator_lt_2(_x, __rhs) + }) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -36,67 +81,63 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &s2) + operator_eq_0(_x, &s2) }) ); assert!( (unsafe { let _x: *const S = &s1; - WeaklyEqualityComparableWithUnsafe::not_equal(_x, &s3) + operator_ne_1(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &s3) + operator_eq_0(_x, &s3) }) ); assert!( (unsafe { let _x: *const S = &s1; - LessThanComparableUnsafe::less(_x, &s3) + operator_lt_2(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s3; - LessThanComparableUnsafe::less(_x, &s1) + operator_lt_2(_x, &s1) }) ); - assert!(((unsafe { compare_0(&s1, &s3,) }) == (-1_i32))); - assert!(((unsafe { compare_0(&s3, &s1,) }) == (1))); - assert!(((unsafe { compare_0(&s1, &s2,) }) == (0))); + assert!(((unsafe { compare_3(&s1, &s3,) }) == (-1_i32))); + assert!(((unsafe { compare_3(&s3, &s1,) }) == (1))); + assert!(((unsafe { compare_3(&s1, &s2,) }) == (0))); return 0; } -impl LessThanComparableUnsafe for S { - unsafe fn less(x: *const S, y: *const S) -> bool { - return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b))); - } +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 { + return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b))); } -pub unsafe fn compare_0(x: *const S, y: *const S) -> i32 { +pub unsafe fn compare_3(x: *const S, y: *const S) -> i32 { if (unsafe { let _x: *const S = x; - LessThanComparableUnsafe::less(_x, y) + operator_lt_2(_x, y) }) { return -1_i32; } if (unsafe { let _x: *const S = y; - LessThanComparableUnsafe::less(_x, x) + operator_lt_2(_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/class/class.compare/out/refcount/class.spaceship.rs b/tests/std/class/class.compare/out/refcount/class.spaceship.rs index 222558373f..f882ac34eb 100644 --- a/tests/std/class/class.compare/out/refcount/class.spaceship.rs +++ b/tests/std/class/class.compare/out/refcount/class.spaceship.rs @@ -17,10 +17,8 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(12)] pub struct p1_memberwise_in_declaration_order_Date { @@ -31,9 +29,8 @@ pub struct p1_memberwise_in_declaration_order_Date { #[offset(8)] pub day: i32, } -impl ThreeWayComparable for p1_memberwise_in_declaration_order_Date { - type Category = libcc2rs::StrongOrdering; - fn three_way( +impl p1_memberwise_in_declaration_order_Date { + pub fn operator_cmp( this: Ptr, _a0: Ptr, ) -> libcc2rs::StrongOrdering { @@ -66,11 +63,132 @@ impl ThreeWayComparable for p1_memberwise_in_declaration_order_Date { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.year) } == { _a0.with(|__s| __s.year) }) + && (({ this.with(|__s| __s.month) } == { _a0.with(|__s| __s.month) }) + && ({ this.with(|__s| __s.day) } == { _a0.with(|__s| __s.day) })); + } +} +impl Cpp17EqualityComparable for p1_memberwise_in_declaration_order_Date { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + ({ + p1_memberwise_in_declaration_order_Date::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_memberwise_in_declaration_order_Date { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + !({ + p1_memberwise_in_declaration_order_Date::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); } impl LessThanComparable for p1_memberwise_in_declaration_order_Date { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_memberwise_in_declaration_order_Date { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl ThreeWayComparable for p1_memberwise_in_declaration_order_Date { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); } pub fn test_0() { let earlier: Value = @@ -92,29 +210,76 @@ pub fn test_0() { day: 1, })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(earlier.as_pointer(), later_day.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + earlier.as_pointer(), + later_day.as_pointer(), + ) + }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(later_year.as_pointer(), later_day.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + later_year.as_pointer(), + later_day.as_pointer(), + ) + }) )); assert!(libcc2rs::is_eq( - ({ ThreeWayComparable::three_way(earlier.as_pointer(), earlier.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + earlier.as_pointer(), + earlier.as_pointer(), + ) + }) )); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(earlier.as_pointer(), later_day.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + earlier.as_pointer(), + later_day.as_pointer(), + ) + }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(later_year.as_pointer(), earlier.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + later_year.as_pointer(), + earlier.as_pointer(), + ) + }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(earlier.as_pointer(), earlier.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + earlier.as_pointer(), + earlier.as_pointer(), + ) + }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(later_year.as_pointer(), later_day.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_cmp( + later_year.as_pointer(), + later_day.as_pointer(), + ) + }) )); - assert!(({ WeaklyEqualityComparableWith::equal(earlier.as_pointer(), earlier.as_pointer(),) })); assert!( - !({ WeaklyEqualityComparableWith::equal(earlier.as_pointer(), later_day.as_pointer(),) }) + ({ + p1_memberwise_in_declaration_order_Date::operator_eq( + earlier.as_pointer(), + earlier.as_pointer(), + ) + }) + ); + assert!( + !({ + p1_memberwise_in_declaration_order_Date::operator_eq( + earlier.as_pointer(), + later_day.as_pointer(), + ) + }) ); } #[derive( @@ -128,10 +293,8 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(16)] pub struct p2_common_comparison_category_Reading { @@ -140,9 +303,8 @@ pub struct p2_common_comparison_category_Reading { #[offset(8)] pub value: f64, } -impl ThreeWayComparable for p2_common_comparison_category_Reading { - type Category = libcc2rs::PartialOrdering; - fn three_way( +impl p2_common_comparison_category_Reading { + pub fn operator_cmp( this: Ptr, _a0: Ptr, ) -> libcc2rs::PartialOrdering { @@ -173,11 +335,125 @@ impl ThreeWayComparable for p2_common_comparison_category_Reading { ({ (*libcc2rs::strong_ordering_equal().upgrade().deref()) }), ); } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.sensor) } == { _a0.with(|__s| __s.sensor) }) + && ({ this.with(|__s| __s.value) } == { _a0.with(|__s| __s.value) }); + } +} +impl Cpp17EqualityComparable for p2_common_comparison_category_Reading { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + ({ + p2_common_comparison_category_Reading::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p2_common_comparison_category_Reading { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + !({ + p2_common_comparison_category_Reading::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); } impl LessThanComparable for p2_common_comparison_category_Reading { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p2_common_comparison_category_Reading::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p2_common_comparison_category_Reading { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p2_common_comparison_category_Reading::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p2_common_comparison_category_Reading::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p2_common_comparison_category_Reading::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl ThreeWayComparable for p2_common_comparison_category_Reading { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::PartialOrdering, + |__lhs, __rhs| { + ({ + p2_common_comparison_category_Reading::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); } pub fn test_1() { let low: Value = @@ -191,20 +467,30 @@ pub fn test_1() { value: 2.5_f64, })); let order: Value = Rc::new(RefCell::new( - ({ ThreeWayComparable::three_way(low.as_pointer(), high.as_pointer()) }), + ({ + p2_common_comparison_category_Reading::operator_cmp(low.as_pointer(), high.as_pointer()) + }), )); assert!(libcc2rs::is_lt(({ (*order.borrow()) }))); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(low.as_pointer(), high.as_pointer(),) }) + ({ + p2_common_comparison_category_Reading::operator_cmp(low.as_pointer(), high.as_pointer()) + }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(high.as_pointer(), low.as_pointer(),) }) + ({ + p2_common_comparison_category_Reading::operator_cmp(high.as_pointer(), low.as_pointer()) + }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(low.as_pointer(), low.as_pointer(),) }) + ({ + p2_common_comparison_category_Reading::operator_cmp(low.as_pointer(), low.as_pointer()) + }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(high.as_pointer(), low.as_pointer(),) }) + ({ + p2_common_comparison_category_Reading::operator_cmp(high.as_pointer(), low.as_pointer()) + }) )); } #[derive( @@ -218,10 +504,8 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct weak_ordering_from_user_operator_Fraction { @@ -242,12 +526,76 @@ impl weak_ordering_from_user_operator_Fraction { } } impl LessThanComparable for weak_ordering_from_user_operator_Fraction { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(weak_ordering_from_user_operator_Fraction::operator_cmp( - this.clone(), - other.clone(), - )) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + weak_ordering_from_user_operator_Fraction::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for weak_ordering_from_user_operator_Fraction { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + weak_ordering_from_user_operator_Fraction::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + weak_ordering_from_user_operator_Fraction::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + weak_ordering_from_user_operator_Fraction::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); } pub fn test_2() { let half: Value = @@ -314,7 +662,14 @@ pub fn test_2() { }) )); assert!( - (if LessThanComparable::less(third.as_pointer().clone(), half.as_pointer().clone()) { + (if ::is_less( + LvalueRef::>::bind( + third.as_pointer().clone() + ), + LvalueRef::>::bind( + half.as_pointer().clone() + ), + ) { half.as_pointer() } else { third.as_pointer() @@ -323,7 +678,14 @@ pub fn test_2() { == 2) ); assert!( - (if LessThanComparable::less(half.as_pointer().clone(), third.as_pointer().clone()) { + (if ::is_less( + LvalueRef::>::bind( + half.as_pointer().clone() + ), + LvalueRef::>::bind( + third.as_pointer().clone() + ), + ) { half.as_pointer() } else { third.as_pointer() @@ -343,10 +705,8 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct partial_ordering_from_user_operator_Interval { @@ -375,12 +735,76 @@ impl partial_ordering_from_user_operator_Interval { } } impl LessThanComparable for partial_ordering_from_user_operator_Interval { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(partial_ordering_from_user_operator_Interval::operator_cmp( - this.clone(), - other.clone(), - )) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + partial_ordering_from_user_operator_Interval::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for partial_ordering_from_user_operator_Interval { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + partial_ordering_from_user_operator_Interval::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + partial_ordering_from_user_operator_Interval::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + partial_ordering_from_user_operator_Interval::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); } pub fn test_3() { let early: Value = @@ -490,17 +914,4 @@ fn main_0() -> i32 { ({ test_3() }); return 0; } -impl WeaklyEqualityComparableWith for p1_memberwise_in_declaration_order_Date { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.year) } == { _a0.with(|__s| __s.year) }) - && (({ this.with(|__s| __s.month) } == { _a0.with(|__s| __s.month) }) - && ({ this.with(|__s| __s.day) } == { _a0.with(|__s| __s.day) })); - } -} -impl WeaklyEqualityComparableWith for p2_common_comparison_category_Reading { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.sensor) } == { _a0.with(|__s| __s.sensor) }) - && ({ this.with(|__s| __s.value) } == { _a0.with(|__s| __s.value) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs index 38362beb7f..46b6cffd48 100644 --- a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs +++ b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs @@ -16,19 +16,16 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_memberwise_in_declaration_order_Date { pub year: i32, pub month: i32, pub day: i32, } -impl ThreeWayComparableUnsafe for p1_memberwise_in_declaration_order_Date { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way( +impl p1_memberwise_in_declaration_order_Date { + pub unsafe fn operator_cmp( this: *const Self, _a0: *const p1_memberwise_in_declaration_order_Date, ) -> libcc2rs::StrongOrdering { @@ -56,11 +53,125 @@ impl ThreeWayComparableUnsafe for p1_memberwise_in_declaration_order_Date { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_eq( + this: *const Self, + _a0: *const p1_memberwise_in_declaration_order_Date, + ) -> bool { + return (((*this).year) == ((*_a0).year)) + && ((((*this).month) == ((*_a0).month)) && (((*this).day) == ((*_a0).day))); + } +} +impl Cpp17EqualityComparableUnsafe for p1_memberwise_in_declaration_order_Date { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_memberwise_in_declaration_order_Date { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + !(unsafe { + p1_memberwise_in_declaration_order_Date::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); } impl LessThanComparableUnsafe for p1_memberwise_in_declaration_order_Date { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_memberwise_in_declaration_order_Date { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_memberwise_in_declaration_order_Date, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p1_memberwise_in_declaration_order_Date { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const (*__lhs), __rhs) + }) + } + ); } pub unsafe fn test_0() { let mut earlier: p1_memberwise_in_declaration_order_Date = @@ -82,40 +193,52 @@ pub unsafe fn test_0() { day: 1, }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const earlier, &later_day,) }) + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const earlier, &later_day) + }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const later_year, &later_day,) }) + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const later_year, &later_day) + }) )); assert!(libcc2rs::is_eq( (unsafe { let _arg0: *const p1_memberwise_in_declaration_order_Date = &earlier; - ThreeWayComparableUnsafe::three_way(&raw const earlier, _arg0) + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const earlier, _arg0) }) )); assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const earlier, &later_day,) }) + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const earlier, &later_day) + }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const later_year, &earlier,) }) + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const later_year, &earlier) + }) )); assert!(libcc2rs::is_lteq( (unsafe { let _arg0: *const p1_memberwise_in_declaration_order_Date = &earlier; - ThreeWayComparableUnsafe::three_way(&raw const earlier, _arg0) + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const earlier, _arg0) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const later_year, &later_day,) }) + (unsafe { + p1_memberwise_in_declaration_order_Date::operator_cmp(&raw const later_year, &later_day) + }) )); assert!( (unsafe { let _arg0: *const p1_memberwise_in_declaration_order_Date = &earlier; - WeaklyEqualityComparableWithUnsafe::equal(&raw const earlier, _arg0) + p1_memberwise_in_declaration_order_Date::operator_eq(&raw const earlier, _arg0) }) ); assert!( - !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const earlier, &later_day,) }) + !(unsafe { + p1_memberwise_in_declaration_order_Date::operator_eq(&raw const earlier, &later_day) + }) ); } #[repr(C)] @@ -128,18 +251,15 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p2_common_comparison_category_Reading { pub sensor: i32, pub value: f64, } -impl ThreeWayComparableUnsafe for p2_common_comparison_category_Reading { - type Category = libcc2rs::PartialOrdering; - unsafe fn three_way( +impl p2_common_comparison_category_Reading { + pub unsafe fn operator_cmp( this: *const Self, _a0: *const p2_common_comparison_category_Reading, ) -> libcc2rs::PartialOrdering { @@ -162,11 +282,112 @@ impl ThreeWayComparableUnsafe for p2_common_comparison_category_Reading { } return libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_EQUAL); } + pub unsafe fn operator_eq( + this: *const Self, + _a0: *const p2_common_comparison_category_Reading, + ) -> bool { + return (((*this).sensor) == ((*_a0).sensor)) && (((*this).value) == ((*_a0).value)); + } +} +impl Cpp17EqualityComparableUnsafe for p2_common_comparison_category_Reading { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + (unsafe { + p2_common_comparison_category_Reading::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p2_common_comparison_category_Reading { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + !(unsafe { + p2_common_comparison_category_Reading::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); } impl LessThanComparableUnsafe for p2_common_comparison_category_Reading { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p2_common_comparison_category_Reading::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p2_common_comparison_category_Reading { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p2_common_comparison_category_Reading::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p2_common_comparison_category_Reading::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_common_comparison_category_Reading, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p2_common_comparison_category_Reading::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p2_common_comparison_category_Reading { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::PartialOrdering, + |__lhs, __rhs| { + (unsafe { + p2_common_comparison_category_Reading::operator_cmp(&raw const (*__lhs), __rhs) + }) + } + ); } pub unsafe fn test_1() { let mut low: p2_common_comparison_category_Reading = p2_common_comparison_category_Reading { @@ -178,22 +399,22 @@ pub unsafe fn test_1() { value: 2.5_f64, }; let mut order: libcc2rs::PartialOrdering = - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const low, &high) }); + (unsafe { p2_common_comparison_category_Reading::operator_cmp(&raw const low, &high) }); assert!(libcc2rs::is_lt(order)); assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const low, &high,) }) + (unsafe { p2_common_comparison_category_Reading::operator_cmp(&raw const low, &high,) }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const high, &low,) }) + (unsafe { p2_common_comparison_category_Reading::operator_cmp(&raw const high, &low,) }) )); assert!(libcc2rs::is_lteq( (unsafe { let _arg0: *const p2_common_comparison_category_Reading = &low; - ThreeWayComparableUnsafe::three_way(&raw const low, _arg0) + p2_common_comparison_category_Reading::operator_cmp(&raw const low, _arg0) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const high, &low,) }) + (unsafe { p2_common_comparison_category_Reading::operator_cmp(&raw const high, &low,) }) )); } #[repr(C)] @@ -206,10 +427,8 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct weak_ordering_from_user_operator_Fraction { pub numerator: i32, @@ -227,11 +446,76 @@ impl weak_ordering_from_user_operator_Fraction { } } impl LessThanComparableUnsafe for weak_ordering_from_user_operator_Fraction { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(weak_ordering_from_user_operator_Fraction::operator_cmp( - this, other, - )) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + weak_ordering_from_user_operator_Fraction::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for weak_ordering_from_user_operator_Fraction { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + weak_ordering_from_user_operator_Fraction::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + weak_ordering_from_user_operator_Fraction::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + weak_ordering_from_user_operator_Fraction, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + weak_ordering_from_user_operator_Fraction::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); } pub unsafe fn test_2() { let mut half: weak_ordering_from_user_operator_Fraction = @@ -283,7 +567,10 @@ pub unsafe fn test_2() { (((*{ let __a: *const _ = &mut third; let __b: *const _ = &mut half; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -296,7 +583,10 @@ pub unsafe fn test_2() { (((*{ let __a: *const _ = &mut third; let __b: *const _ = &mut half; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -316,10 +606,8 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct partial_ordering_from_user_operator_Interval { pub low: i32, @@ -343,11 +631,76 @@ impl partial_ordering_from_user_operator_Interval { } } impl LessThanComparableUnsafe for partial_ordering_from_user_operator_Interval { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(partial_ordering_from_user_operator_Interval::operator_cmp( - this, other, - )) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + partial_ordering_from_user_operator_Interval::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for partial_ordering_from_user_operator_Interval { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + partial_ordering_from_user_operator_Interval::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + partial_ordering_from_user_operator_Interval::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + partial_ordering_from_user_operator_Interval, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + partial_ordering_from_user_operator_Interval::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); } pub unsafe fn test_3() { let mut early: partial_ordering_from_user_operator_Interval = @@ -440,18 +793,4 @@ unsafe fn main_0() -> i32 { (unsafe { test_3() }); return 0; } -impl WeaklyEqualityComparableWithUnsafe for p1_memberwise_in_declaration_order_Date { - unsafe fn equal( - this: *const Self, - _a0: *const p1_memberwise_in_declaration_order_Date, - ) -> bool { - return (((*this).year) == ((*_a0).year)) - && ((((*this).month) == ((*_a0).month)) && (((*this).day) == ((*_a0).day))); - } -} -impl WeaklyEqualityComparableWithUnsafe for p2_common_comparison_category_Reading { - unsafe fn equal(this: *const Self, _a0: *const p2_common_comparison_category_Reading) -> bool { - return (((*this).sensor) == ((*_a0).sensor)) && (((*this).value) == ((*_a0).value)); - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 4c4224906a..c38966cffc 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -68,6 +68,86 @@ impl p2_implicit_conversion_function_Ratio { return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); } } +impl Cpp17EqualityComparable for p2_implicit_conversion_function_Ratio { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } == { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p2_implicit_conversion_function_Ratio { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } != { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl LessThanComparable for p2_implicit_conversion_function_Ratio { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } < { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl PartiallyOrderedWith for p2_implicit_conversion_function_Ratio { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } > { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } <= { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p2_implicit_conversion_function_Ratio::to_i32((__lhs).clone()) }) } >= { + ({ p2_implicit_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} pub fn test_1() { let ratio: Value = Rc::new(RefCell::new(p2_implicit_conversion_function_Ratio { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index 9aa229123c..7a1c4429bc 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -59,6 +59,80 @@ impl p2_implicit_conversion_function_Ratio { return (((*this).numerator) / ((*this).denominator)); } } +impl Cpp17EqualityComparableUnsafe for p2_implicit_conversion_function_Ratio { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + == (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p2_implicit_conversion_function_Ratio { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + != (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl LessThanComparableUnsafe for p2_implicit_conversion_function_Ratio { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + < (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for p2_implicit_conversion_function_Ratio { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + > (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + <= (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_implicit_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__lhs)) }) + >= (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} pub unsafe fn test_1() { let mut ratio: p2_implicit_conversion_function_Ratio = p2_implicit_conversion_function_Ratio { numerator: 9, diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs index 36685a983f..a56508da10 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs @@ -28,6 +28,39 @@ pub struct p1_3_not_equal_Meters { #[offset(0)] pub value: i32, } +impl p1_3_not_equal_Meters { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { other.with(|__s| __s.value) }); + } + pub fn operator_ne(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 Cpp17EqualityComparable for p1_3_not_equal_Meters { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_3_not_equal_Meters, + |__lhs, __rhs| { + ({ p1_3_not_equal_Meters::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_3_not_equal_Meters { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_3_not_equal_Meters, + |__lhs, __rhs| { + ({ p1_3_not_equal_Meters::operator_ne((__lhs).clone(), (__rhs).clone()) }) + } + ); +} pub fn test_1() { let three: Value = Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 3 })); @@ -35,15 +68,11 @@ pub fn test_1() { 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!(({ p1_3_not_equal_Meters::operator_eq(three.as_pointer(), also_three.as_pointer(),) })); assert!( - ({ WeaklyEqualityComparableWith::equal(three.as_pointer(), also_three.as_pointer(),) }) + !({ p1_3_not_equal_Meters::operator_ne(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!(({ p1_3_not_equal_Meters::operator_ne(three.as_pointer(), four.as_pointer(),) })); assert!((not_equal_calls_0.with(|rc| *rc.borrow()) == 2)); } #[derive( @@ -65,31 +94,84 @@ pub struct p1_2_reversed_operands_Meters { #[offset(0)] pub value: i32, } +impl p1_2_reversed_operands_Meters { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl Cpp17EqualityComparable for p1_2_reversed_operands_Meters { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { + ({ p1_2_reversed_operands_Meters::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl Cpp17EqualityComparable for i32 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_2_reversed_operands_Meters, + |__lhs, __rhs| { + ({ p1_2_reversed_operands_Meters::operator_eq((__rhs).clone(), (__lhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_2_reversed_operands_Meters { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { + !({ p1_2_reversed_operands_Meters::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for i32 { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_2_reversed_operands_Meters, + |__lhs, __rhs| { + !({ p1_2_reversed_operands_Meters::operator_eq((__rhs).clone(), (__lhs).clone()) }) + } + ); +} 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()) + p1_2_reversed_operands_Meters::operator_eq(three.as_pointer(), _other.as_pointer()) }) ); assert!( ({ let _other: Value = Rc::new(RefCell::new(3)); - WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + p1_2_reversed_operands_Meters::operator_eq(three.as_pointer(), _other.as_pointer()) }) ); assert!( !({ let _other: Value = Rc::new(RefCell::new(4)); - WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + p1_2_reversed_operands_Meters::operator_eq(three.as_pointer(), _other.as_pointer()) }) ); assert!( !({ let _other: Value = Rc::new(RefCell::new(4)); - WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + p1_2_reversed_operands_Meters::operator_eq(three.as_pointer(), _other.as_pointer()) }) ); } @@ -112,6 +194,59 @@ pub struct p1_different_types_Meters { #[offset(0)] pub value: i32, } +impl p1_different_types_Meters { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl Cpp17EqualityComparable for p1_different_types_Meters { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { + ({ p1_different_types_Meters::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl Cpp17EqualityComparable for i32 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_different_types_Meters, + |__lhs, __rhs| { + ({ p1_different_types_Meters::operator_eq((__rhs).clone(), (__lhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_different_types_Meters { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { + !({ p1_different_types_Meters::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for i32 { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_different_types_Meters, + |__lhs, __rhs| { + !({ p1_different_types_Meters::operator_eq((__rhs).clone(), (__lhs).clone()) }) + } + ); +} pub fn test_3() { let lengths: Value> = Rc::new(RefCell::new(Vec::from([ p1_different_types_Meters { value: 1 }, @@ -126,53 +261,21 @@ pub fn test_3() { 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(); - } + while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind(__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!(WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind( + found.as_pointer() + ), + LvalueRef::>>::bind( + 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()) - } - }); + 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 as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind(__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,) => { Cpp17EqualityComparable::is_equal( LvalueRef:: >>::bind((__tmp_1 ).clone()), LvalueRef:: >>::bind((__tmp_3 ).clone()), ) } } ); } pub fn main() { __cpp2rust_init_globals(); @@ -184,35 +287,6 @@ fn main_0() -> i32 { ({ 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/refcount/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs index ac877077aa..e51bc38568 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs @@ -34,10 +34,105 @@ pub struct p1_each_relation_is_an_operator_Score { #[offset(0)] pub points: i32, } -impl LessThanComparable for p1_each_relation_is_an_operator_Score { - fn less(this: Ptr, other: Ptr) -> bool { +impl p1_each_relation_is_an_operator_Score { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.points) } == { other.with(|__s| __s.points) }); + } + pub fn operator_lt(this: Ptr, other: Ptr) -> bool { return ({ this.with(|__s| __s.points) } < { other.with(|__s| __s.points) }); } + pub fn operator_gt(this: Ptr, other: Ptr) -> bool { + (*greater_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.points) } > { other.with(|__s| __s.points) }); + } + pub fn operator_le(this: Ptr, other: Ptr) -> bool { + (*less_equal_calls_1.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.points) } <= { other.with(|__s| __s.points) }); + } + pub fn operator_ge(this: Ptr, other: Ptr) -> bool { + (*greater_equal_calls_2.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.points) } >= { other.with(|__s| __s.points) }); + } +} +impl Cpp17EqualityComparable for p1_each_relation_is_an_operator_Score { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + ({ + p1_each_relation_is_an_operator_Score::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_each_relation_is_an_operator_Score { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + !({ + p1_each_relation_is_an_operator_Score::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl LessThanComparable for p1_each_relation_is_an_operator_Score { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + ({ + p1_each_relation_is_an_operator_Score::operator_lt((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl PartiallyOrderedWith for p1_each_relation_is_an_operator_Score { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + ({ + p1_each_relation_is_an_operator_Score::operator_gt((__lhs).clone(), (__rhs).clone()) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + ({ + p1_each_relation_is_an_operator_Score::operator_le((__lhs).clone(), (__rhs).clone()) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + ({ + p1_each_relation_is_an_operator_Score::operator_ge((__lhs).clone(), (__rhs).clone()) + }) + } + ); } pub fn test_3() { let low: Value = @@ -48,12 +143,36 @@ pub fn test_3() { Rc::new(RefCell::new(p1_each_relation_is_an_operator_Score { points: 20, })); - assert!(({ LessThanComparable::less(low.as_pointer(), high.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater(high.as_pointer(), low.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::less_equal(low.as_pointer(), high.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::less_equal(low.as_pointer(), low.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater_equal(high.as_pointer(), low.as_pointer(),) })); - assert!(!({ PartiallyOrderedWith::greater_equal(low.as_pointer(), high.as_pointer(),) })); + assert!( + ({ + p1_each_relation_is_an_operator_Score::operator_lt(low.as_pointer(), high.as_pointer()) + }) + ); + assert!( + ({ + p1_each_relation_is_an_operator_Score::operator_gt(high.as_pointer(), low.as_pointer()) + }) + ); + assert!( + ({ + p1_each_relation_is_an_operator_Score::operator_le(low.as_pointer(), high.as_pointer()) + }) + ); + assert!( + ({ + p1_each_relation_is_an_operator_Score::operator_le(low.as_pointer(), low.as_pointer()) + }) + ); + assert!( + ({ + p1_each_relation_is_an_operator_Score::operator_ge(high.as_pointer(), low.as_pointer()) + }) + ); + assert!( + !({ + p1_each_relation_is_an_operator_Score::operator_ge(low.as_pointer(), high.as_pointer()) + }) + ); assert!((greater_calls_0.with(|rc| *rc.borrow()) == 1)); assert!((less_equal_calls_1.with(|rc| *rc.borrow()) == 2)); assert!((greater_equal_calls_2.with(|rc| *rc.borrow()) == 2)); @@ -69,19 +188,19 @@ pub fn test_3() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct p1_relations_from_three_way_Level { #[offset(0)] pub depth: i32, } -impl ThreeWayComparable for p1_relations_from_three_way_Level { - type Category = libcc2rs::StrongOrdering; - fn three_way( +impl p1_relations_from_three_way_Level { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.depth) } == { other.with(|__s| __s.depth) }); + } + pub fn operator_cmp( this: Ptr, other: Ptr, ) -> libcc2rs::StrongOrdering { @@ -91,10 +210,111 @@ impl ThreeWayComparable for p1_relations_from_three_way_Level { )); } } +impl Cpp17EqualityComparable for p1_relations_from_three_way_Level { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + ({ p1_relations_from_three_way_Level::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_relations_from_three_way_Level { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + !({ p1_relations_from_three_way_Level::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} impl LessThanComparable for p1_relations_from_three_way_Level { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), other.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_relations_from_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_relations_from_three_way_Level { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_relations_from_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_relations_from_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_relations_from_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl ThreeWayComparable for p1_relations_from_three_way_Level { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + ({ p1_relations_from_three_way_Level::operator_cmp((__lhs).clone(), (__rhs).clone()) }) + } + ); } pub fn test_4() { let shallow: Value = @@ -102,23 +322,41 @@ pub fn test_4() { let deep: Value = Rc::new(RefCell::new(p1_relations_from_three_way_Level { depth: 5 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(shallow.as_pointer(), deep.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp(shallow.as_pointer(), deep.as_pointer()) + }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(deep.as_pointer(), shallow.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp(deep.as_pointer(), shallow.as_pointer()) + }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(shallow.as_pointer(), deep.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp(shallow.as_pointer(), deep.as_pointer()) + }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(shallow.as_pointer(), shallow.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp( + shallow.as_pointer(), + shallow.as_pointer(), + ) + }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(deep.as_pointer(), shallow.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp(deep.as_pointer(), shallow.as_pointer()) + }) )); assert!( !(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(shallow.as_pointer(), deep.as_pointer(),) }) + ({ + p1_relations_from_three_way_Level::operator_cmp( + shallow.as_pointer(), + deep.as_pointer(), + ) + }) )) ); } @@ -154,14 +392,83 @@ impl p1_operator_preferred_over_three_way_Level { &(other.with(|__s| __s.depth)), )); } + pub fn operator_gt( + this: Ptr, + other: Ptr, + ) -> bool { + (*greater_calls_5.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.depth) } > { other.with(|__s| __s.depth) }); + } } impl LessThanComparable for p1_operator_preferred_over_three_way_Level { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(p1_operator_preferred_over_three_way_Level::operator_cmp( - this.clone(), - other.clone(), - )) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_operator_preferred_over_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_operator_preferred_over_three_way_Level { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + ({ + p1_operator_preferred_over_three_way_Level::operator_gt( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_operator_preferred_over_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_operator_preferred_over_three_way_Level::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); } pub fn test_6() { let shallow: Value = @@ -172,7 +479,14 @@ pub fn test_6() { Rc::new(RefCell::new(p1_operator_preferred_over_three_way_Level { depth: 5, })); - assert!(({ PartiallyOrderedWith::greater(deep.as_pointer(), shallow.as_pointer(),) })); + assert!( + ({ + p1_operator_preferred_over_three_way_Level::operator_gt( + deep.as_pointer(), + shallow.as_pointer(), + ) + }) + ); assert!((greater_calls_5.with(|rc| *rc.borrow()) == 1)); assert!(libcc2rs::is_lt( ({ @@ -202,54 +516,6 @@ fn main_0() -> i32 { ({ test_6() }); return 0; } -impl PartiallyOrderedWith for p1_each_relation_is_an_operator_Score { - fn greater(this: Ptr, other: Ptr) -> bool { - (*greater_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ this.with(|__s| __s.points) } > { other.with(|__s| __s.points) }); - } - fn less_equal(this: Ptr, other: Ptr) -> bool { - (*less_equal_calls_1.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ this.with(|__s| __s.points) } <= { other.with(|__s| __s.points) }); - } - fn greater_equal(this: Ptr, other: Ptr) -> bool { - (*greater_equal_calls_2.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ this.with(|__s| __s.points) } >= { other.with(|__s| __s.points) }); - } - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } -} -impl PartiallyOrderedWith for p1_operator_preferred_over_three_way_Level { - fn greater(this: Ptr, other: Ptr) -> bool { - (*greater_calls_5.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ this.with(|__s| __s.depth) } > { other.with(|__s| __s.depth) }); - } - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } - fn less_equal(lhs: Ptr, rhs: Ptr) -> bool { - libcc2rs::is_lteq(p1_operator_preferred_over_three_way_Level::operator_cmp( - lhs.clone(), - rhs.clone(), - )) - } - fn greater_equal(lhs: Ptr, rhs: Ptr) -> bool { - libcc2rs::is_gteq(p1_operator_preferred_over_three_way_Level::operator_cmp( - lhs.clone(), - rhs.clone(), - )) - } -} -impl WeaklyEqualityComparableWith for p1_each_relation_is_an_operator_Score { - fn equal(this: Ptr, other: Ptr) -> bool { - return ({ this.with(|__s| __s.points) } == { other.with(|__s| __s.points) }); - } -} -impl WeaklyEqualityComparableWith for p1_relations_from_three_way_Level { - fn equal(this: Ptr, other: Ptr) -> bool { - return ({ this.with(|__s| __s.depth) } == { other.with(|__s| __s.depth) }); - } -} pub fn __cpp2rust_init_globals() { let _ = greater_calls_0.with(|_| ()); let _ = less_equal_calls_1.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 index 232ae81cb3..7b4c7561ef 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -24,15 +24,46 @@ pub static mut not_equal_calls_0: std::cell::LazyCell = pub struct p1_3_not_equal_Meters { pub value: i32, } +impl p1_3_not_equal_Meters { + pub unsafe fn operator_eq(this: *const Self, other: *const p1_3_not_equal_Meters) -> bool { + return (((*this).value) == ((*other).value)); + } + pub unsafe fn operator_ne(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 Cpp17EqualityComparableUnsafe for p1_3_not_equal_Meters { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_3_not_equal_Meters, + |__lhs, __rhs| { + (unsafe { p1_3_not_equal_Meters::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_3_not_equal_Meters { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_3_not_equal_Meters, + |__lhs, __rhs| { + (unsafe { p1_3_not_equal_Meters::operator_ne(&raw const (*__lhs), __rhs) }) + } + ); +} 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!((unsafe { p1_3_not_equal_Meters::operator_eq(&raw const three, &also_three,) })); + assert!(!(unsafe { p1_3_not_equal_Meters::operator_ne(&raw const three, &also_three,) })); + assert!((unsafe { p1_3_not_equal_Meters::operator_ne(&raw const three, &four,) })); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut not_equal_calls_0)) == (2))); } #[repr(C)] @@ -51,30 +82,83 @@ pub unsafe fn test_1() { pub struct p1_2_reversed_operands_Meters { pub value: i32, } +impl p1_2_reversed_operands_Meters { + pub unsafe fn operator_eq(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl Cpp17EqualityComparableUnsafe for p1_2_reversed_operands_Meters { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { + (unsafe { p1_2_reversed_operands_Meters::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl Cpp17EqualityComparableUnsafe for i32 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_2_reversed_operands_Meters, + |__lhs, __rhs| { + (unsafe { p1_2_reversed_operands_Meters::operator_eq(&raw const (*__rhs), __lhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_2_reversed_operands_Meters { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { + !(unsafe { p1_2_reversed_operands_Meters::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_2_reversed_operands_Meters, + |__lhs, __rhs| { + !(unsafe { p1_2_reversed_operands_Meters::operator_eq(&raw const (*__rhs), __lhs) }) + } + ); +} 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) + p1_2_reversed_operands_Meters::operator_eq(&raw const three, &mut _other) }) ); assert!( (unsafe { let mut _other: i32 = 3; - WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + p1_2_reversed_operands_Meters::operator_eq(&raw const three, &mut _other) }) ); assert!( !(unsafe { let mut _other: i32 = 4; - WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + p1_2_reversed_operands_Meters::operator_eq(&raw const three, &mut _other) }) ); assert!( !(unsafe { let mut _other: i32 = 4; - WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + p1_2_reversed_operands_Meters::operator_eq(&raw const three, &mut _other) }) ); } @@ -94,6 +178,59 @@ pub unsafe fn test_2() { pub struct p1_different_types_Meters { pub value: i32, } +impl p1_different_types_Meters { + pub unsafe fn operator_eq(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl Cpp17EqualityComparableUnsafe for p1_different_types_Meters { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { + (unsafe { p1_different_types_Meters::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl Cpp17EqualityComparableUnsafe for i32 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_different_types_Meters, + |__lhs, __rhs| { + (unsafe { p1_different_types_Meters::operator_eq(&raw const (*__rhs), __lhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_different_types_Meters { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { + !(unsafe { p1_different_types_Meters::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_different_types_Meters, + |__lhs, __rhs| { + !(unsafe { p1_different_types_Meters::operator_eq(&raw const (*__rhs), __lhs) }) + } + ); +} pub unsafe fn test_3() { let mut lengths: Vec = Vec::from([ p1_different_types_Meters { value: 1 }, @@ -104,31 +241,29 @@ pub unsafe fn test_3() { 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(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_1 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&2 ), ) { __it.iter_inc(); } __it }; - assert!(WeaklyEqualityComparableWithUnsafe::not_equal( - &found, - &lengths.end() + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind( + &found + ), + LvalueRefUnsafe::>>::bind( + &lengths.end() + ), )); assert!((((*found.iter_deref()).value) == (2))); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ 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(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_3 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&7 ), ) { __it.iter_inc(); } __it - }, - &lengths.end() + }), + LvalueRefUnsafe::>>::bind( + &lengths.end() + ), )); } pub fn main() { @@ -143,35 +278,6 @@ unsafe fn main_0() -> i32 { (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/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs index 4afcb87738..bea3a27776 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs @@ -28,27 +28,147 @@ pub static mut greater_equal_calls_2: std::cell::LazyCell = pub struct p1_each_relation_is_an_operator_Score { pub points: i32, } -impl LessThanComparableUnsafe for p1_each_relation_is_an_operator_Score { - unsafe fn less(this: *const Self, other: *const p1_each_relation_is_an_operator_Score) -> bool { +impl p1_each_relation_is_an_operator_Score { + pub unsafe fn operator_eq( + this: *const Self, + other: *const p1_each_relation_is_an_operator_Score, + ) -> bool { + return (((*this).points) == ((*other).points)); + } + pub unsafe fn operator_lt( + this: *const Self, + other: *const p1_each_relation_is_an_operator_Score, + ) -> bool { return (((*this).points) < ((*other).points)); } + pub unsafe fn operator_gt( + this: *const Self, + other: *const p1_each_relation_is_an_operator_Score, + ) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_0)).prefix_inc(); + return (((*this).points) > ((*other).points)); + } + pub unsafe fn operator_le( + this: *const Self, + other: *const p1_each_relation_is_an_operator_Score, + ) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut less_equal_calls_1)).prefix_inc(); + return (((*this).points) <= ((*other).points)); + } + pub unsafe fn operator_ge( + this: *const Self, + other: *const p1_each_relation_is_an_operator_Score, + ) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_equal_calls_2)).prefix_inc(); + return (((*this).points) >= ((*other).points)); + } +} +impl Cpp17EqualityComparableUnsafe for p1_each_relation_is_an_operator_Score { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + (unsafe { + p1_each_relation_is_an_operator_Score::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_each_relation_is_an_operator_Score { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + !(unsafe { + p1_each_relation_is_an_operator_Score::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for p1_each_relation_is_an_operator_Score { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + (unsafe { + p1_each_relation_is_an_operator_Score::operator_lt(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_each_relation_is_an_operator_Score { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + (unsafe { + p1_each_relation_is_an_operator_Score::operator_gt(&raw const (*__lhs), __rhs) + }) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + (unsafe { + p1_each_relation_is_an_operator_Score::operator_le(&raw const (*__lhs), __rhs) + }) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_each_relation_is_an_operator_Score, + |__lhs, __rhs| { + (unsafe { + p1_each_relation_is_an_operator_Score::operator_ge(&raw const (*__lhs), __rhs) + }) + } + ); } pub unsafe fn test_3() { let mut low: p1_each_relation_is_an_operator_Score = p1_each_relation_is_an_operator_Score { points: 10 }; let mut high: p1_each_relation_is_an_operator_Score = p1_each_relation_is_an_operator_Score { points: 20 }; - assert!((unsafe { LessThanComparableUnsafe::less(&raw const low, &high,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::greater(&raw const high, &low,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::less_equal(&raw const low, &high,) })); + assert!( + (unsafe { p1_each_relation_is_an_operator_Score::operator_lt(&raw const low, &high,) }) + ); + assert!( + (unsafe { p1_each_relation_is_an_operator_Score::operator_gt(&raw const high, &low,) }) + ); + assert!( + (unsafe { p1_each_relation_is_an_operator_Score::operator_le(&raw const low, &high,) }) + ); assert!( (unsafe { let _other: *const p1_each_relation_is_an_operator_Score = &low; - PartiallyOrderedWithUnsafe::less_equal(&raw const low, _other) + p1_each_relation_is_an_operator_Score::operator_le(&raw const low, _other) }) ); - assert!((unsafe { PartiallyOrderedWithUnsafe::greater_equal(&raw const high, &low,) })); - assert!(!(unsafe { PartiallyOrderedWithUnsafe::greater_equal(&raw const low, &high,) })); + assert!( + (unsafe { p1_each_relation_is_an_operator_Score::operator_ge(&raw const high, &low,) }) + ); + assert!( + !(unsafe { p1_each_relation_is_an_operator_Score::operator_ge(&raw const low, &high,) }) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut less_equal_calls_1)) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut greater_equal_calls_2)) == (2))); @@ -63,17 +183,20 @@ pub unsafe fn test_3() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_relations_from_three_way_Level { pub depth: i32, } -impl ThreeWayComparableUnsafe for p1_relations_from_three_way_Level { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way( +impl p1_relations_from_three_way_Level { + pub unsafe fn operator_eq( + this: *const Self, + other: *const p1_relations_from_three_way_Level, + ) -> bool { + return (((*this).depth) == ((*other).depth)); + } + pub unsafe fn operator_cmp( this: *const Self, other: *const p1_relations_from_three_way_Level, ) -> libcc2rs::StrongOrdering { @@ -83,10 +206,99 @@ impl ThreeWayComparableUnsafe for p1_relations_from_three_way_Level { )); } } +impl Cpp17EqualityComparableUnsafe for p1_relations_from_three_way_Level { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + (unsafe { p1_relations_from_three_way_Level::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_relations_from_three_way_Level { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + !(unsafe { p1_relations_from_three_way_Level::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} impl LessThanComparableUnsafe for p1_relations_from_three_way_Level { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, other)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_relations_from_three_way_Level::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_relations_from_three_way_Level { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_relations_from_three_way_Level::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_relations_from_three_way_Level::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_relations_from_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_relations_from_three_way_Level::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p1_relations_from_three_way_Level { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { p1_relations_from_three_way_Level::operator_cmp(&raw const (*__lhs), __rhs) }) + } + ); } pub unsafe fn test_4() { let mut shallow: p1_relations_from_three_way_Level = @@ -94,26 +306,28 @@ pub unsafe fn test_4() { let mut deep: p1_relations_from_three_way_Level = p1_relations_from_three_way_Level { depth: 5 }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const shallow, &deep,) }) + (unsafe { p1_relations_from_three_way_Level::operator_cmp(&raw const shallow, &deep,) }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const deep, &shallow,) }) + (unsafe { p1_relations_from_three_way_Level::operator_cmp(&raw const deep, &shallow,) }) )); assert!(libcc2rs::is_lteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const shallow, &deep,) }) + (unsafe { p1_relations_from_three_way_Level::operator_cmp(&raw const shallow, &deep,) }) )); assert!(libcc2rs::is_lteq( (unsafe { let _other: *const p1_relations_from_three_way_Level = &shallow; - ThreeWayComparableUnsafe::three_way(&raw const shallow, _other) + p1_relations_from_three_way_Level::operator_cmp(&raw const shallow, _other) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const deep, &shallow,) }) + (unsafe { p1_relations_from_three_way_Level::operator_cmp(&raw const deep, &shallow,) }) )); assert!( !(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const shallow, &deep,) }) + (unsafe { + p1_relations_from_three_way_Level::operator_cmp(&raw const shallow, &deep) + }) )) ); } @@ -145,20 +359,91 @@ impl p1_operator_preferred_over_three_way_Level { &((*other).depth), )); } + pub unsafe fn operator_gt( + this: *const Self, + other: *const p1_operator_preferred_over_three_way_Level, + ) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_5)).prefix_inc(); + return (((*this).depth) > ((*other).depth)); + } } impl LessThanComparableUnsafe for p1_operator_preferred_over_three_way_Level { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(p1_operator_preferred_over_three_way_Level::operator_cmp( - this, other, - )) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_operator_preferred_over_three_way_Level::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_operator_preferred_over_three_way_Level { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + (unsafe { + p1_operator_preferred_over_three_way_Level::operator_gt(&raw const (*__lhs), __rhs) + }) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_operator_preferred_over_three_way_Level::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_operator_preferred_over_three_way_Level, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_operator_preferred_over_three_way_Level::operator_cmp( + &raw const (*__lhs), + __rhs, + ) + }), + ) + } + ); } pub unsafe fn test_6() { let mut shallow: p1_operator_preferred_over_three_way_Level = p1_operator_preferred_over_three_way_Level { depth: 1 }; let mut deep: p1_operator_preferred_over_three_way_Level = p1_operator_preferred_over_three_way_Level { depth: 5 }; - assert!((unsafe { PartiallyOrderedWithUnsafe::greater(&raw const deep, &shallow,) })); + assert!( + (unsafe { + p1_operator_preferred_over_three_way_Level::operator_gt(&raw const deep, &shallow) + }) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_5)) == (1))); assert!(libcc2rs::is_lt( (unsafe { @@ -184,67 +469,6 @@ unsafe fn main_0() -> i32 { (unsafe { test_6() }); return 0; } -impl PartiallyOrderedWithUnsafe for p1_each_relation_is_an_operator_Score { - unsafe fn greater( - this: *const Self, - other: *const p1_each_relation_is_an_operator_Score, - ) -> bool { - (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_0)).prefix_inc(); - return (((*this).points) > ((*other).points)); - } - unsafe fn less_equal( - this: *const Self, - other: *const p1_each_relation_is_an_operator_Score, - ) -> bool { - (*std::cell::LazyCell::force_mut(&mut *&raw mut less_equal_calls_1)).prefix_inc(); - return (((*this).points) <= ((*other).points)); - } - unsafe fn greater_equal( - this: *const Self, - other: *const p1_each_relation_is_an_operator_Score, - ) -> bool { - (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_equal_calls_2)).prefix_inc(); - return (((*this).points) >= ((*other).points)); - } - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } -} -impl PartiallyOrderedWithUnsafe for p1_operator_preferred_over_three_way_Level { - unsafe fn greater( - this: *const Self, - other: *const p1_operator_preferred_over_three_way_Level, - ) -> bool { - (*std::cell::LazyCell::force_mut(&mut *&raw mut greater_calls_5)).prefix_inc(); - return (((*this).depth) > ((*other).depth)); - } - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } - unsafe fn less_equal(lhs: *const Self, rhs: *const Self) -> bool { - libcc2rs::is_lteq(p1_operator_preferred_over_three_way_Level::operator_cmp( - lhs, rhs, - )) - } - unsafe fn greater_equal(lhs: *const Self, rhs: *const Self) -> bool { - libcc2rs::is_gteq(p1_operator_preferred_over_three_way_Level::operator_cmp( - lhs, rhs, - )) - } -} -impl WeaklyEqualityComparableWithUnsafe for p1_each_relation_is_an_operator_Score { - unsafe fn equal( - this: *const Self, - other: *const p1_each_relation_is_an_operator_Score, - ) -> bool { - return (((*this).points) == ((*other).points)); - } -} -impl WeaklyEqualityComparableWithUnsafe for p1_relations_from_three_way_Level { - unsafe fn equal(this: *const Self, other: *const p1_relations_from_three_way_Level) -> bool { - return (((*this).depth) == ((*other).depth)); - } -} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const greater_calls_0); std::cell::LazyCell::force(&*&raw const less_equal_calls_1); diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs index 08b66f6b78..33e2b4a99e 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs @@ -83,6 +83,99 @@ impl p1_convertible_to_Ratio { return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); } } +impl Cpp17EqualityComparable for p1_convertible_to_Ratio { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } == { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_convertible_to_Ratio { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } != { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl LessThanComparable for p1_convertible_to_Ratio { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } < { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl PartiallyOrderedWith for p1_convertible_to_Ratio { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } > { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } <= { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ({ ({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }) } >= { + ({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl ThreeWayComparable for p1_convertible_to_Ratio { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &({ p1_convertible_to_Ratio::to_i32((__lhs).clone()) }), + &({ p1_convertible_to_Ratio::to_i32((__rhs).clone()) }), + )) + } + ); +} const _: () = assert!(true, "std::convertible_to"); const _: () = assert!(!(false), "!std::convertible_to"); const _: () = assert!(true, "std::convertible_to"); diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs index 3a19952892..bccca868ad 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs @@ -73,6 +73,93 @@ impl p1_convertible_to_Ratio { return (((*this).numerator) / ((*this).denominator)); } } +impl Cpp17EqualityComparableUnsafe for p1_convertible_to_Ratio { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + == (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_convertible_to_Ratio { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + != (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl LessThanComparableUnsafe for p1_convertible_to_Ratio { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + < (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_convertible_to_Ratio { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + > (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + <= (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_convertible_to_Ratio, + |__lhs, __rhs| { + ((unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }) + >= (unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl ThreeWayComparableUnsafe for p1_convertible_to_Ratio { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__lhs)) }), + &(unsafe { p1_convertible_to_Ratio::to_i32(&raw const (*__rhs)) }), + )) + } + ); +} const _: () = assert!(true, "std::convertible_to"); const _: () = assert!(!(false), "!std::convertible_to"); const _: () = assert!(true, "std::convertible_to"); diff --git a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs index 21121f5e06..c9873f4a28 100644 --- a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs +++ b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs @@ -31,6 +31,86 @@ impl p38_insert_range_by_conversion_function_Ratio { return this.with(|__s| __s.num); } } +impl Cpp17EqualityComparable for p38_insert_range_by_conversion_function_Ratio { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } == { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl WeaklyEqualityComparableWith for p38_insert_range_by_conversion_function_Ratio { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } != { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl LessThanComparable for p38_insert_range_by_conversion_function_Ratio { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } < { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} +impl PartiallyOrderedWith for p38_insert_range_by_conversion_function_Ratio { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } > { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } <= { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ({ ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__lhs).clone()) }) } >= { + ({ p38_insert_range_by_conversion_function_Ratio::to_i32((__rhs).clone()) }) + }) + } + ); +} pub fn test_0() { let ratios: Value> = Rc::new(RefCell::new(Box::new([ @@ -46,20 +126,7 @@ pub fn test_0() { Rc::new(RefCell::new(ratios.decay())); let __last: Value> = Rc::new(RefCell::new(ratios.decay().offset((2) as isize))); - while >::not_equal( - __it.as_pointer(), - __last.as_pointer(), - ) { - let __i = temp_vec.borrow().len(); - temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - temp_vec.as_pointer().decay().offset(__i), - (LvalueRef::< - Const, - >::bind(__it.borrow().iter_deref()),), - ); - __it.borrow_mut().iter_inc(); - } + while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice( start_idx..start_idx, @@ -114,20 +181,7 @@ pub fn test_1() { Rc::new(RefCell::new(levels.decay())); let __last: Value> = Rc::new(RefCell::new(levels.decay().offset((2) as isize))); - while >::not_equal( - __it.as_pointer(), - __last.as_pointer(), - ) { - let __i = temp_vec.borrow().len(); - temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - temp_vec.as_pointer().decay().offset(__i), - (LvalueRef::< - Const, - >::bind(__it.borrow().iter_deref()),), - ); - __it.borrow_mut().iter_inc(); - } + while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } ints.as_pointer().with_mut(|v: &mut Vec| { v.splice( start_idx..start_idx, diff --git a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs index 17cd966374..570168cfef 100644 --- a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs +++ b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs @@ -28,6 +28,98 @@ impl p38_insert_range_by_conversion_function_Ratio { return (*this).num; } } +impl Cpp17EqualityComparableUnsafe for p38_insert_range_by_conversion_function_Ratio { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) == (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p38_insert_range_by_conversion_function_Ratio { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) != (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); +} +impl LessThanComparableUnsafe for p38_insert_range_by_conversion_function_Ratio { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) < (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); +} +impl PartiallyOrderedWithUnsafe for p38_insert_range_by_conversion_function_Ratio { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) > (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) <= (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p38_insert_range_by_conversion_function_Ratio, + |__lhs, __rhs| { + ((unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__lhs)) + }) >= (unsafe { + p38_insert_range_by_conversion_function_Ratio::to_i32(&raw const (*__rhs)) + })) + } + ); +} pub unsafe fn test_0() { let mut ratios: [p38_insert_range_by_conversion_function_Ratio; 2] = [ p38_insert_range_by_conversion_function_Ratio { num: 1 }, @@ -41,16 +133,7 @@ pub unsafe fn test_0() { __tmp_0.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; let mut __tmp: Vec = Vec::new(); let mut __it = ratios.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::< - Const, - >::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } + while <*mut p38_insert_range_by_conversion_function_Ratio as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe::>::bind(&__it), LvalueRefUnsafe::>::bind(&__tmp_1 ), ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } longs.splice(__off..__off, __tmp); UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr().add(__off)) }; @@ -95,16 +178,7 @@ pub unsafe fn test_1() { __tmp_2.iter_distance(&UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr())) as usize; let mut __tmp: Vec = Vec::new(); let mut __it = levels.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::< - Const, - >::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } + while <*mut p38_insert_range_best_conversion_function_Level as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe::>::bind(&__it), LvalueRefUnsafe::>::bind(&__tmp_3 ), ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } ints.splice(__off..__off, __tmp); UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr().add(__off)) }; diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index 76311ce8ab..594b6a49ac 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -45,12 +45,38 @@ impl p16_rebind_member_Alloc_std_pair_const_int__int__ { field!(this, id).write(0); } } +impl Cpp17EqualityComparable for p16_rebind_member_Alloc_std_pair_const_int__int__ { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p16_rebind_member_Alloc_std_pair_const_int__int__, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for p16_rebind_member_Alloc_std_pair_const_int__int__ { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p16_rebind_member_Alloc_std_pair_const_int__int__, + |__lhs, __rhs| { !({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } } } -pub fn test_0() { +pub fn operator_eq_0( + a: Ptr, + b: Ptr, +) -> bool { + return ({ a.with(|__s| __s.id) } == { b.with(|__s| __s.id) }); +} +pub fn test_1() { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); let n: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { @@ -89,7 +115,7 @@ pub fn test_0() { #[conversions(copy, move)] #[byte_size(1)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} -pub fn test_1() { +pub fn test_2() { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_2,) => { @@ -113,8 +139,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_0() }); ({ test_1() }); + ({ test_2() }); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 82820a63f9..4ad7ab13c8 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -40,12 +40,48 @@ impl p16_rebind_member_Alloc_std_pair_const_int__int__ { (&raw mut (*this).id).write(0); } } +impl Cpp17EqualityComparableUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p16_rebind_member_Alloc_std_pair_const_int__int__, + |__lhs, __rhs| { + (unsafe { + let _a: *const p16_rebind_member_Alloc_std_pair_const_int__int__ = __lhs; + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p16_rebind_member_Alloc_std_pair_const_int__int__, + |__lhs, __rhs| { + !(unsafe { + let _a: *const p16_rebind_member_Alloc_std_pair_const_int__int__ = __lhs; + operator_eq_0(_a, __rhs) + }) + } + ); +} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { unsafe { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } } } -pub unsafe fn test_0() { +pub unsafe fn operator_eq_0( + a: *const p16_rebind_member_Alloc_std_pair_const_int__int__, + b: *const p16_rebind_member_Alloc_std_pair_const_int__int__, +) -> bool { + return (((*a).id) == ((*b).id)); +} +pub unsafe fn test_1() { let mut m: UnsafeMap = UnsafeMap::new(); let mut n: UnsafeMap = UnsafeMap::new(); { @@ -83,7 +119,7 @@ pub unsafe fn test_0() { )] #[conversions(copy, move)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} -pub unsafe fn test_1() { +pub unsafe fn test_2() { let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_2: i32; @@ -110,8 +146,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_0() }); (unsafe { test_1() }); + (unsafe { test_2() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs index b59ba33b07..7193cb942c 100644 --- a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs @@ -6,8 +6,381 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct table28_equal_operator_Ticket { + #[offset(0)] + pub number: i32, +} +impl table28_equal_operator_Ticket { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.number) } == { other.with(|__s| __s.number) }); + } +} +impl Cpp17EqualityComparable for table28_equal_operator_Ticket { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + table28_equal_operator_Ticket, + |__lhs, __rhs| { + ({ table28_equal_operator_Ticket::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for table28_equal_operator_Ticket { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + table28_equal_operator_Ticket, + |__lhs, __rhs| { + !({ table28_equal_operator_Ticket::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +pub fn test_0() { + let tickets: Value> = Rc::new(RefCell::new(Vec::from([ + table28_equal_operator_Ticket { number: 4 }, + table28_equal_operator_Ticket { number: 4 }, + table28_equal_operator_Ticket { number: 7 }, + table28_equal_operator_Ticket { number: 9 }, + table28_equal_operator_Ticket { number: 9 }, + ]))); + assert!(( ({ let __tmp_0 : Value = Rc::new(RefCell::new(table28_equal_operator_Ticket { number : 7 , } )); {let __it: Value > = Rc::new(RefCell::new(tickets .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(tickets .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind((__tmp_0.as_pointer()).clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) .iter_deref() .with(|__s| __s . number ) == 7 ) ); + assert!(match (Rc::new(RefCell::new(({ let __tmp_2 : Value = Rc::new(RefCell::new(table28_equal_operator_Ticket { number : 5 , } )); {let __it: Value > = Rc::new(RefCell::new(tickets .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(tickets .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind((__tmp_2.as_pointer()).clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) )).as_pointer(), Rc::new(RefCell::new(tickets .decay() .end() )).as_pointer(),) { (__tmp_1, __tmp_3,) => { Cpp17EqualityComparable::is_equal( LvalueRef:: >>::bind((__tmp_1 ).clone()), LvalueRef:: >>::bind((__tmp_3 ).clone()), ) } } ); + let last: Value> = Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(tickets.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(tickets.decay().end())); + if as Cpp17EqualityComparable>::is_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { __last.borrow().clone() } else { let mut __write = __it.borrow().clone(); __it.borrow_mut().iter_inc(); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { if !::is_equal( LvalueRef::>::bind(__write.iter_deref()), LvalueRef::>::bind(__it.borrow().iter_deref()), ) { __write.iter_inc(); __write.iter_deref().write(__it.borrow().iter_deref().read()); } __it.borrow_mut().iter_inc(); } __write.iter_inc(); __write } + })); + assert!( + (({ { (*tickets.borrow())[0_usize] }.number } == 4) + && ({ { (*tickets.borrow())[1_usize] }.number } == 7)) + && ({ { (*tickets.borrow())[2_usize] }.number } == 9) + ); + { + (*last.borrow_mut()).iter_inc(); + }; + assert!(WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind( + last.as_pointer() + ), + LvalueRef::>>::bind( + Rc::new(RefCell::new(tickets.decay().end())).as_pointer() + ), + )); + { + (*last.borrow_mut()).iter_inc(); + }; + assert!( + match (Rc::new(RefCell::new(tickets.decay().end())).as_pointer(),) { + (__tmp_4,) => { + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind( + last.as_pointer(), + ), + LvalueRef::>>::bind( + (__tmp_4).clone(), + ), + ) + } + } + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRef>, bool )] +#[byte_size(1)] +pub struct table28_result_convertible_to_bool_Truth { + #[offset(0)] + pub value: bool, +} +impl table28_result_convertible_to_bool_Truth { + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} +impl Cpp17EqualityComparable for table28_result_convertible_to_bool_Truth { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + == { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl WeaklyEqualityComparableWith for table28_result_convertible_to_bool_Truth { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + != { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl LessThanComparable for table28_result_convertible_to_bool_Truth { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + < { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl PartiallyOrderedWith for table28_result_convertible_to_bool_Truth { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + > { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + <= { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + >= { + (({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl ThreeWayComparable for table28_result_convertible_to_bool_Truth { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(({ table28_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32), + &(({ table28_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) as i32), + )) + } + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct table28_result_convertible_to_bool_Ticket { + #[offset(0)] + pub number: i32, +} +impl table28_result_convertible_to_bool_Ticket { + pub fn operator_eq( + this: Ptr, + other: Ptr, + ) -> table28_result_convertible_to_bool_Truth { + return table28_result_convertible_to_bool_Truth { + value: ({ this.with(|__s| __s.number) } == { other.with(|__s| __s.number) }), + }; + } +} +impl Cpp17EqualityComparable for table28_result_convertible_to_bool_Ticket { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = table28_result_convertible_to_bool_Truth, + table28_result_convertible_to_bool_Ticket, + |__return, __lhs, __rhs| { + __return.write( + ({ + table28_result_convertible_to_bool_Ticket::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ); + }, + |__lhs, __rhs| { + ({ + table28_result_convertible_to_bool_Truth::to_bool( + Rc::new(RefCell::new( + ({ + table28_result_convertible_to_bool_Ticket::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + )) + .as_pointer(), + ) + }) + } + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct table28_result_convertible_to_bool_Badge { + #[offset(0)] + pub id: i32, +} +impl table28_result_convertible_to_bool_Badge { + pub fn operator_eq( + this: Ptr, + other: Ptr, + ) -> table28_result_convertible_to_bool_Truth { + return table28_result_convertible_to_bool_Truth { + value: ({ this.with(|__s| __s.id) } == { (other.read()) }), + }; + } +} +impl Cpp17EqualityComparable for table28_result_convertible_to_bool_Badge { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = table28_result_convertible_to_bool_Truth, + i32, + |__return, __lhs, __rhs| { + __return.write( + ({ + table28_result_convertible_to_bool_Badge::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ); + }, + |__lhs, __rhs| { + ({ + table28_result_convertible_to_bool_Truth::to_bool( + Rc::new(RefCell::new( + ({ + table28_result_convertible_to_bool_Badge::operator_eq( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + )) + .as_pointer(), + ) + }) + } + ); +} +pub fn test_1() { + let tickets: Value> = + Rc::new(RefCell::new(Vec::from([ + table28_result_convertible_to_bool_Ticket { number: 4 }, + table28_result_convertible_to_bool_Ticket { number: 7 }, + table28_result_convertible_to_bool_Ticket { number: 9 }, + ]))); + assert!(( ({ let __tmp_5 : Value = Rc::new(RefCell::new(table28_result_convertible_to_bool_Ticket { number : 9 , } )); {let __it: Value > = Rc::new(RefCell::new(tickets .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(tickets .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind((__tmp_5.as_pointer()).clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) .iter_deref() .with(|__s| __s . number ) == 9 ) ); + assert!(match (Rc::new(RefCell::new(({ let __tmp_7 : Value = Rc::new(RefCell::new(table28_result_convertible_to_bool_Ticket { number : 5 , } )); {let __it: Value > = Rc::new(RefCell::new(tickets .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(tickets .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind((__tmp_7.as_pointer()).clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) )).as_pointer(), Rc::new(RefCell::new(tickets .decay() .end() )).as_pointer(),) { (__tmp_6, __tmp_8,) => { Cpp17EqualityComparable::is_equal( LvalueRef:: >>::bind((__tmp_6 ).clone()), LvalueRef:: >>::bind((__tmp_8 ).clone()), ) } } ); + let badges: Value> = + Rc::new(RefCell::new(Vec::from([ + table28_result_convertible_to_bool_Badge { id: 1 }, + table28_result_convertible_to_bool_Badge { id: 2 }, + table28_result_convertible_to_bool_Badge { id: 3 }, + ]))); + assert!(( ({ let __tmp_9 : Value = Rc::new(RefCell::new(2 )); {let __it: Value > = Rc::new(RefCell::new(badges .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(badges .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind(__tmp_9.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) .iter_deref() .with(|__s| __s . id ) == 2 ) ); + assert!(match (Rc::new(RefCell::new(({ let __tmp_11 : Value = Rc::new(RefCell::new(8 )); {let __it: Value > = Rc::new(RefCell::new(badges .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(badges .decay() .end() )); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind(__tmp_11.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone()} }) )).as_pointer(), Rc::new(RefCell::new(badges .decay() .end() )).as_pointer(),) { (__tmp_10, __tmp_12,) => { Cpp17EqualityComparable::is_equal( LvalueRef:: >>::bind((__tmp_10 ).clone()), LvalueRef:: >>::bind((__tmp_12 ).clone()), ) } } ); +} thread_local!( - pub static less_calls_0: Value = Rc::new(RefCell::new(0)); + pub static less_calls_2: Value = Rc::new(RefCell::new(0)); ); #[derive( Copy, @@ -30,15 +403,27 @@ pub struct table29_member_operator_Version { #[offset(4)] pub minor: i32, } -impl LessThanComparable for table29_member_operator_Version { - fn less(this: Ptr, other: Ptr) -> bool { - (*less_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); +impl table29_member_operator_Version { + pub fn operator_lt(this: Ptr, other: Ptr) -> bool { + (*less_calls_2.with(Value::clone).borrow_mut()).prefix_inc(); return ({ this.with(|__s| __s.major) } < { other.with(|__s| __s.major) }) || (({ this.with(|__s| __s.major) } == { other.with(|__s| __s.major) }) && ({ this.with(|__s| __s.minor) } < { other.with(|__s| __s.minor) })); } } -pub fn test_1() { +impl LessThanComparable for table29_member_operator_Version { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_member_operator_Version, + |__lhs, __rhs| { + ({ table29_member_operator_Version::operator_lt((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +pub fn test_3() { let old_version: Value = Rc::new(RefCell::new(table29_member_operator_Version { major: 1, @@ -50,9 +435,13 @@ pub fn test_1() { minor: 0, })); assert!( - (if LessThanComparable::less( - old_version.as_pointer().clone(), - new_version.as_pointer().clone() + (if ::is_less( + LvalueRef::>::bind( + old_version.as_pointer().clone() + ), + LvalueRef::>::bind( + new_version.as_pointer().clone() + ), ) { new_version.as_pointer() } else { @@ -62,9 +451,13 @@ pub fn test_1() { == 2) ); assert!( - (if LessThanComparable::less( - new_version.as_pointer().clone(), - old_version.as_pointer().clone() + (if ::is_less( + LvalueRef::>::bind( + new_version.as_pointer().clone() + ), + LvalueRef::>::bind( + old_version.as_pointer().clone() + ), ) { new_version.as_pointer() } else { @@ -73,18 +466,18 @@ pub fn test_1() { .with(|__s| __s.major) == 1) ); - assert!((less_calls_0.with(|rc| *rc.borrow()) == 2)); + assert!((less_calls_2.with(|rc| *rc.borrow()) == 2)); let versions: Value> = Rc::new(RefCell::new(Vec::from([ table29_member_operator_Version { major: 2, minor: 1 }, table29_member_operator_Version { major: 1, minor: 9 }, table29_member_operator_Version { major: 2, minor: 0 }, ]))); { - let mut __tmp_0 = { versions.decay().begin() }; - let __n = versions.decay().end().iter_distance(&__tmp_0); + let mut __tmp_13 = { versions.decay().begin() }; + let __n = versions.decay().end().iter_distance(&__tmp_13); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_0.iter_at(__x), &__tmp_0.iter_at(__y))); - reorder(__order, |__i| __tmp_0.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_13.iter_at(__x), &__tmp_13.iter_at(__y))); + reorder(__order, |__i| __tmp_13.iter_at(__i)); }; assert!( ({ { (*versions.borrow())[0_usize] }.major } == 1) @@ -98,48 +491,21 @@ pub fn test_1() { ({ { (*versions.borrow())[2_usize] }.major } == 2) && ({ { (*versions.borrow())[2_usize] }.minor } == 1) ); - assert!( - ({ - let __it: Value> = - Rc::new(RefCell::new(versions.decay().begin())); - let __last: Value> = - Rc::new(RefCell::new(versions.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 LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { - __best = __it.borrow().clone(); - } - __it.borrow_mut().iter_inc(); - } - } - __best - } - .iter_deref() - .with(|__s| __s.minor) - == 1) - ); + assert!(( {let __it: Value > = Rc::new(RefCell::new(versions .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(versions .decay() .end() )); let mut __best = __it.borrow().clone(); if as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { __it.borrow_mut().iter_inc(); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { if ::is_less( LvalueRef::>::bind(__best.iter_deref()), LvalueRef::>::bind(__it.borrow().iter_deref()), ) { __best = __it.borrow().clone(); } __it.borrow_mut().iter_inc(); } } __best} .iter_deref() .with(|__s| __s . minor ) == 1 ) ); let downloads: Value< Map, Value)>, > = Rc::new(RefCell::new(Map::new())); match (new_version.as_pointer(),) { - (__tmp_1,) => ({ (*downloads.borrow_mut()).subscript(__tmp_1, || 0_i32) }), + (__tmp_14,) => ({ (*downloads.borrow_mut()).subscript(__tmp_14, || 0_i32) }), } .write(7); match (old_version.as_pointer(),) { - (__tmp_2,) => ({ (*downloads.borrow_mut()).subscript(__tmp_2, || 0_i32) }), + (__tmp_15,) => ({ (*downloads.borrow_mut()).subscript(__tmp_15, || 0_i32) }), } .write(3); { match (new_version.as_pointer(),) { - (__tmp_3,) => ({ (*downloads.borrow_mut()).subscript(__tmp_3, || 0_i32) }), + (__tmp_16,) => ({ (*downloads.borrow_mut()).subscript(__tmp_16, || 0_i32) }), } .with_mut(|__v| *__v = *__v + 1) }; @@ -162,8 +528,8 @@ pub fn test_1() { ); assert!( ((match (new_version.as_pointer(),) { - (__tmp_4,) => { - ({ (*downloads.borrow_mut()).subscript(__tmp_4, || 0_i32) }) + (__tmp_17,) => { + ({ (*downloads.borrow_mut()).subscript(__tmp_17, || 0_i32) }) } } .read()) @@ -195,9 +561,20 @@ impl table29_other_operator_shapes_Weight { } } impl LessThanComparable for table29_other_operator_shapes_Weight { - fn less(this: Ptr, other: Ptr) -> bool { - table29_other_operator_shapes_Weight::operator_lt(this.clone(), other.read()) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Weight, + |__lhs, __rhs| { + ({ + table29_other_operator_shapes_Weight::operator_lt((__lhs).clone(), { + (*__rhs.upgrade().deref()) + }) + }) + } + ); } #[derive( Copy, @@ -219,12 +596,20 @@ pub struct table29_other_operator_shapes_Height { pub millimeters: i32, } impl LessThanComparable for table29_other_operator_shapes_Height { - fn less( - lhs: Ptr, - rhs: Ptr, - ) -> bool { - return ({ lhs.with(|__s| __s.millimeters) } < { rhs.with(|__s| __s.millimeters) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Height, + |__lhs, __rhs| { ({ operator_lt_4((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_lt_4( + lhs: Ptr, + rhs: Ptr, +) -> bool { + return ({ lhs.with(|__s| __s.millimeters) } < { rhs.with(|__s| __s.millimeters) }); } #[derive( Copy, @@ -237,10 +622,8 @@ impl LessThanComparable for table29_other_operator_shapes_Height { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(table29_other_operator_shapes_Depth::operator_cmp)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Depth { @@ -259,77 +642,593 @@ impl table29_other_operator_shapes_Depth { } } impl LessThanComparable for table29_other_operator_shapes_Depth { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(table29_other_operator_shapes_Depth::operator_cmp( - this.clone(), - other.clone(), - )) + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + table29_other_operator_shapes_Depth::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for table29_other_operator_shapes_Depth { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + table29_other_operator_shapes_Depth::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + table29_other_operator_shapes_Depth::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + table29_other_operator_shapes_Depth::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct table29_other_operator_shapes_Length { + #[offset(0)] + pub meters: i32, +} +impl table29_other_operator_shapes_Length { + pub fn operator_cmp( + this: Ptr, + _a0: Ptr, + ) -> libcc2rs::StrongOrdering { + { + let cmp: Value = Rc::new(RefCell::new( + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(this.with(|__s| __s.meters)), + &(_a0.with(|__s| __s.meters)), + )), + )); + if !(libcc2rs::is_eq(({ (*cmp.borrow()) }))) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.meters) } == { _a0.with(|__s| __s.meters) }); } } -pub fn test_2() { +impl Cpp17EqualityComparable for table29_other_operator_shapes_Length { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + ({ + table29_other_operator_shapes_Length::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl WeaklyEqualityComparableWith for table29_other_operator_shapes_Length { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + !({ + table29_other_operator_shapes_Length::operator_eq((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +impl LessThanComparable for table29_other_operator_shapes_Length { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + table29_other_operator_shapes_Length::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for table29_other_operator_shapes_Length { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + table29_other_operator_shapes_Length::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + table29_other_operator_shapes_Length::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + table29_other_operator_shapes_Length::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl ThreeWayComparable for table29_other_operator_shapes_Length { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + ({ + table29_other_operator_shapes_Length::operator_cmp((__lhs).clone(), (__rhs).clone()) + }) + } + ); +} +pub fn test_5() { assert!( ({ - let __tmp_5: Value = + let __tmp_18: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Weight { grams: 3, })); - let __tmp_6: Value = + let __tmp_19: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Weight { grams: 5, })); - if LessThanComparable::less( - (__tmp_5.as_pointer()).clone(), - (__tmp_6.as_pointer()).clone(), + if ::is_less( + LvalueRef::>::bind( + (__tmp_18.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_19.as_pointer()).clone(), + ), ) { - (__tmp_6.as_pointer()) + (__tmp_19.as_pointer()) } else { - (__tmp_5.as_pointer()) + (__tmp_18.as_pointer()) } .with(|__s| __s.grams) } == 5) ); assert!( ({ - let __tmp_7: Value = + let __tmp_20: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Height { millimeters: 50, })); - let __tmp_8: Value = + let __tmp_21: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Height { millimeters: 30, })); - if LessThanComparable::less( - (__tmp_7.as_pointer()).clone(), - (__tmp_8.as_pointer()).clone(), + if ::is_less( + LvalueRef::>::bind( + (__tmp_20.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_21.as_pointer()).clone(), + ), ) { - (__tmp_7.as_pointer()) + (__tmp_20.as_pointer()) } else { - (__tmp_8.as_pointer()) + (__tmp_21.as_pointer()) } .with(|__s| __s.millimeters) } == 30) ); assert!( ({ - let __tmp_9: Value = + let __tmp_22: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Depth { millimeters: 7, })); - let __tmp_10: Value = + let __tmp_23: Value = Rc::new(RefCell::new(table29_other_operator_shapes_Depth { millimeters: 4, })); - if LessThanComparable::less( - (__tmp_9.as_pointer()).clone(), - (__tmp_10.as_pointer()).clone(), + if ::is_less( + LvalueRef::>::bind( + (__tmp_22.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_23.as_pointer()).clone(), + ), ) { - (__tmp_10.as_pointer()) + (__tmp_23.as_pointer()) } else { - (__tmp_9.as_pointer()) + (__tmp_22.as_pointer()) } .with(|__s| __s.millimeters) } == 7) ); + assert!( + ({ + let __tmp_24: Value = + Rc::new(RefCell::new(table29_other_operator_shapes_Length { + meters: 9, + })); + let __tmp_25: Value = + Rc::new(RefCell::new(table29_other_operator_shapes_Length { + meters: 2, + })); + if ::is_less( + LvalueRef::>::bind( + (__tmp_24.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_25.as_pointer()).clone(), + ), + ) { + (__tmp_24.as_pointer()) + } else { + (__tmp_25.as_pointer()) + } + .with(|__s| __s.meters) + } == 2) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRef>, bool )] +#[byte_size(1)] +pub struct table29_result_convertible_to_bool_Truth { + #[offset(0)] + pub value: bool, +} +impl table29_result_convertible_to_bool_Truth { + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} +impl Cpp17EqualityComparable for table29_result_convertible_to_bool_Truth { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + == { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl WeaklyEqualityComparableWith for table29_result_convertible_to_bool_Truth { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + != { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl LessThanComparable for table29_result_convertible_to_bool_Truth { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + < { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl PartiallyOrderedWith for table29_result_convertible_to_bool_Truth { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + > { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + <= { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + ({ (({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32) } + >= { + (({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) + as i32) + }) + } + ); +} +impl ThreeWayComparable for table29_result_convertible_to_bool_Truth { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(({ table29_result_convertible_to_bool_Truth::to_bool((__lhs).clone()) }) as i32), + &(({ table29_result_convertible_to_bool_Truth::to_bool((__rhs).clone()) }) as i32), + )) + } + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct table29_result_convertible_to_bool_Priority { + #[offset(0)] + pub level: i32, +} +impl table29_result_convertible_to_bool_Priority { + pub fn operator_lt( + this: Ptr, + other: Ptr, + ) -> table29_result_convertible_to_bool_Truth { + return table29_result_convertible_to_bool_Truth { + value: ({ this.with(|__s| __s.level) } < { other.with(|__s| __s.level) }), + }; + } +} +impl LessThanComparable for table29_result_convertible_to_bool_Priority { + comparison!( + LessThanComparable, + less, + is_less, + Result = table29_result_convertible_to_bool_Truth, + table29_result_convertible_to_bool_Priority, + |__return, __lhs, __rhs| { + __return.write( + ({ + table29_result_convertible_to_bool_Priority::operator_lt( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ); + }, + |__lhs, __rhs| { + ({ + table29_result_convertible_to_bool_Truth::to_bool( + Rc::new(RefCell::new( + ({ + table29_result_convertible_to_bool_Priority::operator_lt( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + )) + .as_pointer(), + ) + }) + } + ); +} +pub fn test_6() { + assert!( + ({ + let __tmp_26: Value = + Rc::new(RefCell::new(table29_result_convertible_to_bool_Priority { + level: 2, + })); + let __tmp_27: Value = + Rc::new(RefCell::new(table29_result_convertible_to_bool_Priority { + level: 6, + })); + if ::is_less( + LvalueRef::>::bind( + (__tmp_26.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_27.as_pointer()).clone(), + ), + ) { + (__tmp_27.as_pointer()) + } else { + (__tmp_26.as_pointer()) + } + .with(|__s| __s.level) + } == 6) + ); + assert!( + ({ + let __tmp_28: Value = + Rc::new(RefCell::new(table29_result_convertible_to_bool_Priority { + level: 6, + })); + let __tmp_29: Value = + Rc::new(RefCell::new(table29_result_convertible_to_bool_Priority { + level: 2, + })); + if ::is_less( + LvalueRef::>::bind( + (__tmp_28.as_pointer()).clone(), + ), + LvalueRef::>::bind( + (__tmp_29.as_pointer()).clone(), + ), + ) { + (__tmp_28.as_pointer()) + } else { + (__tmp_29.as_pointer()) + } + .with(|__s| __s.level) + } == 2) + ); + let priorities: Value> = + Rc::new(RefCell::new(Vec::from([ + table29_result_convertible_to_bool_Priority { level: 5 }, + table29_result_convertible_to_bool_Priority { level: 1 }, + table29_result_convertible_to_bool_Priority { level: 3 }, + ]))); + { + let mut __tmp_30 = { priorities.decay().begin() }; + let __n = priorities.decay().end().iter_distance(&__tmp_30); + let mut __order: Vec = (0..__n).collect(); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_30.iter_at(__x), &__tmp_30.iter_at(__y))); + reorder(__order, |__i| __tmp_30.iter_at(__i)); + }; + assert!(({ { (*priorities.borrow())[0_usize] }.level } == 1)); + assert!(({ { (*priorities.borrow())[1_usize] }.level } == 3)); + assert!(({ { (*priorities.borrow())[2_usize] }.level } == 5)); + assert!(( {let __it: Value > = Rc::new(RefCell::new(priorities .decay() .begin() )); let __last: Value > = Rc::new(RefCell::new(priorities .decay() .end() )); let mut __best = __it.borrow().clone(); if as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { __it.borrow_mut().iter_inc(); while as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) { if ::is_less( LvalueRef::>::bind(__best.iter_deref()), LvalueRef::>::bind(__it.borrow().iter_deref()), ) { __best = __it.borrow().clone(); } __it.borrow_mut().iter_inc(); } } __best} .iter_deref() .with(|__s| __s . level ) == 5 ) ); } #[derive( Copy, @@ -350,12 +1249,32 @@ pub struct pairs_spec_p3_members_order_pairs_Rank { #[offset(0)] pub value: i32, } -impl LessThanComparable for pairs_spec_p3_members_order_pairs_Rank { - fn less(this: Ptr, other: Ptr) -> bool { +impl pairs_spec_p3_members_order_pairs_Rank { + pub fn operator_lt( + this: Ptr, + other: Ptr, + ) -> bool { return ({ this.with(|__s| __s.value) } < { other.with(|__s| __s.value) }); } } -pub fn test_3() { +impl LessThanComparable for pairs_spec_p3_members_order_pairs_Rank { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + pairs_spec_p3_members_order_pairs_Rank, + |__lhs, __rhs| { + ({ + pairs_spec_p3_members_order_pairs_Rank::operator_lt( + (__lhs).clone(), + (__rhs).clone(), + ) + }) + } + ); +} +pub fn test_7() { let low: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new( @@ -377,30 +1296,15 @@ pub fn test_3() { )), Rc::new(RefCell::new(5)), ))); - assert!(LessThanComparable::less( - low.as_pointer(), - high.as_pointer() - )); - assert!(LessThanComparable::less( - high.as_pointer(), - high_later.as_pointer() - )); - assert!(LessThanComparable::less( - low.as_pointer(), - high_later.as_pointer() - )); - assert!(!LessThanComparable::less( - high.as_pointer(), - low.as_pointer() - )); - assert!(!LessThanComparable::less( - high_later.as_pointer(), - high.as_pointer() - )); - assert!(!(LessThanComparable::less(high.as_pointer(), low.as_pointer()))); + assert!(<(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(low .as_pointer() ), LvalueRef::, Value)>>::bind(high .as_pointer() ), ) ); + assert!(<(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(high .as_pointer() ), LvalueRef::, Value)>>::bind(high_later .as_pointer() ), ) ); + assert!(<(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(low .as_pointer() ), LvalueRef::, Value)>>::bind(high_later .as_pointer() ), ) ); + assert!(!<(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(high .as_pointer() ), LvalueRef::, Value)>>::bind(low .as_pointer() ), ) ); + assert!(!<(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(high_later .as_pointer() ), LvalueRef::, Value)>>::bind(high .as_pointer() ), ) ); + assert!(! ( ( <(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value)>>::bind(high .as_pointer() ), LvalueRef::, Value)>>::bind(low .as_pointer() ), ) ) ) ); assert!( ({ - ( (*(*if LessThanComparable::less(low .as_pointer() .clone(), high .as_pointer() .clone()) { high .as_pointer() } else { low .as_pointer() } .upgrade().deref()) .1.borrow()) == 0 ) + ( (*(*if <(Value, Value) as LessThanComparable>::is_less( LvalueRef::, Value) >>::bind(low .as_pointer() .clone()), LvalueRef::, Value) >>::bind(high .as_pointer() .clone()), ) { high .as_pointer() } else { low .as_pointer() } .upgrade().deref()) .1.borrow()) == 0 ) }) ); } @@ -409,11 +1313,14 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { + ({ test_0() }); ({ test_1() }); - ({ test_2() }); ({ test_3() }); + ({ test_5() }); + ({ test_6() }); + ({ test_7() }); return 0; } pub fn __cpp2rust_init_globals() { - let _ = less_calls_0.with(|_| ()); + let _ = less_calls_2.with(|_| ()); } diff --git a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs index e20798e882..54392adba2 100644 --- a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs @@ -6,7 +6,397 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut less_calls_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct table28_equal_operator_Ticket { + pub number: i32, +} +impl table28_equal_operator_Ticket { + pub unsafe fn operator_eq( + this: *const Self, + other: *const table28_equal_operator_Ticket, + ) -> bool { + return (((*this).number) == ((*other).number)); + } +} +impl Cpp17EqualityComparableUnsafe for table28_equal_operator_Ticket { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + table28_equal_operator_Ticket, + |__lhs, __rhs| { + (unsafe { table28_equal_operator_Ticket::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for table28_equal_operator_Ticket { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + table28_equal_operator_Ticket, + |__lhs, __rhs| { + !(unsafe { table28_equal_operator_Ticket::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +pub unsafe fn test_0() { + let mut tickets: Vec = Vec::from([ + table28_equal_operator_Ticket { number: 4 }, + table28_equal_operator_Ticket { number: 4 }, + table28_equal_operator_Ticket { number: 7 }, + table28_equal_operator_Ticket { number: 9 }, + table28_equal_operator_Ticket { number: 9 }, + ]); + assert!(( ( ( * { let mut __tmp_0 = { tickets .begin() };let mut __tmp_1 = { tickets .end() }; let mut __it = (__tmp_0 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_1 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&(table28_equal_operator_Ticket { number : 7 , } )), ) { __it.iter_inc(); } __it } .iter_deref() ) . number ) == ( 7 ) ) ); + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &{ + let mut __tmp_2 = { tickets.begin() }; + let mut __tmp_3 = { tickets.end() }; + let mut __it = (__tmp_2).clone(); + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_3 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&(table28_equal_operator_Ticket { number : 5 , } )), ) { __it.iter_inc(); } + __it + } + ), + LvalueRefUnsafe::>>::bind( + &tickets.end() + ), + )); + let mut last: UnsafeRandomAccessIterator = { + let mut __tmp_4 = { tickets.begin() }; + let mut __tmp_5 = { tickets.end() }; + if as Cpp17EqualityComparableUnsafe>::is_equal( LvalueRefUnsafe:: >>::bind(&__tmp_4 ), LvalueRefUnsafe:: >>::bind(&__tmp_5 ), ) { (__tmp_5 ).clone() } else { let mut __write = __tmp_4 .clone(); let mut __it = (__tmp_4 ).clone(); __it.iter_inc(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_5 ), ) { if !::is_equal( LvalueRefUnsafe::>::bind(__write.iter_deref()), LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); } __it.iter_inc(); } __write.iter_inc(); __write } + }; + assert!( + (((tickets[(0_usize)].number) == (4)) && ((tickets[(1_usize)].number) == (7))) + && ((tickets[(2_usize)].number) == (9)) + ); + { + last.iter_inc(); + }; + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind( + &last + ), + LvalueRefUnsafe::>>::bind( + &tickets.end() + ), + )); + { + last.iter_inc(); + }; + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &last + ), + LvalueRefUnsafe::>>::bind( + &tickets.end() + ), + )); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] +pub struct table28_result_convertible_to_bool_Truth { + pub value: bool, +} +impl table28_result_convertible_to_bool_Truth { + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; + } +} +impl Cpp17EqualityComparableUnsafe for table28_result_convertible_to_bool_Truth { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + == ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for table28_result_convertible_to_bool_Truth { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + != ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl LessThanComparableUnsafe for table28_result_convertible_to_bool_Truth { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + < ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl PartiallyOrderedWithUnsafe for table28_result_convertible_to_bool_Truth { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + > ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + <= ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table28_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + >= ((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl ThreeWayComparableUnsafe for table28_result_convertible_to_bool_Truth { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) + }) as i32), + &((unsafe { + table28_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32), + )) + } + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct table28_result_convertible_to_bool_Ticket { + pub number: i32, +} +impl table28_result_convertible_to_bool_Ticket { + pub unsafe fn operator_eq( + this: *const Self, + other: *const table28_result_convertible_to_bool_Ticket, + ) -> table28_result_convertible_to_bool_Truth { + return table28_result_convertible_to_bool_Truth { + value: (((*this).number) == ((*other).number)), + }; + } +} +impl Cpp17EqualityComparableUnsafe for table28_result_convertible_to_bool_Ticket { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = table28_result_convertible_to_bool_Truth, + table28_result_convertible_to_bool_Ticket, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + table28_result_convertible_to_bool_Ticket::operator_eq( + &raw const (*__lhs), + __rhs, + ) + }), + ); + }, + |__lhs, __rhs| { + (unsafe { + table28_result_convertible_to_bool_Truth::to_bool( + &(unsafe { + table28_result_convertible_to_bool_Ticket::operator_eq( + &raw const (*__lhs), + __rhs, + ) + }), + ) + }) + } + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct table28_result_convertible_to_bool_Badge { + pub id: i32, +} +impl table28_result_convertible_to_bool_Badge { + pub unsafe fn operator_eq( + this: *const Self, + other: *const i32, + ) -> table28_result_convertible_to_bool_Truth { + return table28_result_convertible_to_bool_Truth { + value: (((*this).id) == (*other)), + }; + } +} +impl Cpp17EqualityComparableUnsafe for table28_result_convertible_to_bool_Badge { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = table28_result_convertible_to_bool_Truth, + i32, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + table28_result_convertible_to_bool_Badge::operator_eq( + &raw const (*__lhs), + __rhs, + ) + }), + ); + }, + |__lhs, __rhs| { + (unsafe { + table28_result_convertible_to_bool_Truth::to_bool( + &(unsafe { + table28_result_convertible_to_bool_Badge::operator_eq( + &raw const (*__lhs), + __rhs, + ) + }), + ) + }) + } + ); +} +pub unsafe fn test_1() { + let mut tickets: Vec = Vec::from([ + table28_result_convertible_to_bool_Ticket { number: 4 }, + table28_result_convertible_to_bool_Ticket { number: 7 }, + table28_result_convertible_to_bool_Ticket { number: 9 }, + ]); + assert!(( ( ( * { let mut __tmp_6 = { tickets .begin() };let mut __tmp_7 = { tickets .end() }; let mut __it = (__tmp_6 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_7 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&(table28_result_convertible_to_bool_Ticket { number : 9 , } )), ) { __it.iter_inc(); } __it } .iter_deref() ) . number ) == ( 9 ) ) ); + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::< + Const>, + >::bind(&{ + let mut __tmp_8 = { tickets.begin() }; + let mut __tmp_9 = { tickets.end() }; + let mut __it = (__tmp_8).clone(); + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_9 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&(table28_result_convertible_to_bool_Ticket { number : 5 , } )), ) { __it.iter_inc(); } + __it + }), + LvalueRefUnsafe::< + Const>, + >::bind(&tickets.end()), + )); + let mut badges: Vec = Vec::from([ + table28_result_convertible_to_bool_Badge { id: 1 }, + table28_result_convertible_to_bool_Badge { id: 2 }, + table28_result_convertible_to_bool_Badge { id: 3 }, + ]); + assert!(( ( ( * { let mut __tmp_10 = { badges .begin() };let mut __tmp_11 = { badges .end() }; let mut __it = (__tmp_10 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_11 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&2 ), ) { __it.iter_inc(); } __it } .iter_deref() ) . id ) == ( 2 ) ) ); + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::< + Const>, + >::bind(&{ + let mut __tmp_12 = { badges.begin() }; + let mut __tmp_13 = { badges.end() }; + let mut __it = (__tmp_12).clone(); + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_13 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&8 ), ) { __it.iter_inc(); } + __it + }), + LvalueRefUnsafe::< + Const>, + >::bind(&badges.end()), + )); +} +pub static mut less_calls_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( Copy, @@ -24,14 +414,29 @@ pub struct table29_member_operator_Version { pub major: i32, pub minor: i32, } -impl LessThanComparableUnsafe for table29_member_operator_Version { - unsafe fn less(this: *const Self, other: *const table29_member_operator_Version) -> bool { - (*std::cell::LazyCell::force_mut(&mut *&raw mut less_calls_0)).prefix_inc(); +impl table29_member_operator_Version { + pub unsafe fn operator_lt( + this: *const Self, + other: *const table29_member_operator_Version, + ) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut less_calls_2)).prefix_inc(); return (((*this).major) < ((*other).major)) || ((((*this).major) == ((*other).major)) && (((*this).minor) < ((*other).minor))); } } -pub unsafe fn test_1() { +impl LessThanComparableUnsafe for table29_member_operator_Version { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_member_operator_Version, + |__lhs, __rhs| { + (unsafe { table29_member_operator_Version::operator_lt(&raw const (*__lhs), __rhs) }) + } + ); +} +pub unsafe fn test_3() { let mut old_version: table29_member_operator_Version = table29_member_operator_Version { major: 1, minor: 4 }; let mut new_version: table29_member_operator_Version = @@ -40,7 +445,10 @@ pub unsafe fn test_1() { (((*{ let __a: *const _ = &mut old_version; let __b: *const _ = &mut new_version; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -53,7 +461,10 @@ pub unsafe fn test_1() { (((*{ let __a: *const _ = &mut old_version; let __b: *const _ = &mut new_version; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -62,22 +473,28 @@ pub unsafe fn test_1() { .major) == (1)) ); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut less_calls_0)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut less_calls_2)) == (2))); let mut versions: Vec = Vec::from([ table29_member_operator_Version { major: 2, minor: 1 }, table29_member_operator_Version { major: 1, minor: 9 }, table29_member_operator_Version { major: 2, minor: 0 }, ]); { - let mut __tmp_0 = { versions.begin() }; - let __n = versions.end().iter_distance(&__tmp_0); + let mut __tmp_14 = { versions.begin() }; + let __n = versions.end().iter_distance(&__tmp_14); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_14.iter_at(__x) as *const table29_member_operator_Version; + let __b = __tmp_14.iter_at(__y) as *const table29_member_operator_Version; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -85,39 +502,16 @@ pub unsafe fn test_1() { }); let __values: Vec<_> = __order .iter() - .map(|&__i| std::ptr::read(__tmp_0.iter_at(__i))) + .map(|&__i| std::ptr::read(__tmp_14.iter_at(__i))) .collect(); for (__i, __v) in (0..__n).zip(__values) { - std::ptr::write(__tmp_0.iter_at(__i), __v); + std::ptr::write(__tmp_14.iter_at(__i), __v); } }; assert!(((versions[(0_usize)].major) == (1)) && ((versions[(0_usize)].minor) == (9))); assert!(((versions[(1_usize)].major) == (2)) && ((versions[(1_usize)].minor) == (0))); assert!(((versions[(2_usize)].major) == (2)) && ((versions[(2_usize)].minor) == (1))); - assert!( - (((*{ - let mut __tmp_1 = { versions.begin() }; - let mut __tmp_2 = { versions.end() }; - let mut __best = __tmp_1.clone(); - if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_1, &__tmp_2) { - let mut __it = (__tmp_1).clone(); - __it.iter_inc(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { - if LessThanComparableUnsafe::less( - __best.iter_deref() as *const _, - __it.iter_deref() as *const _, - ) { - __best = __it.clone(); - } - __it.iter_inc(); - } - } - __best - } - .iter_deref()) - .minor) - == (1)) - ); + assert!(( ( ( * { let mut __tmp_15 = { versions .begin() };let mut __tmp_16 = { versions .end() }; let mut __best = __tmp_15 .clone(); if as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__tmp_15 ), LvalueRefUnsafe:: >>::bind(&__tmp_16 ), ) { let mut __it = (__tmp_15 ).clone(); __it.iter_inc(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_16 ), ) { if ::is_less( LvalueRefUnsafe::>::bind(__best.iter_deref()), LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __best = __it.clone(); } __it.iter_inc(); } } __best } .iter_deref() ) . minor ) == ( 1 ) ) ); let mut downloads: UnsafeMap< table29_member_operator_Version, (table29_member_operator_Version, i32), @@ -154,9 +548,18 @@ impl table29_other_operator_shapes_Weight { } } impl LessThanComparableUnsafe for table29_other_operator_shapes_Weight { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - table29_other_operator_shapes_Weight::operator_lt(this, (*other).clone()) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Weight, + |__lhs, __rhs| { + (unsafe { + table29_other_operator_shapes_Weight::operator_lt(&raw const (*__lhs), (*__rhs)) + }) + } + ); } #[repr(C)] #[derive( @@ -175,12 +578,25 @@ pub struct table29_other_operator_shapes_Height { pub millimeters: i32, } impl LessThanComparableUnsafe for table29_other_operator_shapes_Height { - unsafe fn less( - lhs: *const table29_other_operator_shapes_Height, - rhs: *const table29_other_operator_shapes_Height, - ) -> bool { - return (((*lhs).millimeters) < ((*rhs).millimeters)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Height, + |__lhs, __rhs| { + (unsafe { + let _lhs: *const table29_other_operator_shapes_Height = __lhs; + operator_lt_4(_lhs, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_4( + lhs: *const table29_other_operator_shapes_Height, + rhs: *const table29_other_operator_shapes_Height, +) -> bool { + return (((*lhs).millimeters) < ((*rhs).millimeters)); } #[repr(C)] #[derive( @@ -192,10 +608,8 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Height { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(table29_other_operator_shapes_Depth::operator_cmp)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct table29_other_operator_shapes_Depth { pub millimeters: i32, @@ -212,23 +626,217 @@ impl table29_other_operator_shapes_Depth { } } impl LessThanComparableUnsafe for table29_other_operator_shapes_Depth { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(table29_other_operator_shapes_Depth::operator_cmp( - this, other, - )) + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + table29_other_operator_shapes_Depth::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for table29_other_operator_shapes_Depth { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + table29_other_operator_shapes_Depth::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + table29_other_operator_shapes_Depth::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_other_operator_shapes_Depth, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + table29_other_operator_shapes_Depth::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct table29_other_operator_shapes_Length { + pub meters: i32, +} +impl table29_other_operator_shapes_Length { + pub unsafe fn operator_cmp( + this: *const Self, + _a0: *const table29_other_operator_shapes_Length, + ) -> libcc2rs::StrongOrdering { + { + let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from( + std::cmp::Ord::cmp(&((*this).meters), &((*_a0).meters)), + ); + if !(libcc2rs::is_eq(cmp)) { + return cmp; + } + } + return libcc2rs::STRONG_ORDERING_EQUAL; + } + pub unsafe fn operator_eq( + this: *const Self, + _a0: *const table29_other_operator_shapes_Length, + ) -> bool { + return (((*this).meters) == ((*_a0).meters)); } } -pub unsafe fn test_2() { +impl Cpp17EqualityComparableUnsafe for table29_other_operator_shapes_Length { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + (unsafe { + table29_other_operator_shapes_Length::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for table29_other_operator_shapes_Length { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + !(unsafe { + table29_other_operator_shapes_Length::operator_eq(&raw const (*__lhs), __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for table29_other_operator_shapes_Length { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + table29_other_operator_shapes_Length::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for table29_other_operator_shapes_Length { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + table29_other_operator_shapes_Length::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + table29_other_operator_shapes_Length::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_other_operator_shapes_Length, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + table29_other_operator_shapes_Length::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for table29_other_operator_shapes_Length { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { + table29_other_operator_shapes_Length::operator_cmp(&raw const (*__lhs), __rhs) + }) + } + ); +} +pub unsafe fn test_5() { assert!( (({ - let mut __tmp_3: table29_other_operator_shapes_Weight = + let mut __tmp_17: table29_other_operator_shapes_Weight = table29_other_operator_shapes_Weight { grams: 3 }; - let mut __tmp_4: table29_other_operator_shapes_Weight = + let mut __tmp_18: table29_other_operator_shapes_Weight = table29_other_operator_shapes_Weight { grams: 5 }; (*{ - let __a: *const _ = (&mut __tmp_3); - let __b: *const _ = (&mut __tmp_4); - if LessThanComparableUnsafe::less(__a, __b) { + let __a: *const _ = (&mut __tmp_17); + let __b: *const _ = (&mut __tmp_18); + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -239,14 +847,17 @@ pub unsafe fn test_2() { ); assert!( (({ - let mut __tmp_5: table29_other_operator_shapes_Height = + let mut __tmp_19: table29_other_operator_shapes_Height = table29_other_operator_shapes_Height { millimeters: 30 }; - let mut __tmp_6: table29_other_operator_shapes_Height = + let mut __tmp_20: table29_other_operator_shapes_Height = table29_other_operator_shapes_Height { millimeters: 50 }; (*{ - let __a: *const _ = (&mut __tmp_5); - let __b: *const _ = (&mut __tmp_6); - if LessThanComparableUnsafe::less(__b, __a) { + let __a: *const _ = (&mut __tmp_19); + let __b: *const _ = (&mut __tmp_20); + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -257,14 +868,17 @@ pub unsafe fn test_2() { ); assert!( (({ - let mut __tmp_7: table29_other_operator_shapes_Depth = + let mut __tmp_21: table29_other_operator_shapes_Depth = table29_other_operator_shapes_Depth { millimeters: 7 }; - let mut __tmp_8: table29_other_operator_shapes_Depth = + let mut __tmp_22: table29_other_operator_shapes_Depth = table29_other_operator_shapes_Depth { millimeters: 4 }; (*{ - let __a: *const _ = (&mut __tmp_7); - let __b: *const _ = (&mut __tmp_8); - if LessThanComparableUnsafe::less(__a, __b) { + let __a: *const _ = (&mut __tmp_21); + let __b: *const _ = (&mut __tmp_22); + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -273,6 +887,257 @@ pub unsafe fn test_2() { .millimeters }) == (7)) ); + assert!( + (({ + let mut __tmp_23: table29_other_operator_shapes_Length = + table29_other_operator_shapes_Length { meters: 2 }; + let mut __tmp_24: table29_other_operator_shapes_Length = + table29_other_operator_shapes_Length { meters: 9 }; + (*{ + let __a: *const _ = (&mut __tmp_23); + let __b: *const _ = (&mut __tmp_24); + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { + __b + } else { + __a + } + }) + .meters + }) == (2)) + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] +pub struct table29_result_convertible_to_bool_Truth { + pub value: bool, +} +impl table29_result_convertible_to_bool_Truth { + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; + } +} +impl Cpp17EqualityComparableUnsafe for table29_result_convertible_to_bool_Truth { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + == ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for table29_result_convertible_to_bool_Truth { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + != ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl LessThanComparableUnsafe for table29_result_convertible_to_bool_Truth { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + < ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl PartiallyOrderedWithUnsafe for table29_result_convertible_to_bool_Truth { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + > ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + <= ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + table29_result_convertible_to_bool_Truth, + |__lhs, __rhs| { + (((unsafe { table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) }) + as i32) + >= ((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32)) + } + ); +} +impl ThreeWayComparableUnsafe for table29_result_convertible_to_bool_Truth { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__lhs)) + }) as i32), + &((unsafe { + table29_result_convertible_to_bool_Truth::to_bool(&raw const (*__rhs)) + }) as i32), + )) + } + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct table29_result_convertible_to_bool_Priority { + pub level: i32, +} +impl table29_result_convertible_to_bool_Priority { + pub unsafe fn operator_lt( + this: *const Self, + other: *const table29_result_convertible_to_bool_Priority, + ) -> table29_result_convertible_to_bool_Truth { + return table29_result_convertible_to_bool_Truth { + value: (((*this).level) < ((*other).level)), + }; + } +} +impl LessThanComparableUnsafe for table29_result_convertible_to_bool_Priority { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = table29_result_convertible_to_bool_Truth, + table29_result_convertible_to_bool_Priority, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + table29_result_convertible_to_bool_Priority::operator_lt( + &raw const (*__lhs), + __rhs, + ) + }), + ); + }, + |__lhs, __rhs| { + (unsafe { + table29_result_convertible_to_bool_Truth::to_bool( + &(unsafe { + table29_result_convertible_to_bool_Priority::operator_lt( + &raw const (*__lhs), + __rhs, + ) + }), + ) + }) + } + ); +} +pub unsafe fn test_6() { + assert!( + (({ + let mut __tmp_25: table29_result_convertible_to_bool_Priority = + table29_result_convertible_to_bool_Priority { level: 2 }; + let mut __tmp_26: table29_result_convertible_to_bool_Priority = + table29_result_convertible_to_bool_Priority { level: 6 }; + ( * {let __a: *const _ = (& mut __tmp_25); let __b: *const _ = (& mut __tmp_26); if ::is_less( LvalueRefUnsafe::>::bind(__a), LvalueRefUnsafe::>::bind(__b), ) { __b } else { __a }} ) . level + }) == (6)) + ); + assert!( + (({ + let mut __tmp_27: table29_result_convertible_to_bool_Priority = + table29_result_convertible_to_bool_Priority { level: 2 }; + let mut __tmp_28: table29_result_convertible_to_bool_Priority = + table29_result_convertible_to_bool_Priority { level: 6 }; + ( * {let __a: *const _ = (& mut __tmp_27); let __b: *const _ = (& mut __tmp_28); if ::is_less( LvalueRefUnsafe::>::bind(__b), LvalueRefUnsafe::>::bind(__a), ) { __b } else { __a }} ) . level + }) == (2)) + ); + let mut priorities: Vec = Vec::from([ + table29_result_convertible_to_bool_Priority { level: 5 }, + table29_result_convertible_to_bool_Priority { level: 1 }, + table29_result_convertible_to_bool_Priority { level: 3 }, + ]); + { + let mut __tmp_29 = { priorities.begin() }; + let __n = priorities.end().iter_distance(&__tmp_29); + let mut __order: Vec = (0..__n).collect(); + __order.sort_by(|&__x, &__y| { let __a = __tmp_29 .iter_at(__x) as *const table29_result_convertible_to_bool_Priority ; let __b = __tmp_29 .iter_at(__y) as *const table29_result_convertible_to_bool_Priority ; if ::is_less( LvalueRefUnsafe::>::bind(__a), LvalueRefUnsafe::>::bind(__b), ) { std::cmp::Ordering::Less } else if ::is_less( LvalueRefUnsafe::>::bind(__b), LvalueRefUnsafe::>::bind(__a), ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal } }); + let __values: Vec<_> = __order + .iter() + .map(|&__i| std::ptr::read(__tmp_29.iter_at(__i))) + .collect(); + for (__i, __v) in (0..__n).zip(__values) { + std::ptr::write(__tmp_29.iter_at(__i), __v); + } + }; + assert!(((priorities[(0_usize)].level) == (1))); + assert!(((priorities[(1_usize)].level) == (3))); + assert!(((priorities[(2_usize)].level) == (5))); + assert!(( ( ( * { let mut __tmp_30 = { priorities .begin() };let mut __tmp_31 = { priorities .end() }; let mut __best = __tmp_30 .clone(); if as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__tmp_30 ), LvalueRefUnsafe:: >>::bind(&__tmp_31 ), ) { let mut __it = (__tmp_30 ).clone(); __it.iter_inc(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_31 ), ) { if ::is_less( LvalueRefUnsafe::>::bind(__best.iter_deref()), LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __best = __it.clone(); } __it.iter_inc(); } } __best } .iter_deref() ) . level ) == ( 5 ) ) ); } #[repr(C)] #[derive( @@ -290,32 +1155,85 @@ pub unsafe fn test_2() { pub struct pairs_spec_p3_members_order_pairs_Rank { pub value: i32, } -impl LessThanComparableUnsafe for pairs_spec_p3_members_order_pairs_Rank { - unsafe fn less( +impl pairs_spec_p3_members_order_pairs_Rank { + pub unsafe fn operator_lt( this: *const Self, other: *const pairs_spec_p3_members_order_pairs_Rank, ) -> bool { return (((*this).value) < ((*other).value)); } } -pub unsafe fn test_3() { +impl LessThanComparableUnsafe for pairs_spec_p3_members_order_pairs_Rank { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + pairs_spec_p3_members_order_pairs_Rank, + |__lhs, __rhs| { + (unsafe { + pairs_spec_p3_members_order_pairs_Rank::operator_lt(&raw const (*__lhs), __rhs) + }) + } + ); +} +pub unsafe fn test_7() { let mut low: (pairs_spec_p3_members_order_pairs_Rank, i32) = ((pairs_spec_p3_members_order_pairs_Rank { value: 1 }), 9); let mut high: (pairs_spec_p3_members_order_pairs_Rank, i32) = ((pairs_spec_p3_members_order_pairs_Rank { value: 2 }), 0); let mut high_later: (pairs_spec_p3_members_order_pairs_Rank, i32) = ((pairs_spec_p3_members_order_pairs_Rank { value: 2 }), 5); - assert!(LessThanComparableUnsafe::less(&low, &high)); - assert!(LessThanComparableUnsafe::less(&high, &high_later)); - assert!(LessThanComparableUnsafe::less(&low, &high_later)); - assert!(!LessThanComparableUnsafe::less(&high, &low)); - assert!(!LessThanComparableUnsafe::less(&high_later, &high)); - assert!(!(LessThanComparableUnsafe::less(&high, &low))); + assert!( + <(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&low), + LvalueRefUnsafe::>::bind(&high), + ) + ); + assert!( + <(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&high), + LvalueRefUnsafe::>::bind( + &high_later + ), + ) + ); + assert!( + <(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&low), + LvalueRefUnsafe::>::bind( + &high_later + ), + ) + ); + assert!( + !<(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&high), + LvalueRefUnsafe::>::bind(&low), + ) + ); + assert!( + !<(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind( + &high_later + ), + LvalueRefUnsafe::>::bind(&high), + ) + ); + assert!( + !(<(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&high), + LvalueRefUnsafe::>::bind(&low), + )) + ); assert!( (((*{ let __a: *const _ = &mut low; let __b: *const _ = &mut high; - if LessThanComparableUnsafe::less(__a, __b) { + if <(pairs_spec_p3_members_order_pairs_Rank, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -331,11 +1249,14 @@ pub fn main() { } } unsafe fn main_0() -> i32 { + (unsafe { test_0() }); (unsafe { test_1() }); - (unsafe { test_2() }); (unsafe { test_3() }); + (unsafe { test_5() }); + (unsafe { test_6() }); + (unsafe { test_7() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const less_calls_0); + std::cell::LazyCell::force(&*&raw const less_calls_2); } diff --git a/tests/std/library/requirements/utility.requirements/utility.arg.requirements.cpp b/tests/std/library/requirements/utility.requirements/utility.arg.requirements.cpp index 9d14b6cfad..37d22cb042 100644 --- a/tests/std/library/requirements/utility.requirements/utility.arg.requirements.cpp +++ b/tests/std/library/requirements/utility.requirements/utility.arg.requirements.cpp @@ -6,6 +6,59 @@ #include #include +// N4950 [utility.arg.requirements] Table 28 (Cpp17EqualityComparable): a == b +// is the only operation the library uses to compare values for equality. +namespace table28_equal_operator { +struct Ticket { + int number; + bool operator==(const Ticket &other) const { return number == other.number; } +}; + +void test() { + std::vector tickets{{4}, {4}, {7}, {9}, {9}}; + assert(std::find(tickets.begin(), tickets.end(), Ticket{7})->number == 7); + assert(std::find(tickets.begin(), tickets.end(), Ticket{5}) == tickets.end()); + auto last = std::unique(tickets.begin(), tickets.end()); + assert(tickets[0].number == 4 && tickets[1].number == 7 && + tickets[2].number == 9); + ++last; + assert(last != tickets.end()); + ++last; + assert(last == tickets.end()); +} +} // namespace table28_equal_operator + +// N4950 [utility.arg.requirements] Table 28: the result of a == b need only be +// convertible to bool, and then a != b does not exist ([over.match.oper]/9). +namespace table28_result_convertible_to_bool { +struct Truth { + bool value; + operator bool() const { return value; } +}; + +struct Ticket { + int number; + Truth operator==(const Ticket &other) const { + return Truth{number == other.number}; + } +}; + +struct Badge { + int id; + Truth operator==(const int &other) const { return Truth{id == other}; } +}; + +void test() { + std::vector tickets{{4}, {7}, {9}}; + assert(std::find(tickets.begin(), tickets.end(), Ticket{9})->number == 9); + assert(std::find(tickets.begin(), tickets.end(), Ticket{5}) == tickets.end()); + + std::vector badges{{1}, {2}, {3}}; + assert(std::find(badges.begin(), badges.end(), 2)->id == 2); + assert(std::find(badges.begin(), badges.end(), 8) == badges.end()); +} +} // namespace table28_result_convertible_to_bool + // N4950 [utility.arg.requirements] Table 29 (Cpp17LessThanComparable): a < b // is a strict weak ordering, and is the only operation the library uses to // order values. @@ -68,13 +121,46 @@ struct Depth { } }; +struct Length { + int meters; + auto operator<=>(const Length &) const = default; +}; + void test() { assert(std::max(Weight{3}, Weight{5}).grams == 5); assert(std::min(Height{30}, Height{50}).millimeters == 30); assert(std::max(Depth{7}, Depth{4}).millimeters == 7); + assert(std::min(Length{2}, Length{9}).meters == 2); } } // namespace table29_other_operator_shapes +// N4950 [utility.arg.requirements] Table 29: the result of a < b need only be +// convertible to bool. +namespace table29_result_convertible_to_bool { +struct Truth { + bool value; + operator bool() const { return value; } +}; + +struct Priority { + int level; + Truth operator<(const Priority &other) const { + return Truth{level < other.level}; + } +}; + +void test() { + assert(std::max(Priority{2}, Priority{6}).level == 6); + assert(std::min(Priority{2}, Priority{6}).level == 2); + std::vector priorities{{5}, {1}, {3}}; + std::sort(priorities.begin(), priorities.end()); + assert(priorities[0].level == 1); + assert(priorities[1].level == 3); + assert(priorities[2].level == 5); + assert(std::max_element(priorities.begin(), priorities.end())->level == 5); +} +} // namespace table29_result_convertible_to_bool + // N4950 [pairs.spec]/3: pairs are ordered by their first members, and by // their second members if the first ones are equivalent, using operator< of // the members. @@ -99,8 +185,11 @@ void test() { } // namespace pairs_spec_p3_members_order_pairs int main() { + table28_equal_operator::test(); + table28_result_convertible_to_bool::test(); table29_member_operator::test(); table29_other_operator_shapes::test(); + table29_result_convertible_to_bool::test(); pairs_spec_p3_members_order_pairs::test(); return 0; } diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 0afa87e2a5..b1a7a4f54f 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -118,6 +118,148 @@ impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsTo (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl Cpp17EqualityComparable for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } == { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); +} +impl WeaklyEqualityComparableWith + for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } != { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); +} +impl LessThanComparable for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } < { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); +} +impl PartiallyOrderedWith for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } > { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } <= { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ({ + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__lhs).clone(), + ) + }) + } >= { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + (__rhs).clone(), + ) + }) + }) + } + ); +} pub fn test_7() { { let selector: Value = diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index ca1db4dfaa..7890487e09 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -92,6 +92,126 @@ impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_Conv (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } +impl Cpp17EqualityComparableUnsafe + for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) == (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe + for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) != (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); +} +impl LessThanComparableUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) < (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); +} +impl PartiallyOrderedWithUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) > (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) <= (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p2_condition_variable_lives_for_whole_statement_ConvertsToInt, + |__lhs, __rhs| { + ((unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__lhs), + ) + }) >= (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const (*__rhs), + ) + })) + } + ); +} pub unsafe fn test_7() { { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = diff --git a/tests/std/support/cmp/out/refcount/cmp.concept.rs b/tests/std/support/cmp/out/refcount/cmp.concept.rs index c974b14ce7..718d033f14 100644 --- a/tests/std/support/cmp/out/refcount/cmp.concept.rs +++ b/tests/std/support/cmp/out/refcount/cmp.concept.rs @@ -17,10 +17,8 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct p1_defaulted_three_way_Version { @@ -29,9 +27,8 @@ pub struct p1_defaulted_three_way_Version { #[offset(4)] pub minor: i32, } -impl ThreeWayComparable for p1_defaulted_three_way_Version { - type Category = libcc2rs::StrongOrdering; - fn three_way( +impl p1_defaulted_three_way_Version { + pub fn operator_cmp( this: Ptr, _a0: Ptr, ) -> libcc2rs::StrongOrdering { @@ -55,11 +52,104 @@ impl ThreeWayComparable for p1_defaulted_three_way_Version { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.major) } == { _a0.with(|__s| __s.major) }) + && ({ this.with(|__s| __s.minor) } == { _a0.with(|__s| __s.minor) }); + } +} +impl Cpp17EqualityComparable for p1_defaulted_three_way_Version { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + ({ p1_defaulted_three_way_Version::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_defaulted_three_way_Version { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + !({ p1_defaulted_three_way_Version::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); } impl LessThanComparable for p1_defaulted_three_way_Version { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_defaulted_three_way_Version::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_defaulted_three_way_Version { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_defaulted_three_way_Version::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_defaulted_three_way_Version::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_defaulted_three_way_Version::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl ThreeWayComparable for p1_defaulted_three_way_Version { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + ({ p1_defaulted_three_way_Version::operator_cmp((__lhs).clone(), (__rhs).clone()) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); const _: () = assert!( @@ -78,25 +168,53 @@ pub fn test_0() { minor: 0, })); let order: Value = Rc::new(RefCell::new( - ({ ThreeWayComparable::three_way(old_version.as_pointer(), new_version.as_pointer()) }), + ({ + p1_defaulted_three_way_Version::operator_cmp( + old_version.as_pointer(), + new_version.as_pointer(), + ) + }), )); assert!(libcc2rs::is_lt(({ (*order.borrow()) }))); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(new_version.as_pointer(), old_version.as_pointer(),) }) + ({ + p1_defaulted_three_way_Version::operator_cmp( + new_version.as_pointer(), + old_version.as_pointer(), + ) + }) )); assert!(libcc2rs::is_eq( - ({ ThreeWayComparable::three_way(old_version.as_pointer(), old_version.as_pointer(),) }) + ({ + p1_defaulted_three_way_Version::operator_cmp( + old_version.as_pointer(), + old_version.as_pointer(), + ) + }) )); assert!( ({ - WeaklyEqualityComparableWith::equal(old_version.as_pointer(), old_version.as_pointer()) + p1_defaulted_three_way_Version::operator_eq( + old_version.as_pointer(), + old_version.as_pointer(), + ) }) ); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(old_version.as_pointer(), new_version.as_pointer(),) }) + ({ + p1_defaulted_three_way_Version::operator_cmp( + old_version.as_pointer(), + new_version.as_pointer(), + ) + }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(new_version.as_pointer(), old_version.as_pointer(),) }) + ({ + p1_defaulted_three_way_Version::operator_cmp( + new_version.as_pointer(), + old_version.as_pointer(), + ) + }) )); } thread_local!( @@ -113,19 +231,19 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct p1_user_written_three_way_Money { #[offset(0)] pub cents: i32, } -impl ThreeWayComparable for p1_user_written_three_way_Money { - type Category = libcc2rs::StrongOrdering; - fn three_way( +impl p1_user_written_three_way_Money { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.cents) } == { other.with(|__s| __s.cents) }); + } + pub fn operator_cmp( this: Ptr, other: Ptr, ) -> libcc2rs::StrongOrdering { @@ -136,10 +254,99 @@ impl ThreeWayComparable for p1_user_written_three_way_Money { )); } } +impl Cpp17EqualityComparable for p1_user_written_three_way_Money { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + ({ p1_user_written_three_way_Money::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_user_written_three_way_Money { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + !({ p1_user_written_three_way_Money::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} impl LessThanComparable for p1_user_written_three_way_Money { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), other.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_user_written_three_way_Money::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_user_written_three_way_Money { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_user_written_three_way_Money::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_user_written_three_way_Money::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_user_written_three_way_Money::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl ThreeWayComparable for p1_user_written_three_way_Money { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + ({ p1_user_written_three_way_Money::operator_cmp((__lhs).clone(), (__rhs).clone()) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); pub fn test_2() { @@ -148,22 +355,34 @@ pub fn test_2() { let large: Value = Rc::new(RefCell::new(p1_user_written_three_way_Money { cents: 900 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(small.as_pointer(), large.as_pointer(),) }) + ({ + p1_user_written_three_way_Money::operator_cmp(small.as_pointer(), large.as_pointer()) + }) )); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(small.as_pointer(), large.as_pointer(),) }) + ({ + p1_user_written_three_way_Money::operator_cmp(small.as_pointer(), large.as_pointer()) + }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(large.as_pointer(), small.as_pointer(),) }) + ({ + p1_user_written_three_way_Money::operator_cmp(large.as_pointer(), small.as_pointer()) + }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(small.as_pointer(), small.as_pointer(),) }) + ({ + p1_user_written_three_way_Money::operator_cmp(small.as_pointer(), small.as_pointer()) + }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(large.as_pointer(), small.as_pointer(),) }) + ({ + p1_user_written_three_way_Money::operator_cmp(large.as_pointer(), small.as_pointer()) + }) )); assert!((three_way_calls_1.with(|rc| *rc.borrow()) == 5)); - assert!(({ WeaklyEqualityComparableWith::equal(small.as_pointer(), small.as_pointer(),) })); + assert!( + ({ p1_user_written_three_way_Money::operator_eq(small.as_pointer(), small.as_pointer(),) }) + ); assert!((three_way_calls_1.with(|rc| *rc.borrow()) == 5)); } #[derive( @@ -177,19 +396,19 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct p1_weaker_category_Temperature { #[offset(0)] pub degrees: f64, } -impl ThreeWayComparable for p1_weaker_category_Temperature { - type Category = libcc2rs::PartialOrdering; - fn three_way( +impl p1_weaker_category_Temperature { + pub fn operator_eq(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.degrees) } == { other.with(|__s| __s.degrees) }); + } + pub fn operator_cmp( this: Ptr, other: Ptr, ) -> libcc2rs::PartialOrdering { @@ -199,10 +418,99 @@ impl ThreeWayComparable for p1_weaker_category_Temperature { )); } } +impl Cpp17EqualityComparable for p1_weaker_category_Temperature { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + ({ p1_weaker_category_Temperature::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} +impl WeaklyEqualityComparableWith for p1_weaker_category_Temperature { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + !({ p1_weaker_category_Temperature::operator_eq((__lhs).clone(), (__rhs).clone()) }) + } + ); +} impl LessThanComparable for p1_weaker_category_Temperature { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), other.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_weaker_category_Temperature::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_weaker_category_Temperature { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_weaker_category_Temperature::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_weaker_category_Temperature::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_weaker_category_Temperature::operator_cmp((__lhs).clone(), (__rhs).clone()) + }), + ) + } + ); +} +impl ThreeWayComparable for p1_weaker_category_Temperature { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::PartialOrdering, + |__lhs, __rhs| { + ({ p1_weaker_category_Temperature::operator_cmp((__lhs).clone(), (__rhs).clone()) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); const _: () = assert!( @@ -219,14 +527,14 @@ pub fn test_3() { degrees: 21.5_f64, })); let order: Value = Rc::new(RefCell::new( - ({ ThreeWayComparable::three_way(cold.as_pointer(), warm.as_pointer()) }), + ({ p1_weaker_category_Temperature::operator_cmp(cold.as_pointer(), warm.as_pointer()) }), )); assert!(libcc2rs::is_lt(({ (*order.borrow()) }))); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(cold.as_pointer(), warm.as_pointer(),) }) + ({ p1_weaker_category_Temperature::operator_cmp(cold.as_pointer(), warm.as_pointer(),) }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(warm.as_pointer(), cold.as_pointer(),) }) + ({ p1_weaker_category_Temperature::operator_cmp(warm.as_pointer(), cold.as_pointer(),) }) )); } #[derive( @@ -240,10 +548,8 @@ pub fn test_3() { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(p1_three_way_without_equality_Rank::operator_cmp)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct p1_three_way_without_equality_Rank { @@ -262,12 +568,76 @@ impl p1_three_way_without_equality_Rank { } } impl LessThanComparable for p1_three_way_without_equality_Rank { - fn less(this: Ptr, other: Ptr) -> bool { - libcc2rs::is_lt(p1_three_way_without_equality_Rank::operator_cmp( - this.clone(), - other.clone(), - )) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_lt( + ({ + p1_three_way_without_equality_Rank::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); +} +impl PartiallyOrderedWith for p1_three_way_without_equality_Rank { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_gt( + ({ + p1_three_way_without_equality_Rank::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_lteq( + ({ + p1_three_way_without_equality_Rank::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_gteq( + ({ + p1_three_way_without_equality_Rank::operator_cmp( + (__lhs).clone(), + (__rhs).clone(), + ) + }), + ) + } + ); } const _: () = assert!(!(false), "!std::three_way_comparable"); pub fn test_4() { @@ -306,22 +676,6 @@ fn main_0() -> i32 { ({ test_4() }); return 0; } -impl WeaklyEqualityComparableWith for p1_defaulted_three_way_Version { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.major) } == { _a0.with(|__s| __s.major) }) - && ({ this.with(|__s| __s.minor) } == { _a0.with(|__s| __s.minor) }); - } -} -impl WeaklyEqualityComparableWith for p1_user_written_three_way_Money { - fn equal(this: Ptr, other: Ptr) -> bool { - return ({ this.with(|__s| __s.cents) } == { other.with(|__s| __s.cents) }); - } -} -impl WeaklyEqualityComparableWith for p1_weaker_category_Temperature { - fn equal(this: Ptr, other: Ptr) -> bool { - return ({ this.with(|__s| __s.degrees) } == { other.with(|__s| __s.degrees) }); - } -} pub fn __cpp2rust_init_globals() { let _ = three_way_calls_1.with(|_| ()); } diff --git a/tests/std/support/cmp/out/unsafe/cmp.concept.rs b/tests/std/support/cmp/out/unsafe/cmp.concept.rs index 126c5aa0a9..8d79ad8ba2 100644 --- a/tests/std/support/cmp/out/unsafe/cmp.concept.rs +++ b/tests/std/support/cmp/out/unsafe/cmp.concept.rs @@ -16,18 +16,15 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_defaulted_three_way_Version { pub major: i32, pub minor: i32, } -impl ThreeWayComparableUnsafe for p1_defaulted_three_way_Version { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way( +impl p1_defaulted_three_way_Version { + pub unsafe fn operator_cmp( this: *const Self, _a0: *const p1_defaulted_three_way_Version, ) -> libcc2rs::StrongOrdering { @@ -49,11 +46,106 @@ impl ThreeWayComparableUnsafe for p1_defaulted_three_way_Version { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_eq( + this: *const Self, + _a0: *const p1_defaulted_three_way_Version, + ) -> bool { + return (((*this).major) == ((*_a0).major)) && (((*this).minor) == ((*_a0).minor)); + } +} +impl Cpp17EqualityComparableUnsafe for p1_defaulted_three_way_Version { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + (unsafe { p1_defaulted_three_way_Version::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_defaulted_three_way_Version { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + !(unsafe { p1_defaulted_three_way_Version::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); } impl LessThanComparableUnsafe for p1_defaulted_three_way_Version { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_defaulted_three_way_Version { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_defaulted_three_way_Version, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p1_defaulted_three_way_Version { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { p1_defaulted_three_way_Version::operator_cmp(&raw const (*__lhs), __rhs) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); const _: () = assert!( @@ -65,29 +157,36 @@ pub unsafe fn test_0() { p1_defaulted_three_way_Version { major: 1, minor: 9 }; let mut new_version: p1_defaulted_three_way_Version = p1_defaulted_three_way_Version { major: 2, minor: 0 }; - let mut order: libcc2rs::StrongOrdering = - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const old_version, &new_version) }); + let mut order: libcc2rs::StrongOrdering = (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const old_version, &new_version) + }); assert!(libcc2rs::is_lt(order)); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const new_version, &old_version,) }) + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const new_version, &old_version) + }) )); assert!(libcc2rs::is_eq( (unsafe { let _arg0: *const p1_defaulted_three_way_Version = &old_version; - ThreeWayComparableUnsafe::three_way(&raw const old_version, _arg0) + p1_defaulted_three_way_Version::operator_cmp(&raw const old_version, _arg0) }) )); assert!( (unsafe { let _arg0: *const p1_defaulted_three_way_Version = &old_version; - WeaklyEqualityComparableWithUnsafe::equal(&raw const old_version, _arg0) + p1_defaulted_three_way_Version::operator_eq(&raw const old_version, _arg0) }) ); assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const old_version, &new_version,) }) + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const old_version, &new_version) + }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const new_version, &old_version,) }) + (unsafe { + p1_defaulted_three_way_Version::operator_cmp(&raw const new_version, &old_version) + }) )); } pub static mut three_way_calls_1: std::cell::LazyCell = @@ -102,17 +201,20 @@ pub static mut three_way_calls_1: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_user_written_three_way_Money { pub cents: i32, } -impl ThreeWayComparableUnsafe for p1_user_written_three_way_Money { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way( +impl p1_user_written_three_way_Money { + pub unsafe fn operator_eq( + this: *const Self, + other: *const p1_user_written_three_way_Money, + ) -> bool { + return (((*this).cents) == ((*other).cents)); + } + pub unsafe fn operator_cmp( this: *const Self, other: *const p1_user_written_three_way_Money, ) -> libcc2rs::StrongOrdering { @@ -123,38 +225,127 @@ impl ThreeWayComparableUnsafe for p1_user_written_three_way_Money { )); } } +impl Cpp17EqualityComparableUnsafe for p1_user_written_three_way_Money { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + (unsafe { p1_user_written_three_way_Money::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_user_written_three_way_Money { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + !(unsafe { p1_user_written_three_way_Money::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} impl LessThanComparableUnsafe for p1_user_written_three_way_Money { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, other)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_user_written_three_way_Money::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_user_written_three_way_Money { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_user_written_three_way_Money::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_user_written_three_way_Money::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_user_written_three_way_Money, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_user_written_three_way_Money::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p1_user_written_three_way_Money { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { p1_user_written_three_way_Money::operator_cmp(&raw const (*__lhs), __rhs) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); pub unsafe fn test_2() { let mut small: p1_user_written_three_way_Money = p1_user_written_three_way_Money { cents: 150 }; let mut large: p1_user_written_three_way_Money = p1_user_written_three_way_Money { cents: 900 }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const small, &large,) }) + (unsafe { p1_user_written_three_way_Money::operator_cmp(&raw const small, &large,) }) )); assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const small, &large,) }) + (unsafe { p1_user_written_three_way_Money::operator_cmp(&raw const small, &large,) }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const large, &small,) }) + (unsafe { p1_user_written_three_way_Money::operator_cmp(&raw const large, &small,) }) )); assert!(libcc2rs::is_lteq( (unsafe { let _other: *const p1_user_written_three_way_Money = &small; - ThreeWayComparableUnsafe::three_way(&raw const small, _other) + p1_user_written_three_way_Money::operator_cmp(&raw const small, _other) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const large, &small,) }) + (unsafe { p1_user_written_three_way_Money::operator_cmp(&raw const large, &small,) }) )); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut three_way_calls_1)) == (5))); assert!( (unsafe { let _other: *const p1_user_written_three_way_Money = &small; - WeaklyEqualityComparableWithUnsafe::equal(&raw const small, _other) + p1_user_written_three_way_Money::operator_eq(&raw const small, _other) }) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut three_way_calls_1)) == (5))); @@ -169,17 +360,20 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_weaker_category_Temperature { pub degrees: f64, } -impl ThreeWayComparableUnsafe for p1_weaker_category_Temperature { - type Category = libcc2rs::PartialOrdering; - unsafe fn three_way( +impl p1_weaker_category_Temperature { + pub unsafe fn operator_eq( + this: *const Self, + other: *const p1_weaker_category_Temperature, + ) -> bool { + return (((*this).degrees) == ((*other).degrees)); + } + pub unsafe fn operator_cmp( this: *const Self, other: *const p1_weaker_category_Temperature, ) -> libcc2rs::PartialOrdering { @@ -189,10 +383,99 @@ impl ThreeWayComparableUnsafe for p1_weaker_category_Temperature { )); } } +impl Cpp17EqualityComparableUnsafe for p1_weaker_category_Temperature { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + (unsafe { p1_weaker_category_Temperature::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for p1_weaker_category_Temperature { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + !(unsafe { p1_weaker_category_Temperature::operator_eq(&raw const (*__lhs), __rhs) }) + } + ); +} impl LessThanComparableUnsafe for p1_weaker_category_Temperature { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, other)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_weaker_category_Temperature::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_weaker_category_Temperature { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_weaker_category_Temperature::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_weaker_category_Temperature::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_weaker_category_Temperature, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_weaker_category_Temperature::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl ThreeWayComparableUnsafe for p1_weaker_category_Temperature { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::PartialOrdering, + |__lhs, __rhs| { + (unsafe { p1_weaker_category_Temperature::operator_cmp(&raw const (*__lhs), __rhs) }) + } + ); } const _: () = assert!(true, "std::three_way_comparable"); const _: () = assert!( @@ -205,13 +488,13 @@ pub unsafe fn test_3() { let mut warm: p1_weaker_category_Temperature = p1_weaker_category_Temperature { degrees: 21.5_f64 }; let mut order: libcc2rs::PartialOrdering = - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const cold, &warm) }); + (unsafe { p1_weaker_category_Temperature::operator_cmp(&raw const cold, &warm) }); assert!(libcc2rs::is_lt(order)); assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const cold, &warm,) }) + (unsafe { p1_weaker_category_Temperature::operator_cmp(&raw const cold, &warm,) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const warm, &cold,) }) + (unsafe { p1_weaker_category_Temperature::operator_cmp(&raw const warm, &cold,) }) )); } #[repr(C)] @@ -224,10 +507,8 @@ pub unsafe fn test_3() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(p1_three_way_without_equality_Rank::operator_cmp)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct p1_three_way_without_equality_Rank { pub value: i32, @@ -244,11 +525,64 @@ impl p1_three_way_without_equality_Rank { } } impl LessThanComparableUnsafe for p1_three_way_without_equality_Rank { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - libcc2rs::is_lt(p1_three_way_without_equality_Rank::operator_cmp( - this, other, - )) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + p1_three_way_without_equality_Rank::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); +} +impl PartiallyOrderedWithUnsafe for p1_three_way_without_equality_Rank { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + p1_three_way_without_equality_Rank::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + p1_three_way_without_equality_Rank::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + p1_three_way_without_equality_Rank, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + p1_three_way_without_equality_Rank::operator_cmp(&raw const (*__lhs), __rhs) + }), + ) + } + ); } const _: () = assert!(!(false), "!std::three_way_comparable"); pub unsafe fn test_4() { @@ -279,21 +613,6 @@ unsafe fn main_0() -> i32 { (unsafe { test_4() }); return 0; } -impl WeaklyEqualityComparableWithUnsafe for p1_defaulted_three_way_Version { - unsafe fn equal(this: *const Self, _a0: *const p1_defaulted_three_way_Version) -> bool { - return (((*this).major) == ((*_a0).major)) && (((*this).minor) == ((*_a0).minor)); - } -} -impl WeaklyEqualityComparableWithUnsafe for p1_user_written_three_way_Money { - unsafe fn equal(this: *const Self, other: *const p1_user_written_three_way_Money) -> bool { - return (((*this).cents) == ((*other).cents)); - } -} -impl WeaklyEqualityComparableWithUnsafe for p1_weaker_category_Temperature { - unsafe fn equal(this: *const Self, other: *const p1_weaker_category_Temperature) -> bool { - return (((*this).degrees) == ((*other).degrees)); - } -} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const three_way_calls_1); } diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index 35d80cdd12..3c4b0fdbaa 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -156,36 +156,76 @@ pub fn test_4() { Rc::new(RefCell::new(0)), ))); 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() + !(::is_equal( + LvalueRef::>::bind((*a.borrow()).0.as_pointer()), + LvalueRef::>::bind((*b.borrow()).0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind((*a.borrow()).1.as_pointer()), + LvalueRef::>::bind((*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(), + !(!(::is_equal( + LvalueRef::>::bind((*a.borrow()).0.as_pointer()), + LvalueRef::>::bind((*a.borrow()).0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind((*a.borrow()).1.as_pointer()), + LvalueRef::>::bind((*a.borrow()).1.as_pointer()), ))) }) ); - assert!(LessThanComparable::less(a.as_pointer(), b.as_pointer())); - assert!(!(LessThanComparable::less(b.as_pointer(), a.as_pointer()))); - assert!(LessThanComparable::less(b.as_pointer(), c.as_pointer())); - assert!(!LessThanComparable::less(a.as_pointer(), a.as_pointer())); - assert!(!(!LessThanComparable::less(b.as_pointer(), c.as_pointer()))); - assert!(LessThanComparable::less(b.as_pointer(), c.as_pointer())); - assert!(!(LessThanComparable::less(a.as_pointer(), a.as_pointer()))); - assert!(!LessThanComparable::less(c.as_pointer(), a.as_pointer())); - assert!(!(!LessThanComparable::less(a.as_pointer(), b.as_pointer()))); - let mut ordered: bool = (LessThanComparable::less(a.as_pointer(), b.as_pointer())) - && (LessThanComparable::less(b.as_pointer(), c.as_pointer())); + assert!(<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a.as_pointer()), + LvalueRef::, Value)>>::bind(b.as_pointer()), + )); + assert!( + !(<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(b.as_pointer()), + LvalueRef::, Value)>>::bind(a.as_pointer()), + )) + ); + assert!(<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(b.as_pointer()), + LvalueRef::, Value)>>::bind(c.as_pointer()), + )); + assert!(!<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a.as_pointer()), + LvalueRef::, Value)>>::bind(a.as_pointer()), + )); + assert!( + !(!<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(b.as_pointer()), + LvalueRef::, Value)>>::bind(c.as_pointer()), + )) + ); + assert!(<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(b.as_pointer()), + LvalueRef::, Value)>>::bind(c.as_pointer()), + )); + assert!( + !(<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a.as_pointer()), + LvalueRef::, Value)>>::bind(a.as_pointer()), + )) + ); + assert!(!<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(c.as_pointer()), + LvalueRef::, Value)>>::bind(a.as_pointer()), + )); + assert!( + !(!<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a.as_pointer()), + LvalueRef::, Value)>>::bind(b.as_pointer()), + )) + ); + let mut ordered: bool = (<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(a.as_pointer()), + LvalueRef::, Value)>>::bind(b.as_pointer()), + )) && (<(Value, Value) as LessThanComparable>::is_less( + LvalueRef::, Value)>>::bind(b.as_pointer()), + LvalueRef::, Value)>>::bind(c.as_pointer()), + )); assert!(ordered); } pub fn test_5() { @@ -257,23 +297,23 @@ pub fn test_7() { ))); assert!( ({ - WeaklyEqualityComparableWith::equal( - (*to_x.borrow()).0.as_pointer(), - (*to_y.borrow()).0.as_pointer(), - ) && WeaklyEqualityComparableWith::equal( - (*to_x.borrow()).1.as_pointer(), - (*to_y.borrow()).1.as_pointer(), + as Cpp17EqualityComparable>::is_equal( + LvalueRef::>>::bind((*to_x.borrow()).0.as_pointer()), + LvalueRef::>>::bind((*to_y.borrow()).0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind((*to_x.borrow()).1.as_pointer()), + LvalueRef::>::bind((*to_y.borrow()).1.as_pointer()), ) }) ); (*y.borrow_mut()) = 5; assert!( - !(WeaklyEqualityComparableWith::equal( - (*to_x.borrow()).0.as_pointer(), - (*to_y.borrow()).0.as_pointer() - ) && WeaklyEqualityComparableWith::equal( - (*to_x.borrow()).1.as_pointer(), - (*to_y.borrow()).1.as_pointer() + !( as Cpp17EqualityComparable>::is_equal( + LvalueRef::>>::bind((*to_x.borrow()).0.as_pointer()), + LvalueRef::>>::bind((*to_y.borrow()).0.as_pointer()), + ) && ::is_equal( + LvalueRef::>::bind((*to_x.borrow()).1.as_pointer()), + LvalueRef::>::bind((*to_y.borrow()).1.as_pointer()), )) ); } diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index ca2b64b432..601bc297bb 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -172,24 +172,74 @@ pub unsafe fn test_4() { let mut b: (i32, i32) = (1, 3); let mut c: (i32, i32) = (2, 0); assert!( - !(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &b.0) - && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &b.1)) + !(::is_equal( + LvalueRefUnsafe::>::bind(&a.0), + LvalueRefUnsafe::>::bind(&b.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&a.1), + LvalueRefUnsafe::>::bind(&b.1), + )) ); assert!( - !(!(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &a.0) - && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &a.1))) + !(!(::is_equal( + LvalueRefUnsafe::>::bind(&a.0), + LvalueRefUnsafe::>::bind(&a.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&a.1), + LvalueRefUnsafe::>::bind(&a.1), + ))) ); - assert!(LessThanComparableUnsafe::less(&a, &b)); - assert!(!(LessThanComparableUnsafe::less(&b, &a))); - assert!(LessThanComparableUnsafe::less(&b, &c)); - assert!(!LessThanComparableUnsafe::less(&a, &a)); - assert!(!(!LessThanComparableUnsafe::less(&b, &c))); - assert!(LessThanComparableUnsafe::less(&b, &c)); - assert!(!(LessThanComparableUnsafe::less(&a, &a))); - assert!(!LessThanComparableUnsafe::less(&c, &a)); - assert!(!(!LessThanComparableUnsafe::less(&a, &b))); - let mut ordered: bool = - (LessThanComparableUnsafe::less(&a, &b)) && (LessThanComparableUnsafe::less(&b, &c)); + assert!(<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a), + LvalueRefUnsafe::>::bind(&b), + )); + assert!( + !(<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&b), + LvalueRefUnsafe::>::bind(&a), + )) + ); + assert!(<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&b), + LvalueRefUnsafe::>::bind(&c), + )); + assert!(!<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a), + LvalueRefUnsafe::>::bind(&a), + )); + assert!( + !(!<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&b), + LvalueRefUnsafe::>::bind(&c), + )) + ); + assert!(<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&b), + LvalueRefUnsafe::>::bind(&c), + )); + assert!( + !(<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a), + LvalueRefUnsafe::>::bind(&a), + )) + ); + assert!(!<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&c), + LvalueRefUnsafe::>::bind(&a), + )); + assert!( + !(!<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a), + LvalueRefUnsafe::>::bind(&b), + )) + ); + let mut ordered: bool = (<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&a), + LvalueRefUnsafe::>::bind(&b), + )) && (<(i32, i32) as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(&b), + LvalueRefUnsafe::>::bind(&c), + )); assert!(ordered); } pub unsafe fn test_5() { @@ -236,13 +286,23 @@ pub unsafe fn test_7() { let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 0); assert!( - WeaklyEqualityComparableWithUnsafe::equal(&to_x.0, &to_y.0) - && WeaklyEqualityComparableWithUnsafe::equal(&to_x.1, &to_y.1) + as Cpp17EqualityComparableUnsafe>::is_equal( + LvalueRefUnsafe::>>::bind(&to_x.0), + LvalueRefUnsafe::>>::bind(&to_y.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&to_x.1), + LvalueRefUnsafe::>::bind(&to_y.1), + ) ); y = 5; assert!( - !(WeaklyEqualityComparableWithUnsafe::equal(&to_x.0, &to_y.0) - && WeaklyEqualityComparableWithUnsafe::equal(&to_x.1, &to_y.1)) + !( as Cpp17EqualityComparableUnsafe>::is_equal( + LvalueRefUnsafe::>>::bind(&to_x.0), + LvalueRefUnsafe::>>::bind(&to_y.0), + ) && ::is_equal( + LvalueRefUnsafe::>::bind(&to_x.1), + LvalueRefUnsafe::>::bind(&to_y.1), + )) ); } pub unsafe fn test_8() { diff --git a/tests/ub/out/refcount/max.rs b/tests/ub/out/refcount/max.rs index b6361498e4..d12417dc9b 100644 --- a/tests/ub/out/refcount/max.rs +++ b/tests/ub/out/refcount/max.rs @@ -14,7 +14,10 @@ fn main_0() -> i32 { let a: Ptr = ({ let __tmp_0: Value = Rc::new(RefCell::new(2)); let __tmp_1: Value = Rc::new(RefCell::new(1)); - if LessThanComparable::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { + if ::is_less( + LvalueRef::>::bind(__tmp_0.as_pointer().clone()), + LvalueRef::>::bind(__tmp_1.as_pointer().clone()), + ) { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() @@ -23,7 +26,10 @@ fn main_0() -> i32 { let b: Ptr = ({ let __tmp_2: Value = Rc::new(RefCell::new(1)); let __tmp_3: Value = Rc::new(RefCell::new(2)); - if LessThanComparable::less(__tmp_2.as_pointer().clone(), __tmp_3.as_pointer().clone()) { + if ::is_less( + LvalueRef::>::bind(__tmp_2.as_pointer().clone()), + LvalueRef::>::bind(__tmp_3.as_pointer().clone()), + ) { __tmp_3.as_pointer() } else { __tmp_2.as_pointer() diff --git a/tests/ub/out/unsafe/max.rs b/tests/ub/out/unsafe/max.rs index 8461548df3..e914a88029 100644 --- a/tests/ub/out/unsafe/max.rs +++ b/tests/ub/out/unsafe/max.rs @@ -19,7 +19,10 @@ unsafe fn main_0() -> i32 { { let __a: *const _ = &mut __tmp_0; let __b: *const _ = &mut __tmp_1; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -32,7 +35,10 @@ unsafe fn main_0() -> i32 { { let __a: *const _ = &mut __tmp_2; let __b: *const _ = &mut __tmp_3; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 01d48a3621..ee6db7df92 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -107,6 +107,22 @@ 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 Cpp17EqualityComparable for Counter { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Counter, + |__lhs, __rhs| { ({ Counter::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -196,8 +212,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!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ WeaklyEqualityComparableWith::equal(c2.as_pointer(), c1.as_pointer(),) })); + assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ Counter::operator_eq(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 })); @@ -210,12 +226,4 @@ 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 c4bb6c21e0..3de54a513f 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -41,9 +41,10 @@ pub fn sum_1(v: Ptr>) -> i32 { { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { - (__tmp_0,) => { - WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_0).clone()) - } + (__tmp_0,) => WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind(it.as_pointer()), + LvalueRef::>>::bind((__tmp_0).clone()), + ), } { 'for_body: { total += (({ (*it.borrow()).iter_deref() }).read()); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 36d2db9828..03f6c5865b 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -473,7 +473,10 @@ fn main_0() -> i32 { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index d094221826..4ce59b4127 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -28,12 +28,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_2.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -43,7 +44,10 @@ fn main_0() -> i32 { assert!( match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { (__tmp_3,) => { - WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_3).clone()) + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind(it.as_pointer()), + LvalueRef::>>::bind((__tmp_3).clone()), + ) } } ); diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index 7fc1217ace..cb6c71c4a5 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -36,7 +36,10 @@ fn main_0() -> i32 { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/emplace_receiver_order.rs b/tests/unit/out/refcount/emplace_receiver_order.rs index cb369b1ee9..c80384277b 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -43,8 +43,10 @@ fn main_0() -> i32 { 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()) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -70,8 +72,10 @@ fn main_0() -> i32 { 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()) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index f665062c8d..ce938caf51 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -25,6 +25,21 @@ 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 Cpp17EqualityComparable for P { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + P, + |__lhs, __rhs| { ({ P::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -53,12 +68,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_3.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -66,7 +82,10 @@ fn main_0() -> i32 { }), )); 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()), + (__tmp_4,) => WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind(it.as_pointer()), + LvalueRef::>>::bind((__tmp_4).clone()), + ), }; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { @@ -95,40 +114,15 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - let mut m_result_true: bool = - WeaklyEqualityComparableWith::not_equal(m_begin.as_pointer(), m_end.as_pointer()); - assert!( - ((v_result_true) && (m_result_true)) - && (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()) - } - }) + let mut m_result_true: bool = WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::, Value)>>>::bind( + m_begin.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + m_end.as_pointer(), + ), ); + assert!(( ( v_result_true ) && ( m_result_true ) ) && ( 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 as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef:: >>::bind(__it.as_pointer()), LvalueRef:: >>::bind(__last.as_pointer()), ) && !>::is_equal( LvalueRef::>::bind(__it.borrow().iter_deref()), LvalueRef::>::bind(__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,) => { Cpp17EqualityComparable::is_equal( LvalueRef:: >>::bind((__tmp_8 ).clone()), LvalueRef:: >>::bind((__tmp_10 ).clone()), ) } } ) ); let w: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5]))); assert!(match ( Rc::new(RefCell::new( @@ -139,12 +133,12 @@ fn main_0() -> i32 { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_12.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } @@ -156,7 +150,10 @@ fn main_0() -> i32 { 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()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_11).clone()), + LvalueRef::>>::bind((__tmp_13).clone()), + ) } }); assert!(match ( @@ -168,12 +165,12 @@ fn main_0() -> i32 { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_15.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } @@ -185,7 +182,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(w.decay().end())).as_pointer(), ) { (__tmp_14, __tmp_16) => { - WeaklyEqualityComparableWith::equal((__tmp_14).clone(), (__tmp_16).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_14).clone()), + LvalueRef::>>::bind((__tmp_16).clone()), + ) } }); assert!(match ( @@ -197,12 +197,12 @@ fn main_0() -> i32 { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_18.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } @@ -214,7 +214,10 @@ fn main_0() -> i32 { 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()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_17).clone()), + LvalueRef::>>::bind((__tmp_19).clone()), + ) } }); let p: Value> = Rc::new(RefCell::new(Vec::from([ @@ -231,12 +234,12 @@ fn main_0() -> i32 { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !

>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind((__tmp_21.as_pointer()).clone()), ) { __it.borrow_mut().iter_inc(); } @@ -248,14 +251,12 @@ fn main_0() -> i32 { 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()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_20).clone()), + LvalueRef::>>::bind((__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 b2098a0d9d..e0728e7d98 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -9,10 +9,13 @@ use std::rc::{Rc, Weak}; pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } -pub fn scaled_1(v: Ptr, mut k: i32) -> i32 { +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 { return ({ v.with(|__s| __s.x) } * { k }); } -pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { +pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } #[derive( @@ -34,7 +37,17 @@ pub struct V { #[offset(0)] pub x: i32, } -pub fn get_3(w: Ptr) -> i32 { +impl Cpp17EqualityComparable for V { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + V, + |__lhs, __rhs| { ({ operator_eq_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn get_4(w: Ptr) -> i32 { return w.with(|__s| __s.x); } #[derive( @@ -56,7 +69,7 @@ pub struct W_int_ { #[offset(0)] pub x: i32, } -pub fn get_4(w: Ptr) -> i64 { +pub fn get_5(w: Ptr) -> i64 { return w.with(|__s| __s.x); } #[derive( @@ -97,7 +110,7 @@ pub struct D { #[offset(0)] pub x: i32, } -pub fn declared_then_defined_5(d: Ptr) -> i32 { +pub fn declared_then_defined_6(d: Ptr) -> i32 { return (d.with(|__s| __s.x) + 1); } pub fn main() { @@ -109,21 +122,16 @@ 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!(({ 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)); + 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)); 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_3(wi.as_pointer(),) }) == 5)); - assert!((({ get_4(wl.as_pointer(),) }) == 6_i64)); + assert!((({ get_4(wi.as_pointer(),) }) == 5)); + assert!((({ get_5(wl.as_pointer(),) }) == 6_i64)); let d: Value = Rc::new(RefCell::new(D { x: 7 })); - assert!((({ declared_then_defined_5(d.as_pointer(),) }) == 8)); + assert!((({ declared_then_defined_6(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/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 91d788b618..ad2773314a 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -18,9 +18,9 @@ thread_local!( ({ __tmp_0 = Rc::new(RefCell::new(0)); __tmp_1 = Rc::new(RefCell::new(0)); - if LessThanComparable::less( - __tmp_0.as_pointer().clone(), - __tmp_1.as_pointer().clone(), + if ::is_less( + LvalueRef::>::bind(__tmp_0.as_pointer().clone()), + LvalueRef::>::bind(__tmp_1.as_pointer().clone()), ) { __tmp_0.as_pointer() } else { @@ -46,9 +46,9 @@ thread_local!( let __rhs = { __tmp_2 = Rc::new(RefCell::new(6)); __tmp_3 = Rc::new(RefCell::new(5)); - (if LessThanComparable::less( - __tmp_2.as_pointer().clone(), - __tmp_3.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_2.as_pointer().clone()), + LvalueRef::>::bind(__tmp_3.as_pointer().clone()), ) { __tmp_2.as_pointer() } else { @@ -71,9 +71,9 @@ thread_local!( let __rhs = { __tmp_4 = Rc::new(RefCell::new(1)); __tmp_5 = Rc::new(RefCell::new(2)); - (if LessThanComparable::less( - __tmp_4.as_pointer().clone(), - __tmp_5.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_4.as_pointer().clone()), + LvalueRef::>::bind(__tmp_5.as_pointer().clone()), ) { __tmp_5.as_pointer() } else { @@ -140,9 +140,9 @@ thread_local!( __tmp_7 = Rc::new(RefCell::new(Box::new([{ __tmp_8 = Rc::new(RefCell::new(4)); __tmp_9 = Rc::new(RefCell::new(3)); - (if LessThanComparable::less( - __tmp_8.as_pointer().clone(), - __tmp_9.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_8.as_pointer().clone()), + LvalueRef::>::bind(__tmp_9.as_pointer().clone()), ) { __tmp_8.as_pointer() } else { @@ -156,9 +156,9 @@ thread_local!( value: { __tmp_11 = Rc::new(RefCell::new(5)); __tmp_12 = Rc::new(RefCell::new(6)); - (if LessThanComparable::less( - __tmp_11.as_pointer().clone(), - __tmp_12.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_11.as_pointer().clone()), + LvalueRef::>::bind(__tmp_12.as_pointer().clone()), ) { __tmp_12.as_pointer() } else { @@ -183,9 +183,9 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_13 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if LessThanComparable::less( - __tmp_13.as_pointer().clone(), - left_10.with(|v| v.as_pointer()).clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_13.as_pointer().clone()), + LvalueRef::>::bind(left_10.with(|v| v.as_pointer()).clone()), ) { __tmp_13.as_pointer() } else { @@ -205,9 +205,9 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_14 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if LessThanComparable::less( - left_10.with(|v| v.as_pointer()).clone(), - __tmp_14.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(left_10.with(|v| v.as_pointer()).clone()), + LvalueRef::>::bind(__tmp_14.as_pointer().clone()), ) { __tmp_14.as_pointer() } else { @@ -245,9 +245,9 @@ thread_local!( __tmp_15 = Rc::new(RefCell::new(Box::new([{ __tmp_16 = Rc::new(RefCell::new(7)); __tmp_17 = Rc::new(RefCell::new(8)); - (if LessThanComparable::less( - __tmp_16.as_pointer().clone(), - __tmp_17.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_16.as_pointer().clone()), + LvalueRef::>::bind(__tmp_17.as_pointer().clone()), ) { __tmp_17.as_pointer() } else { @@ -261,9 +261,9 @@ thread_local!( value: { __tmp_19 = Rc::new(RefCell::new(10)); __tmp_20 = Rc::new(RefCell::new(9)); - (if LessThanComparable::less( - __tmp_19.as_pointer().clone(), - __tmp_20.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_19.as_pointer().clone()), + LvalueRef::>::bind(__tmp_20.as_pointer().clone()), ) { __tmp_19.as_pointer() } else { diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index d4c16f8bde..2c2078bd22 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -230,7 +230,10 @@ fn main_0() -> i32 { }), ), )); - let mut x1: u32 = if WeaklyEqualityComparableWith::equal(it.as_pointer(), end.as_pointer()) { + let mut x1: u32 = if Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind(it.as_pointer()), + LvalueRef::, Value)>>>::bind(end.as_pointer()), + ) { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -244,9 +247,14 @@ fn main_0() -> i32 { )>>::from(({ (*end.borrow()).clone() })))) .as_pointer(),) { - (__tmp_20,) => { - WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_20).clone()) - } + (__tmp_20,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + const_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_20).clone(), + ), + ), } { 0_u32 } else { @@ -261,7 +269,14 @@ fn main_0() -> i32 { )) .as_pointer(),) { - (__tmp_21,) => WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_21).clone()), + (__tmp_21,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_21).clone(), + ), + ), } { 0_u32 } else { @@ -279,9 +294,14 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_22,) => { - WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_22).clone()) - } + (__tmp_22,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + const_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_22).clone(), + ), + ), } { 0_u32 } else { @@ -387,7 +407,14 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_28, __tmp_30) => { - WeaklyEqualityComparableWith::not_equal((__tmp_28).clone(), (__tmp_30).clone()) + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::, Value)>>>::bind( + (__tmp_28).clone(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_30).clone(), + ), + ) } }); Map::erase((r).clone(), &({ (*it4.borrow()).clone() })); @@ -410,7 +437,14 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_31, __tmp_33) => { - WeaklyEqualityComparableWith::equal((__tmp_31).clone(), (__tmp_33).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + (__tmp_31).clone(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_33).clone(), + ), + ) } }); match (Rc::new(RefCell::new(7_i16)).as_pointer(),) { @@ -470,7 +504,14 @@ fn main_0() -> i32 { .as_pointer(),) { (__tmp_40,) => { - WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_40).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + next.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_40).clone(), + ), + ) } }); { @@ -483,7 +524,14 @@ fn main_0() -> i32 { .as_pointer(),) { (__tmp_42,) => { - WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_42).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + next.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_42).clone(), + ), + ) } }); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); @@ -505,7 +553,14 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_43, __tmp_45) => { - WeaklyEqualityComparableWith::equal((__tmp_43).clone(), (__tmp_45).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + (__tmp_43).clone(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_45).clone(), + ), + ) } }); let other_map: Value< diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index c8c3306cea..b343ed6a3f 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -41,12 +41,20 @@ impl Key { field!(this, k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl LessThanComparable for Key { - fn less(this: Ptr, o: Ptr) -> bool { + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.k) } < { o.with(|__s| __s.k) }); } } +impl LessThanComparable for Key { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Key, + |__lhs, __rhs| { ({ Key::operator_lt((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); Key::constructor_1(__return.clone(), k); diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 9140286dc0..653d98989c 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -30,10 +30,31 @@ pub struct Key { #[offset(4)] pub identity: i32, } +impl Cpp17EqualityComparable for Key { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Key, + |__lhs, __rhs| { ({ operator_eq_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for Key { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Key, + |__lhs, __rhs| { ({ operator_lt_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_lt_2(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); +} +pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); } #[derive( Copy, @@ -85,11 +106,7 @@ fn main_0() -> i32 { identity: 7, })); ok = { - ((ok as i32) - & ((WeaklyEqualityComparableWith::equal( - distinct_a.as_pointer(), - distinct_b.as_pointer(), - )) as i32)) + ((ok as i32) & ((operator_eq_1(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) != 0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -126,9 +143,14 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_0,) => { - WeaklyEqualityComparableWith::equal(a_it.as_pointer(), (__tmp_0).clone()) - } + (__tmp_0,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + a_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_0).clone(), + ), + ), }) as i32)) != 0 }; @@ -139,9 +161,14 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_1,) => { - WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_1).clone()) - } + (__tmp_1,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + b_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_1).clone(), + ), + ), }) as i32)) != 0 }; @@ -154,9 +181,14 @@ fn main_0() -> i32 { )) .as_pointer(),) { - (__tmp_2,) => { - WeaklyEqualityComparableWith::not_equal(b_it.as_pointer(), (__tmp_2).clone()) - } + (__tmp_2,) => WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::, Value)>>>::bind( + b_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_2).clone(), + ), + ), }) as i32)) != 0 }; @@ -176,11 +208,7 @@ fn main_0() -> i32 { != 0 }; ok = { - ((ok as i32) - & ((WeaklyEqualityComparableWith::equal( - distinct_a.as_pointer(), - distinct_b.as_pointer(), - )) as i32)) + ((ok as i32) & ((operator_eq_1(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) != 0 }; let mut distinct_count: usize = 0_usize; @@ -223,12 +251,7 @@ fn main_0() -> i32 { })); ok = { ((ok as i32) - & (!({ - WeaklyEqualityComparableWith::equal( - equivalent_a.as_pointer(), - equivalent_b.as_pointer(), - ) - }) as i32)) + & (!({ operator_eq_1(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) != 0 }; let equivalent: Value, Value)>> = @@ -260,53 +283,14 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (((*equivalent.borrow()).len() == 1_usize) as i32)) != 0 }; if reused { ok = { - ((ok as i32) - & ((match (Rc::new(RefCell::new( - equivalent - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()), - )) - .as_pointer(),) - { - (__tmp_3,) => WeaklyEqualityComparableWith::not_equal( - first_it.as_pointer(), - (__tmp_3).clone(), - ), - }) as i32)) - != 0 + ( ( ok as i32 ) & ( ( ( match (Rc::new(RefCell::new(equivalent .as_pointer() .with(|__m: &Map, Value)>| __m.end()) )).as_pointer(),) { (__tmp_3,) => { WeaklyEqualityComparableWith::is_not_equal( LvalueRef::, Value) > >>::bind(first_it .as_pointer() ), LvalueRef::, Value) > >>::bind((__tmp_3 ).clone()), ) } } ) ) as i32 ) ) != 0 }; ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; ok = { - ((ok 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 as i32 ) & ( ( ( match (Rc::new(RefCell::new(equivalent .as_pointer() .with(|__m: &Map, Value)>| __m.find(&equivalent_a .as_pointer() )) )).as_pointer(),) { (__tmp_4,) => { Cpp17EqualityComparable::is_equal( LvalueRef::, Value) > >>::bind(first_it .as_pointer() ), LvalueRef::, Value) > >>::bind((__tmp_4 ).clone()), ) } } ) ) as i32 ) ) != 0 }; ok = { - ((ok 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 as i32 ) & ( ( ( match (Rc::new(RefCell::new(equivalent .as_pointer() .with(|__m: &Map, Value)>| __m.find(&equivalent_b .as_pointer() )) )).as_pointer(),) { (__tmp_5,) => { Cpp17EqualityComparable::is_equal( LvalueRef::, Value) > >>::bind(first_it .as_pointer() ), LvalueRef::, Value) > >>::bind((__tmp_5 ).clone()), ) } } ) ) as i32 ) ) != 0 }; ok = { ((ok as i32) @@ -347,12 +331,7 @@ fn main_0() -> i32 { } ok = { ((ok as i32) - & (!({ - WeaklyEqualityComparableWith::equal( - equivalent_a.as_pointer(), - equivalent_b.as_pointer(), - ) - }) as i32)) + & (!({ operator_eq_1(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) != 0 }; let later_key: Value = Rc::new(RefCell::new(Key { @@ -370,20 +349,7 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (((*equivalent.borrow()).len() == 2_usize) as i32)) != 0 }; if reused { ok = { - ((ok 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 as i32 ) & ( ( ( match (Rc::new(RefCell::new(equivalent .as_pointer() .with(|__m: &Map, Value)>| __m.find(&equivalent_a .as_pointer() )) )).as_pointer(),) { (__tmp_6,) => { Cpp17EqualityComparable::is_equal( LvalueRef::, Value) > >>::bind(first_it .as_pointer() ), LvalueRef::, Value) > >>::bind((__tmp_6 ).clone()), ) } } ) ) as i32 ) ) != 0 }; ok = { ((ok as i32) @@ -447,9 +413,14 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_7,) => { - WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_7).clone()) - } + (__tmp_7,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + matched_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_7).clone(), + ), + ), }) as i32)) != 0 }; @@ -484,9 +455,14 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_8,) => { - WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_8).clone()) - } + (__tmp_8,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + matched_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_8).clone(), + ), + ), }) as i32)) != 0 }; @@ -507,11 +483,6 @@ 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 9d4c95638a..02229caf6b 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -307,7 +307,7 @@ fn main_0() -> i32 { as i32)) != 0 }; - 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()) } } ; + 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,) => { Cpp17EqualityComparable::is_equal( LvalueRef::, Value) > >>::bind(({ (*result.borrow()) .0 .as_pointer() })), LvalueRef::, Value) > >>::bind((__tmp_6 ).clone()), ) } } ; ok = { ((ok as i32) & (found as i32)) != 0 }; ok = { ((ok as i32) diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 754e499b86..953c1d18d2 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -53,11 +53,19 @@ impl Bag { } } impl LessThanComparable for Bag { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Bag, + |__lhs, __rhs| { ({ operator_lt_4((__lhs).clone(), (__rhs).clone(),) }) } + ); } -pub fn make_4(__return: Ptr, mut n: i32) { +pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); +} +pub fn make_5(__return: Ptr, mut n: i32) { Bag::constructor_1(__return.clone(), n); return; } @@ -72,38 +80,49 @@ fn main_0() -> i32 { let x4: Value = Rc::new(RefCell::new(20)); let mut p1: Ptr = (x1.as_pointer()); let mut p2: Ptr = (x2.as_pointer()); - let mut r1: i32 = - (if LessThanComparable::less(x1.as_pointer().clone(), x2.as_pointer().clone()) { - x2.as_pointer() - } else { - x1.as_pointer() - } - .read()); - let mut r2: i32 = - (if LessThanComparable::less(x4.as_pointer().clone(), x3.as_pointer().clone()) { - x4.as_pointer() - } else { - x3.as_pointer() - } - .read()); - let mut r3: i32 = - (if LessThanComparable::less((p1).clone().clone(), x2.as_pointer().clone()) { - x2.as_pointer() - } else { - (p1).clone() - } - .read()); - let mut r4: i32 = - (if LessThanComparable::less(x3.as_pointer().clone(), (p2).clone().clone()) { - x3.as_pointer() - } else { - (p2).clone() - } - .read()); + let mut r1: i32 = (if ::is_less( + LvalueRef::>::bind(x1.as_pointer().clone()), + LvalueRef::>::bind(x2.as_pointer().clone()), + ) { + x2.as_pointer() + } else { + x1.as_pointer() + } + .read()); + let mut r2: i32 = (if ::is_less( + LvalueRef::>::bind(x4.as_pointer().clone()), + LvalueRef::>::bind(x3.as_pointer().clone()), + ) { + x4.as_pointer() + } else { + x3.as_pointer() + } + .read()); + let mut r3: i32 = (if ::is_less( + LvalueRef::>::bind((p1).clone().clone()), + LvalueRef::>::bind(x2.as_pointer().clone()), + ) { + x2.as_pointer() + } else { + (p1).clone() + } + .read()); + let mut r4: i32 = (if ::is_less( + LvalueRef::>::bind(x3.as_pointer().clone()), + LvalueRef::>::bind((p2).clone().clone()), + ) { + x3.as_pointer() + } else { + (p2).clone() + } + .read()); let mut r5: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(30)); let __tmp_1: Value = Rc::new(RefCell::new(40)); - (if LessThanComparable::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { + (if ::is_less( + LvalueRef::>::bind(__tmp_0.as_pointer().clone()), + LvalueRef::>::bind(__tmp_1.as_pointer().clone()), + ) { __tmp_1.as_pointer() } else { __tmp_0.as_pointer() @@ -116,10 +135,19 @@ fn main_0() -> i32 { 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()) { + if as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { __it.borrow_mut().iter_inc(); - while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - if LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { + if ::is_less( + LvalueRef::>::bind(__best.iter_deref()), + LvalueRef::>::bind(__it.borrow().iter_deref()), + ) { __best = __it.borrow().clone(); } __it.borrow_mut().iter_inc(); @@ -131,7 +159,10 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { (__tmp_2, __tmp_3) => { - if LessThanComparable::less((__tmp_2).clone().clone(), (__tmp_3).clone().clone()) { + if ::is_less( + LvalueRef::>::bind((__tmp_2).clone().clone()), + LvalueRef::>::bind((__tmp_3).clone().clone()), + ) { (__tmp_3).clone() } else { (__tmp_2).clone() @@ -145,7 +176,10 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { (__tmp_4, __tmp_5) => { - if LessThanComparable::less((__tmp_5).clone().clone(), (__tmp_4).clone().clone()) { + if ::is_less( + LvalueRef::>::bind((__tmp_5).clone().clone()), + LvalueRef::>::bind((__tmp_4).clone().clone()), + ) { (__tmp_5).clone() } else { (__tmp_4).clone() @@ -163,18 +197,18 @@ fn main_0() -> i32 { let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { - ({ make_4(Ptr::clone(&__tmp_7.as_pointer()), 1) }); + ({ make_5(Ptr::clone(&__tmp_7.as_pointer()), 1) }); __tmp_7.as_pointer() }, { - ({ make_4(Ptr::clone(&__tmp_9.as_pointer()), 2) }); + ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 2) }); __tmp_9.as_pointer() }, ) { (__tmp_6, __tmp_8) => { - if LessThanComparable::less( - (__tmp_6).clone().clone(), - (__tmp_8).clone().clone(), + if ::is_less( + LvalueRef::>::bind((__tmp_6).clone().clone()), + LvalueRef::>::bind((__tmp_8).clone().clone()), ) { (__tmp_8).clone() } else { @@ -189,18 +223,18 @@ fn main_0() -> i32 { let __tmp_13: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { - ({ make_4(Ptr::clone(&__tmp_11.as_pointer()), 1) }); + ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 1) }); __tmp_11.as_pointer() }, { - ({ make_4(Ptr::clone(&__tmp_13.as_pointer()), 2) }); + ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 2) }); __tmp_13.as_pointer() }, ) { (__tmp_10, __tmp_12) => { - if LessThanComparable::less( - (__tmp_12).clone().clone(), - (__tmp_10).clone().clone(), + if ::is_less( + LvalueRef::>::bind((__tmp_12).clone().clone()), + LvalueRef::>::bind((__tmp_10).clone().clone()), ) { (__tmp_12).clone() } else { @@ -222,9 +256,9 @@ fn main_0() -> i32 { 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_14,) => { - if LessThanComparable::less( - __tmp_15.as_pointer().clone(), - (__tmp_14).clone().clone(), + if ::is_less( + LvalueRef::>::bind(__tmp_15.as_pointer().clone()), + LvalueRef::>::bind((__tmp_14).clone().clone()), ) { (__tmp_14).clone() } else { diff --git a/tests/unit/out/refcount/min_max_ptr2ptr.rs b/tests/unit/out/refcount/min_max_ptr2ptr.rs index 016528fab0..69d6fd3793 100644 --- a/tests/unit/out/refcount/min_max_ptr2ptr.rs +++ b/tests/unit/out/refcount/min_max_ptr2ptr.rs @@ -17,13 +17,19 @@ fn main_0() -> i32 { let pb: Value> = Rc::new(RefCell::new((b.as_pointer()))); let mut ppa: Ptr> = (pa.as_pointer()); let mut ppb: Ptr> = (pb.as_pointer()); - let mut r1: i32 = (if LessThanComparable::less((ppa.read()).clone(), (ppb.read()).clone()) { + let mut r1: i32 = (if ::is_less( + LvalueRef::>::bind((ppa.read()).clone()), + LvalueRef::>::bind((ppb.read()).clone()), + ) { (ppb.read()) } else { (ppa.read()) } .read()); - let mut r2: i32 = (if LessThanComparable::less((ppb.read()).clone(), (ppa.read()).clone()) { + let mut r2: i32 = (if ::is_less( + LvalueRef::>::bind((ppb.read()).clone()), + LvalueRef::>::bind((ppa.read()).clone()), + ) { (ppb.read()) } else { (ppa.read()) @@ -36,7 +42,10 @@ fn main_0() -> i32 { assert!( ({ ({ - (if LessThanComparable::less(high.as_pointer().clone(), low.as_pointer().clone()) { + (if as LessThanComparable>::is_less( + LvalueRef::>>::bind(high.as_pointer().clone()), + LvalueRef::>>::bind(low.as_pointer().clone()), + ) { high.as_pointer() } else { low.as_pointer() @@ -48,7 +57,10 @@ fn main_0() -> i32 { assert!( ({ ({ - (if LessThanComparable::less(low.as_pointer().clone(), high.as_pointer().clone()) { + (if as LessThanComparable>::is_less( + LvalueRef::>>::bind(low.as_pointer().clone()), + LvalueRef::>>::bind(high.as_pointer().clone()), + ) { low.as_pointer() } else { high.as_pointer() @@ -60,7 +72,10 @@ fn main_0() -> i32 { assert!( ({ ({ - (if LessThanComparable::less(low.as_pointer().clone(), high.as_pointer().clone()) { + (if as LessThanComparable>::is_less( + LvalueRef::>>::bind(low.as_pointer().clone()), + LvalueRef::>>::bind(high.as_pointer().clone()), + ) { high.as_pointer() } else { low.as_pointer() @@ -72,7 +87,10 @@ fn main_0() -> i32 { assert!( ({ ({ - (if LessThanComparable::less(high.as_pointer().clone(), low.as_pointer().clone()) { + (if as LessThanComparable>::is_less( + LvalueRef::>>::bind(high.as_pointer().clone()), + LvalueRef::>>::bind(low.as_pointer().clone()), + ) { low.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 5a2c77a088..218e676e4b 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -27,6 +27,32 @@ 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 Cpp17EqualityComparable for Eq { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Eq, + |__lhs, __rhs| { ({ Eq::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Eq { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Eq, + |__lhs, __rhs| { !({ Eq::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} #[derive( Copy, Clone, @@ -38,10 +64,8 @@ pub struct Eq { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct Cmp { @@ -50,9 +74,8 @@ pub struct Cmp { #[offset(4)] pub b: i32, } -impl ThreeWayComparable for Cmp { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +impl Cmp { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( @@ -73,11 +96,82 @@ impl ThreeWayComparable for 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 Cpp17EqualityComparable for Cmp { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Cmp, + |__lhs, __rhs| { ({ Cmp::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Cmp { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Cmp, + |__lhs, __rhs| { !({ Cmp::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for Cmp { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lt(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for Cmp { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for Cmp { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -90,19 +184,19 @@ impl LessThanComparable for Cmp { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct Both { #[offset(0)] pub a: i32, } -impl ThreeWayComparable for Both { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +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) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( @@ -115,10 +209,77 @@ impl ThreeWayComparable for Both { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } +impl Cpp17EqualityComparable for Both { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Both, + |__lhs, __rhs| { ({ Both::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Both { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Both, + |__lhs, __rhs| { !({ Both::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for Both { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_lt(({ Both::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for Both { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Both::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Both::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ Both::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for Both { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Both::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -131,10 +292,8 @@ impl LessThanComparable for Both { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(OrdOnly::operator_cmp)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct OrdOnly { @@ -156,9 +315,48 @@ impl OrdOnly { } } impl LessThanComparable for OrdOnly { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(OrdOnly::operator_cmp(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_lt(({ OrdOnly::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for OrdOnly { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_gt(({ OrdOnly::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ OrdOnly::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ OrdOnly::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); } #[derive( Copy, @@ -171,19 +369,16 @@ impl LessThanComparable for OrdOnly { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -impl ThreeWayComparable for Inner { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +impl Inner { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( @@ -195,11 +390,81 @@ impl ThreeWayComparable for 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 Cpp17EqualityComparable for Inner { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Inner, + |__lhs, __rhs| { ({ Inner::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Inner { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Inner, + |__lhs, __rhs| { !({ Inner::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for Inner { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_lt(({ Inner::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for Inner { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Inner::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Inner::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ Inner::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for Inner { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Inner::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -212,10 +477,8 @@ impl LessThanComparable for Inner { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct Outer { @@ -225,12 +488,11 @@ pub struct Outer { #[offset(4)] pub y: i32, } -impl ThreeWayComparable for Outer { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +impl Outer { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new( - ({ ThreeWayComparable::three_way(field_ptr!(this, i), field_ptr!(_a0, i)) }), + ({ Inner::operator_cmp(field_ptr!(this, i), field_ptr!(_a0, i)) }), )); if !(libcc2rs::is_eq(({ (*cmp.borrow()) }))) { return (*cmp.borrow_mut()); @@ -247,11 +509,82 @@ impl ThreeWayComparable for 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 Cpp17EqualityComparable for Outer { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Outer, + |__lhs, __rhs| { ({ Outer::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Outer { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Outer, + |__lhs, __rhs| { !({ Outer::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for Outer { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_lt(({ Outer::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for Outer { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Outer::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Outer::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ Outer::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for Outer { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Outer::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -272,9 +605,14 @@ pub struct Secondary { #[offset(0)] pub a: i32, } -impl ThreeWayComparable for Secondary { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +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) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( @@ -286,11 +624,80 @@ impl ThreeWayComparable for Secondary { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } + pub fn operator_lt(this: Ptr, _a0: Ptr) -> bool { + return libcc2rs::is_lt(({ Secondary::operator_cmp((this).clone(), (_a0).clone()) })); + } + pub fn operator_ge(this: Ptr, _a0: Ptr) -> bool { + return libcc2rs::is_gteq(({ Secondary::operator_cmp((this).clone(), (_a0).clone()) })); + } +} +impl Cpp17EqualityComparable for Secondary { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Secondary, + |__lhs, __rhs| { ({ Secondary::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Secondary { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Secondary, + |__lhs, __rhs| { ({ Secondary::operator_ne((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for Secondary { - fn less(this: Ptr, _a0: Ptr) -> bool { - return libcc2rs::is_lt(({ ThreeWayComparable::three_way((this).clone(), (_a0).clone()) })); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Secondary, + |__lhs, __rhs| { ({ Secondary::operator_lt((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl PartiallyOrderedWith for Secondary { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Secondary, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Secondary::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Secondary, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Secondary::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Secondary, + |__lhs, __rhs| { ({ Secondary::operator_ge((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl ThreeWayComparable for Secondary { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Secondary::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Clone, @@ -302,10 +709,8 @@ impl LessThanComparable for Secondary { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(8)] pub struct PtrMember { @@ -313,9 +718,8 @@ pub struct PtrMember { #[byte_size(8)] pub p: Ptr, } -impl ThreeWayComparable for PtrMember { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { +impl PtrMember { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> libcc2rs::StrongOrdering { { let cmp: Value = Rc::new(RefCell::new( libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( @@ -329,11 +733,81 @@ impl ThreeWayComparable for 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 Cpp17EqualityComparable for PtrMember { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + PtrMember, + |__lhs, __rhs| { ({ PtrMember::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for PtrMember { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + PtrMember, + |__lhs, __rhs| { !({ PtrMember::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for PtrMember { - fn less(this: Ptr, _a0: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), _a0.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_lt(({ PtrMember::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for PtrMember { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_gt(({ PtrMember::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ PtrMember::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ PtrMember::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for PtrMember { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ PtrMember::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } pub fn main() { __cpp2rust_init_globals(); @@ -343,22 +817,22 @@ 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!(({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ Eq::operator_eq(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 })); let c4: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 9 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(c1.as_pointer(), c2.as_pointer(),) }) + ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(c3.as_pointer(), c4.as_pointer(),) }) + ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) )); - assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c1.as_pointer(),) })); + assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); assert!({ let __a = libcc2rs::PartialOrdering::from( - ({ ThreeWayComparable::three_way(c1.as_pointer(), c2.as_pointer()) }), + ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer()) }), ); let __b = libcc2rs::PartialOrdering::from( ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }), @@ -370,9 +844,9 @@ fn main_0() -> i32 { let b1: Value = Rc::new(RefCell::new(Both { a: 1 })); let b2: Value = Rc::new(RefCell::new(Both { a: 2 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(b1.as_pointer(), b2.as_pointer(),) }) + ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) )); - assert!(({ WeaklyEqualityComparableWith::equal(b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ Both::operator_eq(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!(libcc2rs::is_lt( @@ -402,12 +876,12 @@ fn main_0() -> i32 { y: 9, })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(x1.as_pointer(), x2.as_pointer(),) }) + ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) )); - assert!(({ WeaklyEqualityComparableWith::equal(x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); assert!({ let __a = libcc2rs::PartialOrdering::from( - ({ ThreeWayComparable::three_way(x2.as_pointer(), x1.as_pointer()) }), + ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer()) }), ); let __b = libcc2rs::PartialOrdering::from( ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }), @@ -418,10 +892,10 @@ fn main_0() -> i32 { }); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ LessThanComparable::less(s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater_equal(s2.as_pointer(), s1.as_pointer(),) })); - assert!(!({ LessThanComparable::less(s2.as_pointer(), s1.as_pointer(),) })); + assert!(({ Secondary::operator_ne(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(),) })); let arr: Value> = Rc::new(RefCell::new(Box::new([0, 0]))); let p1: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); let p2: Value = Rc::new(RefCell::new(PtrMember { @@ -429,12 +903,12 @@ fn main_0() -> i32 { })); let p3: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(p1.as_pointer(), p2.as_pointer(),) }) + ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) )); - assert!(({ WeaklyEqualityComparableWith::equal(p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); assert!({ let __a = libcc2rs::PartialOrdering::from( - ({ ThreeWayComparable::three_way(p2.as_pointer(), p1.as_pointer()) }), + ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer()) }), ); let __b = libcc2rs::PartialOrdering::from( ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }), @@ -445,61 +919,4 @@ fn main_0() -> i32 { }); return 0; } -impl PartiallyOrderedWith for Secondary { - fn greater_equal(this: Ptr, _a0: Ptr) -> bool { - return libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way((this).clone(), (_a0).clone()) }), - ); - } - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } - fn greater(lhs: Ptr, rhs: Ptr) -> bool { - libcc2rs::is_gt(ThreeWayComparable::three_way(lhs.clone(), rhs.clone())) - } - fn less_equal(lhs: Ptr, rhs: Ptr) -> bool { - libcc2rs::is_lteq(ThreeWayComparable::three_way(lhs.clone(), rhs.clone())) - } -} -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 8601f21645..18079c2ff6 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -25,15 +25,104 @@ pub struct S { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ne_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for S { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl PartiallyOrderedWith for S { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { ({ operator_gt_3((__lhs).clone(), (__rhs).clone(),) }) } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_le_4((__lhs).clone(), (__rhs).clone(),) }) } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ge_5((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { ({ operator_lt_6((__lhs).clone(), (__rhs.read()),) }) } + ); +} +impl LessThanComparable for i32 { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_7((__lhs.read()), (__rhs).clone(),) }) } + ); +} +pub fn operator_eq_0(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); +} +pub fn operator_ne_1(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); +} +pub fn operator_lt_2(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 { + return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -pub fn operator_lt_0(a: Ptr, mut b: i32) -> bool { +pub fn operator_le_4(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 { + return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); +} +pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { return ({ a.with(|__s| __s.v) } < { b }); } -pub fn operator_lt_1(mut a: i32, b: Ptr) -> bool { +pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( @@ -55,21 +144,64 @@ pub struct V { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for V { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + V, + |__lhs, __rhs| { + ({ + operator_eq_8({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) + } + ); +} +impl WeaklyEqualityComparableWith for V { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + V, + |__lhs, __rhs| { + ({ + operator_ne_9({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) + } + ); +} impl LessThanComparable for V { - fn less(a: Ptr, b: Ptr) -> bool { - operator_lt_3(a.read(), b.read()) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + V, + |__lhs, __rhs| { + ({ + operator_lt_10({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) + } + ); } -pub fn operator_eq_4(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_2(mut a: V, mut b: V) -> bool { +pub fn operator_ne_9(mut a: V, mut b: V) -> bool { return (a.v != b.v); } -pub fn operator_lt_3(mut a: V, mut b: V) -> bool { +pub fn operator_lt_10(mut a: V, mut b: V) -> bool { return (a.v < b.v); } -pub fn operator_gt_5(mut a: V, mut b: V) -> bool { +pub fn operator_gt_11(mut a: V, mut b: V) -> bool { return (a.v > b.v); } pub fn main() { @@ -80,53 +212,23 @@ 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_4(x, z,) })); - assert!(({ operator_ne_2(x, y,) })); - assert!(({ operator_lt_3(x, y,) })); - assert!(({ operator_gt_5(y, x,) })); - assert!(!({ operator_lt_3(y, x,) })); + assert!(({ operator_eq_8(x, z,) })); + assert!(({ operator_ne_9(x, y,) })); + assert!(({ operator_lt_10(x, y,) })); + assert!(({ operator_gt_11(y, x,) })); + assert!(!({ operator_lt_10(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!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); - assert!(({ LessThanComparable::less(a.as_pointer(), b.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater(b.as_pointer(), a.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::less_equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater_equal(a.as_pointer(), c.as_pointer(),) })); - assert!(!({ LessThanComparable::less(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_lt_0(a.as_pointer(), 5,) })); - assert!(({ operator_lt_1(0, a.as_pointer(),) })); + assert!(({ operator_eq_0(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ne_1(a.as_pointer(), b.as_pointer(),) })); + assert!(({ operator_lt_2(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_lt_2(b.as_pointer(), a.as_pointer(),) })); + assert!(({ operator_lt_6(a.as_pointer(), 5,) })); + assert!(({ operator_lt_7(0, a.as_pointer(),) })); return 0; } -impl PartiallyOrderedWith for S { - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } - fn greater(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); - } - fn less_equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } <= { b.with(|__s| __s.v) }); - } - fn greater_equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); - } -} -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_2(a.read(), b.read()) - } - fn equal(a: Ptr, b: Ptr) -> bool { - operator_eq_4(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 acadd8cc62..8d7bd371d0 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -26,14 +26,93 @@ 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) }); + } + pub fn operator_gt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }); + } + pub fn operator_le(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); + } + pub fn operator_ge(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); + } pub fn operator_lt_7(this: Ptr, mut o: i32) -> bool { return (this.with(|__s| __s.v) < o); } } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_ne((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for S { - fn less(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ S::operator_lt_3((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl PartiallyOrderedWith for S { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_gt((__lhs).clone(), (__rhs).clone(),) }) } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_le((__lhs).clone(), (__rhs).clone(),) }) } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_ge((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { ({ S::operator_lt_7((__lhs).clone(), (__rhs.read()),) }) } + ); } pub fn main() { __cpp2rust_init_globals(); @@ -43,36 +122,14 @@ 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!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); - assert!(({ LessThanComparable::less(a.as_pointer(), b.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater(b.as_pointer(), a.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::less_equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ PartiallyOrderedWith::greater_equal(a.as_pointer(), c.as_pointer(),) })); - assert!(!({ LessThanComparable::less(b.as_pointer(), a.as_pointer(),) })); + assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); + assert!(({ S::operator_ne(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(),) })); + assert!(({ S::operator_ge(a.as_pointer(), c.as_pointer(),) })); + assert!(!({ S::operator_lt_3(b.as_pointer(), a.as_pointer(),) })); assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } -impl PartiallyOrderedWith for S { - fn greater(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }); - } - fn less_equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); - } - fn greater_equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); - } - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } -} -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_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index 76333aa36a..203f3aada7 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -45,6 +45,186 @@ impl S { return ({ this.with(|__s| __s.v) } >= { (((o.read()) as i32) - (('0' as i8) as i32)) }); } } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { ({ S::operator_eq((__lhs).clone(), (__rhs.read()),) }) } + ); +} +impl Cpp17EqualityComparable for i32 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0((__lhs.read()), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { ({ S::operator_ne((__lhs).clone(), (__rhs.read()),) }) } + ); +} +impl WeaklyEqualityComparableWith for i32 { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ne_1((__lhs.read()), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { ({ S::operator_lt((__lhs).clone(), (__rhs.read()),) }) } + ); +} +impl LessThanComparable for i32 { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_2((__lhs.read()), (__rhs).clone(),) }) } + ); +} +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + f64, + |__lhs, __rhs| { ({ S::operator_eq((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl Cpp17EqualityComparable for f64 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + f64, + |__lhs, __rhs| { ({ S::operator_ne((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl WeaklyEqualityComparableWith for f64 { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ne_1(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + f64, + |__lhs, __rhs| { ({ S::operator_lt((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl LessThanComparable for f64 { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_2(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + i64, + |__lhs, __rhs| { ({ S::operator_eq((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl Cpp17EqualityComparable for i64 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + i64, + |__lhs, __rhs| { ({ S::operator_ne((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl WeaklyEqualityComparableWith for i64 { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_ne_1(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + i64, + |__lhs, __rhs| { ({ S::operator_lt((__lhs).clone(), ((__rhs.read()) as i32),) }) } + ); +} +impl LessThanComparable for i64 { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_2(((__lhs.read()) as i32), (__rhs).clone(),) }) } + ); +} pub fn operator_eq_0(mut a: i32, b: Ptr) -> bool { return ({ a } == { b.with(|__s| __s.v) }); } diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index fe5d82ba36..dcb9bb8527 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -25,27 +25,168 @@ pub struct X { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for X { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_eq_0({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_eq_0({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); +} +impl WeaklyEqualityComparableWith for X { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_ne_1({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_ne_1({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); +} impl LessThanComparable for X { - fn less(a: Ptr, b: Ptr) -> bool { - ((operator_lt_4(a.read(), b.read())) != 0) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_lt_2({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_lt_2({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); +} +impl PartiallyOrderedWith for X { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_gt_3({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_gt_3({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_le_4({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_le_4({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_ge_5({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + (({ + operator_ge_5({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }) != 0) + } + ); } -pub fn operator_eq_5(mut a: X, mut b: X) -> i32 { +pub fn operator_eq_0(mut a: X, mut b: X) -> i32 { return if (a.v == b.v) { 2 } else { 0 }; } -pub fn operator_ne_0(mut a: X, mut b: X) -> i32 { +pub fn operator_ne_1(mut a: X, mut b: X) -> i32 { return if (a.v != b.v) { 3 } else { 0 }; } -pub fn operator_lt_4(mut a: X, mut b: X) -> i32 { +pub fn operator_lt_2(mut a: X, mut b: X) -> i32 { return if (a.v < b.v) { 4 } else { 0 }; } -pub fn operator_gt_1(mut a: X, mut b: X) -> i32 { +pub fn operator_gt_3(mut a: X, mut b: X) -> i32 { return if (a.v > b.v) { 5 } else { 0 }; } -pub fn operator_le_2(mut a: X, mut b: X) -> i32 { +pub fn operator_le_4(mut a: X, mut b: X) -> i32 { return if (a.v <= b.v) { 6 } else { 0 }; } -pub fn operator_ge_3(mut a: X, mut b: X) -> i32 { +pub fn operator_ge_5(mut a: X, mut b: X) -> i32 { return if (a.v >= b.v) { 7 } else { 0 }; } #[derive( @@ -133,10 +274,31 @@ impl Mixed { }; } } +impl Cpp17EqualityComparable for Mixed { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + Mixed, + |__return, __lhs, __rhs| { + __return.write(({ Mixed::operator_eq((__lhs).clone(), (__rhs).clone()) })); + }, + |__lhs, __rhs| { (({ Mixed::operator_eq((__lhs).clone(), (__rhs).clone(),) }) != 0) } + ); +} impl LessThanComparable for Mixed { - fn less(this: Ptr, o: Ptr) -> bool { - ((Mixed::operator_lt(this.clone(), o.clone())) != 0) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = i32, + Mixed, + |__return, __lhs, __rhs| { + __return.write(({ Mixed::operator_lt((__lhs).clone(), (__rhs).clone()) })); + }, + |__lhs, __rhs| { (({ Mixed::operator_lt((__lhs).clone(), (__rhs).clone(),) }) != 0) } + ); } #[derive( Copy, @@ -167,6 +329,99 @@ impl MyBool { return this.with(|__s| __s.value); } } +impl Cpp17EqualityComparable for MyBool { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } == { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl WeaklyEqualityComparableWith for MyBool { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } != { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl LessThanComparable for MyBool { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } < { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl PartiallyOrderedWith for MyBool { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } > { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } <= { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + MyBool, + |__lhs, __rhs| { + ({ (({ MyBool::to_bool((__lhs).clone()) }) as i32) } >= { + (({ MyBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl ThreeWayComparable for MyBool { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(({ MyBool::to_bool((__lhs).clone()) }) as i32), + &(({ MyBool::to_bool((__rhs).clone()) }) as i32), + )) + } + ); +} #[derive( Copy, Clone, @@ -186,22 +441,78 @@ pub struct Boolish { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for Boolish { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = MyBool, + Boolish, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_eq_6({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + ({ + MyBool::to_bool( + Rc::new(RefCell::new( + ({ + operator_eq_6({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + )) + .as_pointer(), + ) + }) + } + ); +} impl LessThanComparable for Boolish { - fn less(a: Ptr, b: Ptr) -> bool { - { - let __cmp = operator_lt_6(a.read(), b.read()); - MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) + comparison!( + LessThanComparable, + less, + is_less, + Result = MyBool, + Boolish, + |__return, __lhs, __rhs| { + __return.write( + ({ + operator_lt_7({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + ); + }, + |__lhs, __rhs| { + ({ + MyBool::to_bool( + Rc::new(RefCell::new( + ({ + operator_lt_7({ (*__lhs.upgrade().deref()) }, { + (*__rhs.upgrade().deref()) + }) + }), + )) + .as_pointer(), + ) + }) } - } + ); } -pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { +pub fn operator_eq_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); MyBool::constructor_1(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } -pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { +pub fn operator_lt_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); MyBool::constructor_1(__v.as_pointer(), (a.v < b.v)); @@ -235,6 +546,99 @@ impl RefBool { return this.with(|__s| __s.value); } } +impl Cpp17EqualityComparable for RefBool { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } == { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl WeaklyEqualityComparableWith for RefBool { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } != { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl LessThanComparable for RefBool { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } < { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl PartiallyOrderedWith for RefBool { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } > { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } <= { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + RefBool, + |__lhs, __rhs| { + ({ (({ RefBool::to_bool((__lhs).clone()) }) as i32) } >= { + (({ RefBool::to_bool((__rhs).clone()) }) as i32) + }) + } + ); +} +impl ThreeWayComparable for RefBool { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &(({ RefBool::to_bool((__lhs).clone()) }) as i32), + &(({ RefBool::to_bool((__rhs).clone()) }) as i32), + )) + } + ); +} thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); @@ -266,6 +670,10 @@ impl RefInt { return ref_true_8.with(|v| v.as_pointer()); } } +impl Cpp17EqualityComparable for RefInt { + comparison! ( Cpp17EqualityComparable , equal , is_equal , EqualResult = LvalueRef , RefInt , |__return, __lhs, __rhs| { __return .write ( LvalueRef ::bind ( ( { RefInt :: operator_eq ( (__lhs ).clone() , (__rhs ).clone() , ) } ) ) ) ; +} , |__lhs, __rhs| { ( { RefBool :: to_bool ( ( { RefInt :: operator_eq ( (__lhs ).clone() , (__rhs ).clone() , ) } ) , ) } ) } ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -274,13 +682,13 @@ 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_5(a, c,) }) == 2)); - assert!((({ operator_eq_5(a, b,) }) == 0)); - assert!((({ operator_ne_0(a, b,) }) == 3)); - assert!((({ operator_lt_4(a, b,) }) == 4)); - assert!((({ operator_gt_1(b, a,) }) == 5)); - assert!((({ operator_le_2(a, c,) }) == 6)); - assert!((({ operator_ge_3(a, c,) }) == 7)); + assert!((({ operator_eq_0(a, c,) }) == 2)); + assert!((({ operator_eq_0(a, b,) }) == 0)); + assert!((({ operator_ne_1(a, b,) }) == 3)); + assert!((({ operator_lt_2(a, b,) }) == 4)); + assert!((({ operator_gt_3(b, a,) }) == 5)); + assert!((({ operator_le_4(a, c,) }) == 6)); + assert!((({ operator_ge_5(a, c,) }) == 7)); let xs: Value> = Rc::new(RefCell::new(Box::new([X { v: 3 }, X { v: 1 }, X { v: 2 }]))); { let mut __tmp_0 = { xs.decay() }; @@ -323,14 +731,14 @@ fn main_0() -> i32 { assert!( ({ MyBool::to_bool( - Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), + Rc::new(RefCell::new(({ operator_eq_6(b1, Boolish { v: 1 }) }))).as_pointer(), ) }) ); assert!( - !({ MyBool::to_bool(Rc::new(RefCell::new(({ operator_lt_6(b2, b1,) }))).as_pointer(),) }) + !({ MyBool::to_bool(Rc::new(RefCell::new(({ operator_lt_7(b2, b1,) }))).as_pointer(),) }) ); - let mut lt: MyBool = ({ operator_lt_6(b1, b2) }); + let mut lt: MyBool = ({ operator_lt_7(b1, b2) }); assert!(lt.value); let bs: Value> = Rc::new(RefCell::new(Box::new([ Boolish { v: 3 }, @@ -360,12 +768,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(ri2.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -373,49 +782,6 @@ fn main_0() -> i32 { ); return 0; } -impl PartiallyOrderedWith for X { - fn less(lhs: Ptr, rhs: Ptr) -> bool { - ::less(lhs, rhs) - } - fn greater(lhs: Ptr, rhs: Ptr) -> bool { - ((operator_gt_1(lhs.read(), rhs.read())) != 0) - } - fn less_equal(lhs: Ptr, rhs: Ptr) -> bool { - ((operator_le_2(lhs.read(), rhs.read())) != 0) - } - fn greater_equal(lhs: Ptr, rhs: Ptr) -> bool { - ((operator_ge_3(lhs.read(), rhs.read())) != 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_5(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 100f191845..76527d7433 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -6,10 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -impl LessThanComparable for S { - fn less(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); - } +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 { + return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, @@ -28,6 +29,26 @@ impl S { field!(this, data_).write(data); } } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { ({ operator_lt_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -36,14 +57,9 @@ fn main_0() -> i32 { object!(a, S::constructor_1(1)); object!(b, S::constructor_1(2)); object!(c, S::constructor_1(1)); - assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ LessThanComparable::less(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ LessThanComparable::less(b.as_pointer(), a.as_pointer(),) })); + 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(),) })); 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 73a37d4914..1aaa95e6cc 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -6,6 +6,10 @@ 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, @@ -27,20 +31,40 @@ pub struct Defaulted { #[offset(4)] pub b: i32, } -impl ThreeWayComparable for DefaultedOrd { - type Category = libcc2rs::StrongOrdering; - fn three_way(_a0: Ptr, _a1: Ptr) -> libcc2rs::StrongOrdering { - { - let cmp: Value = - Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( - std::cmp::Ord::cmp(&(_a0.with(|__s| __s.a)), &(_a1.with(|__s| __s.a))), - ))); - if !(libcc2rs::is_eq(({ (*cmp.borrow()) }))) { - return (*cmp.borrow_mut()); - } +impl Cpp17EqualityComparable for Defaulted { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Defaulted, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Defaulted { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Defaulted, + |__lhs, __rhs| { !({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> libcc2rs::StrongOrdering { + { + let cmp: Value = + Rc::new(RefCell::new(libcc2rs::StrongOrdering::from( + std::cmp::Ord::cmp(&(_a0.with(|__s| __s.a)), &(_a1.with(|__s| __s.a))), + ))); + if !(libcc2rs::is_eq(({ (*cmp.borrow()) }))) { + return (*cmp.borrow_mut()); } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } + 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, @@ -53,27 +77,89 @@ impl ThreeWayComparable for DefaultedOrd { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] pub a: i32, } +impl Cpp17EqualityComparable for DefaultedOrd { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { ({ operator_eq_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for DefaultedOrd { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { !({ operator_eq_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for DefaultedOrd { - fn less(_a0: Ptr, _a1: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(_a0, _a1.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + DefaultedOrd, + |__lhs, __rhs| { libcc2rs::is_lt(({ operator_cmp_1((__lhs).clone(), (__rhs).clone(),) })) } + ); } -impl LessThanComparable for Inline { - fn less(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); - } +impl PartiallyOrderedWith for DefaultedOrd { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + DefaultedOrd, + |__lhs, __rhs| { libcc2rs::is_gt(({ operator_cmp_1((__lhs).clone(), (__rhs).clone(),) })) } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ operator_cmp_1((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ operator_cmp_1((__lhs).clone(), (__rhs).clone()) })) + } + ); } -pub fn operator_add_0(x: Ptr, y: Ptr) -> Inline { +impl ThreeWayComparable for DefaultedOrd { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ operator_cmp_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +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 { + return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); +} +pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { return Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; @@ -97,6 +183,36 @@ pub struct Inline { #[offset(0)] pub a: i32, } +impl Cpp17EqualityComparable for Inline { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Inline, + |__lhs, __rhs| { ({ operator_eq_3((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Inline { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Inline, + |__lhs, __rhs| { !({ operator_eq_3((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for Inline { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Inline, + |__lhs, __rhs| { ({ operator_lt_4((__lhs).clone(), (__rhs).clone(),) }) } + ); +} #[derive( Copy, Clone, @@ -116,10 +232,40 @@ pub struct OutOfLine { #[offset(0)] pub a: i32, } -impl LessThanComparable for Tmpl_int_ { - fn less(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); - } +impl Cpp17EqualityComparable for OutOfLine { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + OutOfLine, + |__lhs, __rhs| { ({ operator_eq_6((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for OutOfLine { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + OutOfLine, + |__lhs, __rhs| { ({ operator_ne_7((__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 { + 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, @@ -140,6 +286,42 @@ pub struct Tmpl_int_ { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for Tmpl_int_ { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Tmpl_int_, + |__lhs, __rhs| { ({ operator_eq_8((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Tmpl_int_, + |__lhs, __rhs| { !({ operator_eq_8((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for Tmpl_int_ { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Tmpl_int_, + |__lhs, __rhs| { ({ operator_lt_9((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_eq_11(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); +} +pub fn operator_lt_12(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); +} #[derive( Copy, Clone, @@ -159,6 +341,39 @@ pub struct Tmpl_long_ { #[offset(0)] pub v: i64, } +impl Cpp17EqualityComparable for Tmpl_long_ { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Tmpl_long_, + |__lhs, __rhs| { ({ operator_eq_11((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Tmpl_long_ { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Tmpl_long_, + |__lhs, __rhs| { !({ operator_eq_11((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for Tmpl_long_ { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Tmpl_long_, + |__lhs, __rhs| { ({ operator_lt_12((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_eq_13(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); +} #[derive( Copy, Clone, @@ -178,6 +393,26 @@ pub struct TmplDefaulted_int_ { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for TmplDefaulted_int_ { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + TmplDefaulted_int_, + |__lhs, __rhs| { ({ operator_eq_13((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + TmplDefaulted_int_, + |__lhs, __rhs| { !({ operator_eq_13((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -186,22 +421,21 @@ 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!(({ 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(),) })); + 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(),) })); let o1: Value = Rc::new(RefCell::new(DefaultedOrd { a: 1 })); let o2: Value = Rc::new(RefCell::new(DefaultedOrd { a: 2 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(o1.as_pointer(), o2.as_pointer(),) }) + ({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(o2.as_pointer(), o1.as_pointer(),) }) + ({ operator_cmp_1(o2.as_pointer(), o1.as_pointer(),) }) )); - assert!(({ WeaklyEqualityComparableWith::equal(o1.as_pointer(), o1.as_pointer(),) })); + assert!(({ operator_eq_2(o1.as_pointer(), o1.as_pointer(),) })); assert!({ - let __a = libcc2rs::PartialOrdering::from( - ({ ThreeWayComparable::three_way(o1.as_pointer(), o2.as_pointer()) }), - ); + let __a = + libcc2rs::PartialOrdering::from(({ operator_cmp_1(o1.as_pointer(), o2.as_pointer()) })); let __b = libcc2rs::PartialOrdering::from( ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }), ); @@ -212,85 +446,41 @@ fn main_0() -> i32 { 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!(({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i3.as_pointer(),) })); - assert!(!({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i2.as_pointer(),) })); - assert!(({ LessThanComparable::less(i1.as_pointer(), i2.as_pointer(),) })); - assert!(!({ LessThanComparable::less(i2.as_pointer(), i1.as_pointer(),) })); + 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!( ({ let _x: Value = Rc::new(RefCell::new( - ({ operator_add_0(i1.as_pointer(), i2.as_pointer()) }), + ({ operator_add_5(i1.as_pointer(), i2.as_pointer()) }), )); let _y: Value = Rc::new(RefCell::new(Inline { a: 3 })); - WeaklyEqualityComparableWith::equal(_x.as_pointer(), _y.as_pointer()) + operator_eq_3(_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!(({ 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(),) })); + 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(),) })); 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!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t3.as_pointer(),) })); - assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t2.as_pointer(),) })); - assert!(({ LessThanComparable::less(t1.as_pointer(), t2.as_pointer(),) })); + 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(),) })); 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!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ operator_eq_10(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ operator_eq_10(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!(({ 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(),) })); + assert!(({ operator_eq_13(v1.as_pointer(), v2.as_pointer(),) })); + assert!(!({ operator_eq_13(v1.as_pointer(), v3.as_pointer(),) })); + assert!(!({ operator_eq_13(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 92681a1bd6..353661b487 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -34,11 +34,6 @@ impl Pair { && ({ this.with(|__s| __s.y) } < { other.with(|__s| __s.y) })); } } -impl LessThanComparable for Pair { - fn less(this: Ptr, other: Ptr) -> bool { - Pair::operator_lt(this.clone(), other.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index e933c0b1ef..686895afd6 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -70,6 +70,74 @@ impl S { return (this.with(|__s| __s.v) != 0); } } +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } == { ({ S::to_i32((__rhs).clone()) }) }) + } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } != { ({ S::to_i32((__rhs).clone()) }) }) + } + ); +} +impl LessThanComparable for S { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } < { ({ S::to_i32((__rhs).clone()) }) }) + } + ); +} +impl PartiallyOrderedWith for S { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } > { ({ S::to_i32((__rhs).clone()) }) }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } <= { ({ S::to_i32((__rhs).clone()) }) }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { + ({ ({ S::to_i32((__lhs).clone()) }) } >= { ({ S::to_i32((__rhs).clone()) }) }) + } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index b74cfdd244..ad33f3a694 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -56,22 +56,89 @@ impl S { return ((this.with(|__s| __s.v) * o) + 1); } } -pub fn operator_div_0(a: Ptr, b: Ptr) -> i32 { +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + i32, + |__return, __lhs, __rhs| { + __return.write(({ S::operator_eq_1((__lhs).clone(), (__rhs.read())) })); + }, + |__lhs, __rhs| { (({ S::operator_eq_1((__lhs).clone(), (__rhs.read()),) }) != 0) } + ); +} +impl Cpp17EqualityComparable for i32 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + S, + |__return, __lhs, __rhs| { + __return.write(({ operator_eq_0((__lhs.read()), { (*__rhs.upgrade().deref()) }) })); + }, + |__lhs, __rhs| { + (({ operator_eq_0((__lhs.read()), { (*__rhs.upgrade().deref()) }) }) != 0) + } + ); +} +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + i64, + |__return, __lhs, __rhs| { + __return.write(({ S::operator_eq_2((__lhs).clone(), (__rhs.read())) })); + }, + |__lhs, __rhs| { (({ S::operator_eq_2((__lhs).clone(), (__rhs.read()),) }) != 0) } + ); +} +impl Cpp17EqualityComparable for i64 { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + S, + |__return, __lhs, __rhs| { + __return.write(({ operator_eq_1((__lhs.read()), (__rhs).clone()) })); + }, + |__lhs, __rhs| { (({ operator_eq_1((__lhs.read()), (__rhs).clone(),) }) != 0) } + ); +} +impl Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = i32, + f64, + |__return, __lhs, __rhs| { + __return.write(({ S::operator_eq_3((__lhs).clone(), (__rhs.read())) })); + }, + |__lhs, __rhs| { (({ S::operator_eq_3((__lhs).clone(), (__rhs.read()),) }) != 0) } + ); +} +pub fn operator_div_2(a: Ptr, b: Ptr) -> i32 { return ({ a.with(|__s| __s.v) } / { b.with(|__s| __s.v) }); } -pub fn operator_div_1(mut a: S, mut b: i32) -> i32 { +pub fn operator_div_3(mut a: S, mut b: i32) -> i32 { return ((a.v / b) + 1); } -pub fn operator_rem_2(mut a: S, mut b: S) -> i32 { +pub fn operator_rem_4(mut a: S, mut b: S) -> i32 { return (a.v % b.v); } -pub fn operator_rem_3(a: Ptr, mut b: i32) -> i32 { +pub fn operator_rem_5(a: Ptr, mut b: i32) -> i32 { return (({ a.with(|__s| __s.v) } % { b }) + 1); } -pub fn operator_eq_4(mut a: i32, mut b: S) -> i32 { +pub fn operator_eq_0(mut a: i32, mut b: S) -> i32 { return if (a == b.v) { 4 } else { 0 }; } -pub fn operator_eq_5(mut a: i64, b: Ptr) -> i32 { +pub fn operator_eq_1(mut a: i64, b: Ptr) -> i32 { return if ({ a } == { (b.with(|__s| __s.v) as i64) }) { 5 } else { @@ -93,12 +160,12 @@ fn main_0() -> i32 { assert!((({ S::operator_sub(s.as_pointer(), { (*t.borrow()) },) }) == 2)); assert!((({ S::operator_mul_6(s.as_pointer(), t.as_pointer(),) }) == 24)); assert!((({ S::operator_mul_7(s.as_pointer(), 2,) }) == 13)); - assert!((({ operator_div_0(s.as_pointer(), t.as_pointer(),) }) == 1)); - assert!((({ operator_div_1({ (*s.borrow()) }, 4,) }) == 2)); - assert!((({ operator_rem_2({ (*s.borrow()) }, { (*t.borrow()) },) }) == 2)); - assert!((({ operator_rem_3(s.as_pointer(), 4,) }) == 3)); - assert!((({ operator_eq_4(6, { (*s.borrow()) },) }) == 4)); - assert!((({ operator_eq_5(6_i64, s.as_pointer(),) }) == 5)); + assert!((({ operator_div_2(s.as_pointer(), t.as_pointer(),) }) == 1)); + assert!((({ operator_div_3({ (*s.borrow()) }, 4,) }) == 2)); + assert!((({ operator_rem_4({ (*s.borrow()) }, { (*t.borrow()) },) }) == 2)); + assert!((({ operator_rem_5(s.as_pointer(), 4,) }) == 3)); + assert!((({ operator_eq_0(6, { (*s.borrow()) },) }) == 4)); + assert!((({ operator_eq_1(6_i64, s.as_pointer(),) }) == 5)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 3174e5eb07..e071bc30a1 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -17,19 +17,16 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -impl ThreeWayComparable for S { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, o: Ptr) -> libcc2rs::StrongOrdering { +impl S { + pub fn operator_cmp(this: Ptr, o: Ptr) -> libcc2rs::StrongOrdering { if ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { return (*libcc2rs::strong_ordering_less().upgrade().deref()); } @@ -38,11 +35,81 @@ impl ThreeWayComparable for 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 Cpp17EqualityComparable for S { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { ({ S::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for S { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { !({ S::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for S { - fn less(this: Ptr, o: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), o.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_lt(({ S::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for S { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_gt(({ S::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ S::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ S::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for S { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ S::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } pub fn main() { __cpp2rust_init_globals(); @@ -52,22 +119,21 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); assert!(libcc2rs::is_lt( - ({ ThreeWayComparable::three_way(a.as_pointer(), b.as_pointer(),) }) + ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) )); assert!(libcc2rs::is_gt( - ({ ThreeWayComparable::three_way(b.as_pointer(), a.as_pointer(),) }) + ({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) )); assert!(libcc2rs::is_lteq( - ({ ThreeWayComparable::three_way(a.as_pointer(), b.as_pointer(),) }) + ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) )); assert!(libcc2rs::is_gteq( - ({ ThreeWayComparable::three_way(b.as_pointer(), a.as_pointer(),) }) + ({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) )); - assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); assert!({ - let __a = libcc2rs::PartialOrdering::from( - ({ ThreeWayComparable::three_way(a.as_pointer(), b.as_pointer()) }), - ); + let __a = + libcc2rs::PartialOrdering::from(({ S::operator_cmp(a.as_pointer(), b.as_pointer()) })); let __b = libcc2rs::PartialOrdering::from( ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }), ); @@ -77,9 +143,4 @@ fn main_0() -> i32 { }); 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 1d662beb1d..b2d233da08 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -25,11 +25,21 @@ pub struct Lt { #[offset(0)] pub v: i32, } -impl LessThanComparable for Lt { - fn less(this: Ptr, o: Ptr) -> bool { +impl Lt { + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); } } +impl LessThanComparable for Lt { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Lt, + |__lhs, __rhs| { ({ Lt::operator_lt((__lhs).clone(), (__rhs).clone(),) }) } + ); +} #[derive( Copy, Clone, @@ -49,6 +59,31 @@ 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 Cpp17EqualityComparable for Eq { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Eq, + |__lhs, __rhs| { ({ Eq::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Eq { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Eq, + |__lhs, __rhs| { !({ Eq::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} #[derive( Copy, Clone, @@ -60,29 +95,96 @@ pub struct Eq { TriviallyDefaultConstructible, TriviallyCopyable, Default, - PartiallyOrderedWith, + Conversions, )] -#[three_way(ThreeWayComparable::three_way)] -#[derive(Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct Cmp { #[offset(0)] pub v: i32, } -impl ThreeWayComparable for Cmp { - type Category = libcc2rs::StrongOrdering; - fn three_way(this: Ptr, o: Ptr) -> libcc2rs::StrongOrdering { +impl Cmp { + pub fn operator_cmp(this: Ptr, o: Ptr) -> libcc2rs::StrongOrdering { return libcc2rs::StrongOrdering::from(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 Cpp17EqualityComparable for Cmp { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Cmp, + |__lhs, __rhs| { ({ Cmp::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Cmp { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Cmp, + |__lhs, __rhs| { !({ Cmp::operator_eq((__lhs).clone(), (__rhs).clone(),) }) } + ); } impl LessThanComparable for Cmp { - fn less(this: Ptr, o: Ptr) -> bool { - libcc2rs::is_lt(ThreeWayComparable::three_way(this.clone(), o.clone())) - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lt(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl PartiallyOrderedWith for Cmp { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gt(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lteq(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gteq(({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone()) })) + } + ); +} +impl ThreeWayComparable for Cmp { + comparison!( + ThreeWayComparable, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { ({ Cmp::operator_cmp((__lhs).clone(), (__rhs).clone(),) }) } + ); } #[derive( Copy, @@ -103,10 +205,47 @@ pub struct Free { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for Free { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Free, + |__lhs, __rhs| { ({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Free { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Free, + |__lhs, __rhs| { !({ operator_eq_0((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for Free { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Free, + |__lhs, __rhs| { ({ operator_lt_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); +} +pub fn operator_eq_0(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); +} +pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); +} +pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } #[derive( Copy, @@ -127,6 +266,36 @@ pub struct Wrapped_int_ { #[offset(0)] pub v: i32, } +impl Cpp17EqualityComparable for Wrapped_int_ { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Wrapped_int_, + |__lhs, __rhs| { ({ operator_eq_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl WeaklyEqualityComparableWith for Wrapped_int_ { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Wrapped_int_, + |__lhs, __rhs| { !({ operator_eq_2((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +impl LessThanComparable for Wrapped_int_ { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Wrapped_int_, + |__lhs, __rhs| { ({ operator_lt_3((__lhs).clone(), (__rhs).clone(),) }) } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -161,12 +330,13 @@ fn main_0() -> i32 { ({ 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(two.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -179,12 +349,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(nine.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -193,7 +364,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(eqs.decay().end())).as_pointer(), ) { (__tmp_1, __tmp_2) => { - WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_2).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_1).clone()), + LvalueRef::>>::bind((__tmp_2).clone()), + ) } }); let cmps: Value> = Rc::new(RefCell::new(Vec::from([ @@ -218,12 +392,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(three.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -248,12 +423,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(ftwo.as_pointer().clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -297,19 +473,4 @@ 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/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index bf4a93e669..2aafb3b871 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -56,6 +56,74 @@ impl Meters { return this.with(|__s| __s.value); } } +impl Cpp17EqualityComparable for Meters { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } == { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); +} +impl WeaklyEqualityComparableWith for Meters { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } != { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); +} +impl LessThanComparable for Meters { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } < { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); +} +impl PartiallyOrderedWith for Meters { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } > { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } <= { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Meters, + |__lhs, __rhs| { + ({ ({ Meters::to_i32((__lhs).clone()) }) } >= { ({ Meters::to_i32((__rhs).clone()) }) }) + } + ); +} #[derive( Copy, Clone, diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 3a5e4706fa..a0a040a9ea 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -96,7 +96,10 @@ pub fn push_local_from_field_1(mut jpg: Ptr, mut cond: bool) { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -133,7 +136,10 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -405,7 +411,10 @@ pub fn emplace_from_element_14(mut v: Ptr>>) { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -517,7 +526,10 @@ pub fn emplace_from_sibling_18(mut s: Ptr) { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/redundant_copy_in_conversion.rs b/tests/unit/out/refcount/redundant_copy_in_conversion.rs index 2d3679ec5b..06348e736c 100644 --- a/tests/unit/out/refcount/redundant_copy_in_conversion.rs +++ b/tests/unit/out/refcount/redundant_copy_in_conversion.rs @@ -17,7 +17,14 @@ pub fn sink_0(it: BidirectionalIterator<(Value, Value)>) -> i32 { )>>::from(({ (*it.borrow()).clone() })))) .as_pointer(),) { - (__tmp_0,) => WeaklyEqualityComparableWith::equal(cit.as_pointer(), (__tmp_0).clone()), + (__tmp_0,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + cit.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_0).clone(), + ), + ), } { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) .1 @@ -58,14 +65,24 @@ fn main_0() -> i32 { )>>::from(({ (*end.borrow()).clone() })))) .as_pointer(),) { - (__tmp_3,) => WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_3).clone()), + (__tmp_3,) => Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + const_it.as_pointer(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_3).clone(), + ), + ), } { 0 } else { 1 }; r += ({ sink_0({ (*it0.borrow()).clone() }) }); - r += if WeaklyEqualityComparableWith::equal(end.as_pointer(), end.as_pointer()) { + r += if Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind(end.as_pointer()), + LvalueRef::, Value)>>>::bind(end.as_pointer()), + ) { 0 } else { 1 @@ -78,9 +95,9 @@ fn main_0() -> i32 { >::from(({ (*middle.borrow()).clone() })), )); assert!(((({ (*const_middle.borrow()).iter_deref() }).read()) == 8_u32)); - assert!(WeaklyEqualityComparableWith::equal( - const_middle.as_pointer(), - middle.as_pointer() + assert!(Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind(const_middle.as_pointer()), + LvalueRef::>>::bind(middle.as_pointer()), )); return 0; } diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index ec68ef0ef9..e288f936d4 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -36,7 +36,10 @@ pub fn size_t_in_rules_3() { 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 >::not_equal(__first.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__first.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { object!(__value, u64, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this @@ -118,7 +121,14 @@ pub fn size_t_in_rules_3() { .as_pointer(), ) { (__tmp_2, __tmp_4) => { - WeaklyEqualityComparableWith::not_equal((__tmp_2).clone(), (__tmp_4).clone()) + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::, Value)>>>::bind( + (__tmp_2).clone(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_4).clone(), + ), + ) } }); assert!( @@ -258,7 +268,10 @@ pub fn size_t_in_rules_3() { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -281,7 +294,10 @@ pub fn size_t_in_rules_3() { { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { __it.borrow() .iter_deref() .write(Clone::clone(&({ ((*k.borrow()) as u64) }))); @@ -296,9 +312,9 @@ pub fn size_t_in_rules_3() { let __tmp_10: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); (match (v.decay().offset(1_usize),) { (__tmp_9,) => { - if LessThanComparable::less( - (__tmp_9).clone().clone(), - __tmp_10.as_pointer().clone(), + if ::is_less( + LvalueRef::>::bind((__tmp_9).clone().clone()), + LvalueRef::>::bind(__tmp_10.as_pointer().clone()), ) { __tmp_10.as_pointer() } else { @@ -390,12 +406,12 @@ pub fn size_t_in_rules_3() { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(__tmp_19.as_pointer().clone()), ) { __it.borrow_mut().iter_inc(); } @@ -407,7 +423,10 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new(v3.decay().end())).as_pointer(), ) { (__tmp_18, __tmp_20) => { - WeaklyEqualityComparableWith::not_equal((__tmp_18).clone(), (__tmp_20).clone()) + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind((__tmp_18).clone()), + LvalueRef::>>::bind((__tmp_20).clone()), + ) } }); assert!( @@ -468,13 +487,24 @@ fn main_0() -> i32 { (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); let __tmp_22: Value = Rc::new(RefCell::new((sz as u64))); - (if LessThanComparable::less(__tmp_21.as_pointer().clone(), __tmp_22.as_pointer().clone()) { __tmp_21.as_pointer() } else { __tmp_22.as_pointer() } .read()) + (if ::is_less( + LvalueRef::>::bind(__tmp_21.as_pointer().clone()), + LvalueRef::>::bind(__tmp_22.as_pointer().clone()), + ) { + __tmp_21.as_pointer() + } else { + __tmp_22.as_pointer() + } + .read()) }) as usize); let mut hi: usize = (({ let __tmp_23: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if LessThanComparable::less(__tmp_23.as_pointer().clone(), ul.as_pointer().clone()) { + (if ::is_less( + LvalueRef::>::bind(__tmp_23.as_pointer().clone()), + LvalueRef::>::bind(ul.as_pointer().clone()), + ) { ul.as_pointer() } else { __tmp_23.as_pointer() @@ -486,7 +516,15 @@ fn main_0() -> i32 { let mut bound: usize = (({ let __tmp_24: Value = Rc::new(RefCell::new((4_usize as u64))); let __tmp_25: Value = Rc::new(RefCell::new((sz as u64))); - (if LessThanComparable::less(__tmp_24.as_pointer().clone(), __tmp_25.as_pointer().clone()) { __tmp_24.as_pointer() } else { __tmp_25.as_pointer() } .read()) + (if ::is_less( + LvalueRef::>::bind(__tmp_24.as_pointer().clone()), + LvalueRef::>::bind(__tmp_25.as_pointer().clone()), + ) { + __tmp_24.as_pointer() + } else { + __tmp_25.as_pointer() + } + .read()) }) as usize); assert!((bound == 4_usize)); let mut data: [i32; 8] = [0_i32; 8]; @@ -537,12 +575,28 @@ fn main_0() -> i32 { let mut smin: isize = (({ let __tmp_26: Value = Rc::new(RefCell::new((sm as i64))); let __tmp_27: Value = Rc::new(RefCell::new((sd as i64))); - (if LessThanComparable::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { __tmp_26.as_pointer() } else { __tmp_27.as_pointer() } .read()) + (if ::is_less( + LvalueRef::>::bind(__tmp_26.as_pointer().clone()), + LvalueRef::>::bind(__tmp_27.as_pointer().clone()), + ) { + __tmp_26.as_pointer() + } else { + __tmp_27.as_pointer() + } + .read()) }) as isize); let mut smax: isize = (({ let __tmp_28: Value = Rc::new(RefCell::new((sd as i64))); let __tmp_29: Value = Rc::new(RefCell::new((sm as i64))); - (if LessThanComparable::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { __tmp_29.as_pointer() } else { __tmp_28.as_pointer() } .read()) + (if ::is_less( + LvalueRef::>::bind(__tmp_28.as_pointer().clone()), + LvalueRef::>::bind(__tmp_29.as_pointer().clone()), + ) { + __tmp_29.as_pointer() + } else { + __tmp_28.as_pointer() + } + .read()) }) as isize); assert!((smin == (-7_i32 as isize))); assert!((smax == 15_isize)); @@ -564,9 +618,9 @@ fn main_0() -> i32 { (({ let __tmp_30: Value = Rc::new(RefCell::new((mx as u64))); let __tmp_31: Value = Rc::new(RefCell::new(1_u64)); - (if LessThanComparable::less( - __tmp_30.as_pointer().clone(), - __tmp_31.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_30.as_pointer().clone()), + LvalueRef::>::bind(__tmp_31.as_pointer().clone()), ) { __tmp_30.as_pointer() } else { @@ -577,9 +631,9 @@ fn main_0() -> i32 { (({ 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 LessThanComparable::less( - __tmp_32.as_pointer().clone(), - __tmp_33.as_pointer().clone(), + (if ::is_less( + LvalueRef::>::bind(__tmp_32.as_pointer().clone()), + LvalueRef::>::bind(__tmp_33.as_pointer().clone()), ) { __tmp_32.as_pointer() } else { diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index a9e08862ee..203e861dfd 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -52,6 +52,16 @@ impl MoveAssignable for Tracked { return (this).clone(); } } +impl LessThanComparable for Tracked { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Tracked, + |__lhs, __rhs| { ({ operator_lt_1((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl Default for Tracked { fn default() -> Self { { @@ -63,12 +73,10 @@ impl Default for Tracked { } } } -impl LessThanComparable for Tracked { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); - } +pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn greater_1(a: Ptr, b: Ptr) -> bool { +pub fn greater_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } #[derive( @@ -96,9 +104,17 @@ impl MoveOnly { } } impl LessThanComparable for MoveOnly { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + MoveOnly, + |__lhs, __rhs| { ({ operator_lt_3((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, @@ -118,10 +134,31 @@ impl Bag { field!(this, items).write(Vec::new()); } } +impl Cpp17EqualityComparable for Bag { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Bag, + |__lhs, __rhs| { ({ operator_eq_4((__lhs).clone(), (__rhs).clone(),) }) } + ); +} impl LessThanComparable for Bag { - fn less(a: Ptr, b: Ptr) -> bool { - return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); - } + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Bag, + |__lhs, __rhs| { ({ operator_lt_5((__lhs).clone(), (__rhs).clone(),) }) } + ); +} +pub fn operator_lt_5(a: Ptr, b: Ptr) -> bool { + return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); +} +pub fn operator_eq_4(a: Ptr, b: Ptr) -> bool { + return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); } pub fn main() { __cpp2rust_init_globals(); @@ -237,9 +274,9 @@ fn main_0() -> i32 { __order.sort_by(|&__x, &__y| { let __a = __tmp_6.iter_at(__x); let __b = __tmp_6.iter_at(__y); - if greater_1.call(__a.clone(), __b.clone()) { + if greater_2.call(__a.clone(), __b.clone()) { std::cmp::Ordering::Less - } else if greater_1.call(__b, __a) { + } else if greater_2.call(__b, __a) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -291,9 +328,9 @@ fn main_0() -> i32 { __order.sort_by(|&__x, &__y| { let __a = __tmp_8.iter_at(__x); let __b = __tmp_8.iter_at(__y); - if greater_1.call(__a.clone(), __b.clone()) { + if greater_2.call(__a.clone(), __b.clone()) { std::cmp::Ordering::Less - } else if greater_1.call(__b, __a) { + } else if greater_2.call(__b, __a) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -424,12 +461,13 @@ fn main_0() -> i32 { 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(), - ) - { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(bags.decay().offset(1).clone()), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -438,7 +476,10 @@ fn main_0() -> i32 { 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()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_20).clone()), + LvalueRef::>>::bind((__tmp_21).clone()), + ) } }); assert!(match ( @@ -448,11 +489,19 @@ fn main_0() -> i32 { 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()) { + if as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { __it.borrow_mut().iter_inc(); - while >::not_equal(__it.as_pointer(), __last.as_pointer()) - { - if LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { + if ::is_less( + LvalueRef::>::bind(__best.iter_deref()), + LvalueRef::>::bind(__it.borrow().iter_deref()), + ) { __best = __it.borrow().clone(); } __it.borrow_mut().iter_inc(); @@ -464,13 +513,16 @@ fn main_0() -> i32 { 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()) + Cpp17EqualityComparable::is_equal( + LvalueRef::>>::bind((__tmp_22).clone()), + LvalueRef::>>::bind((__tmp_23).clone()), + ) } }); assert!( - ((if LessThanComparable::less( - bags.decay().offset(2).clone(), - bags.decay().offset(0).clone() + ((if ::is_less( + LvalueRef::>::bind(bags.decay().offset(2).clone()), + LvalueRef::>::bind(bags.decay().offset(0).clone()), ) { bags.decay().offset(2) } else { @@ -478,9 +530,9 @@ fn main_0() -> i32 { }) == (bags.decay().offset(0))) ); assert!( - ((if LessThanComparable::less( - bags.decay().offset(0).clone(), - bags.decay().offset(2).clone() + ((if ::is_less( + LvalueRef::>::bind(bags.decay().offset(0).clone()), + LvalueRef::>::bind(bags.decay().offset(2).clone()), ) { bags.decay().offset(2) } else { @@ -525,7 +577,14 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_26, __tmp_27) => { - WeaklyEqualityComparableWith::equal((__tmp_26).clone(), (__tmp_27).clone()) + Cpp17EqualityComparable::is_equal( + LvalueRef::, Value)>>>::bind( + (__tmp_26).clone(), + ), + LvalueRef::, Value)>>>::bind( + (__tmp_27).clone(), + ), + ) } }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); @@ -610,11 +669,6 @@ 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 3a312a4201..8918eee1dd 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -43,7 +43,10 @@ fn main_0() -> i32 { 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 >::not_equal(__first.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__first.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { object!(__value, i32, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this @@ -66,7 +69,10 @@ fn main_0() -> i32 { 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 >::not_equal(__first.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__first.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { object!(__value, i64, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this @@ -99,7 +105,10 @@ fn main_0() -> i32 { 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 >::not_equal(__first.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__first.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { object!(__value, Degrees, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this @@ -127,7 +136,10 @@ fn main_0() -> i32 { 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 >::not_equal(__first.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__first.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { object!(__value, f64, |__this| ConvertibleTo::convert( LvalueRef::::bind(__first.borrow().iter_deref()), __this diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index 125d536561..c1927139dd 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -32,7 +32,10 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new(__tmp_1)); let __out = &mut (*ofs.borrow_mut()); let mut __bytes: Vec = Vec::new(); - while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { __bytes.push(__it.borrow().iter_deref().read() as u8); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/stdmin_fpoint.rs b/tests/unit/out/refcount/stdmin_fpoint.rs index 23a3bcef2f..bc2fa581d2 100644 --- a/tests/unit/out/refcount/stdmin_fpoint.rs +++ b/tests/unit/out/refcount/stdmin_fpoint.rs @@ -13,7 +13,10 @@ pub fn main() { fn main_0() -> i32 { let a0: Value = Rc::new(RefCell::new(3.14_f64)); let a1: Value = Rc::new(RefCell::new(2.71_f64)); - if LessThanComparable::less(a1.as_pointer().clone(), a0.as_pointer().clone()) { + if ::is_less( + LvalueRef::>::bind(a1.as_pointer().clone()), + LvalueRef::>::bind(a0.as_pointer().clone()), + ) { a1.as_pointer() } else { a0.as_pointer() diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 393e236257..00656fbc53 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -59,12 +59,12 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { 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(), + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) && !>::is_equal( + LvalueRef::>::bind(__it.borrow().iter_deref()), + LvalueRef::>::bind(sigma.offset((i) as isize).clone()), ) { __it.borrow_mut().iter_inc(); } @@ -73,9 +73,13 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { assert!( match (Rc::new(RefCell::new(items.decay().end())).as_pointer(),) { (__tmp_0,) => { - WeaklyEqualityComparableWith::not_equal( - it.as_pointer(), - (__tmp_0).clone(), + WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind( + it.as_pointer(), + ), + LvalueRef::>>::bind( + (__tmp_0).clone(), + ), ) } } @@ -100,9 +104,10 @@ pub fn sum_4(v: Ptr>) -> i32 { { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { - (__tmp_2,) => { - WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_2).clone()) - } + (__tmp_2,) => WeaklyEqualityComparableWith::is_not_equal( + LvalueRef::>>::bind(it.as_pointer()), + LvalueRef::>>::bind((__tmp_2).clone()), + ), } { 'for_body: { s += (({ (*it.borrow()).iter_deref() }).read()); diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 2430ac05fb..ab412a64da 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -176,7 +176,10 @@ fn main_0() -> i32 { let high: Value = Rc::new(RefCell::new(3)); let mut low: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(2)); - (if LessThanComparable::less(__tmp_0.as_pointer().clone(), high.as_pointer().clone()) { + (if ::is_less( + LvalueRef::>::bind(__tmp_0.as_pointer().clone()), + LvalueRef::>::bind(high.as_pointer().clone()), + ) { __tmp_0.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 7d9809b4eb..b014105313 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -192,7 +192,10 @@ fn main_0() -> i32 { let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -706,7 +709,10 @@ fn main_0() -> i32 { let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -740,7 +746,10 @@ fn main_0() -> i32 { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -767,7 +776,10 @@ fn main_0() -> i32 { let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -797,7 +809,10 @@ fn main_0() -> i32 { let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -829,7 +844,10 @@ fn main_0() -> i32 { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 258b666ca4..dd12352407 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -56,6 +56,86 @@ impl Reading { return ((this.with(|__s| __s.raw_) as i64) * 10_i64); } } +impl Cpp17EqualityComparable for Reading { + comparison!( + Cpp17EqualityComparable, + equal, + is_equal, + EqualResult = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } == { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); +} +impl WeaklyEqualityComparableWith for Reading { + comparison!( + WeaklyEqualityComparableWith, + not_equal, + is_not_equal, + NotEqualResult = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } != { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); +} +impl LessThanComparable for Reading { + comparison!( + LessThanComparable, + less, + is_less, + Result = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } < { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); +} +impl PartiallyOrderedWith for Reading { + comparison!( + PartiallyOrderedWith, + greater, + is_greater, + GreaterResult = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } > { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + less_equal, + is_less_equal, + LessEqualResult = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } <= { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); + comparison!( + PartiallyOrderedWith, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Reading, + |__lhs, __rhs| { + ({ ({ Reading::to_i64((__lhs).clone()) }) } >= { + ({ Reading::to_i64((__rhs).clone()) }) + }) + } + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -66,7 +146,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -83,7 +166,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -100,7 +186,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -118,7 +207,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -142,7 +234,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -184,20 +279,7 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - while , Value)>>::not_equal( - __it.as_pointer(), - __last.as_pointer(), - ) { - let __i = __v.borrow().len(); - __v.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - __v.as_pointer().decay().offset(__i), - (LvalueRef::, Value)>>::bind( - __it.borrow().iter_deref(), - ),), - ); - __it.borrow_mut().iter_inc(); - } + while , Value) > as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef::, Value) > >>::bind(__it.as_pointer()), LvalueRef::, Value) > >>::bind(__last.as_pointer()), ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), (LvalueRef::, Value) >>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ ((*v6.borrow()).len() == 3_usize) })); @@ -229,20 +311,7 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - while , Value)>>::not_equal( - __it.as_pointer(), - __last.as_pointer(), - ) { - let __i = temp_vec.borrow().len(); - temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - temp_vec.as_pointer().decay().offset(__i), - (LvalueRef::, Value)>>::bind( - __it.borrow().iter_deref(), - ),), - ); - __it.borrow_mut().iter_inc(); - } + while , Value) > as WeaklyEqualityComparableWith>::is_not_equal( LvalueRef::, Value) > >>::bind(__it.as_pointer()), LvalueRef::, Value) > >>::bind(__last.as_pointer()), ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), (LvalueRef::, Value) >>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } v6.as_pointer() .with_mut(|v: &mut Vec<(Value, Value)>| { v.splice( @@ -265,7 +334,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -286,7 +358,10 @@ fn main_0() -> i32 { 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index a3c027a626..87fdf8bbbd 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -405,7 +405,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -422,7 +425,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -439,7 +445,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -457,7 +466,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( @@ -478,7 +490,10 @@ fn main_0() -> i32 { let __v: Value> = Rc::new(RefCell::new(Vec::new())); 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()) { + while as WeaklyEqualityComparableWith>::is_not_equal( + LvalueRef::>>::bind(__it.as_pointer()), + LvalueRef::>>::bind(__last.as_pointer()), + ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); ConstructibleFrom::construct( diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 49f7e8d1f1..d2190a8a22 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -188,11 +188,17 @@ pub unsafe fn order_physical_2() { let __n = ps.as_mut_ptr().offset((4) as isize).iter_distance(&__tmp_0); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_0.iter_at(__x) as *const *mut i32; + let __b = __tmp_0.iter_at(__y) as *const *mut i32; + if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index fd2a3eea1b..3e349c30cd 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -98,6 +98,20 @@ 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 Cpp17EqualityComparableUnsafe for Counter { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Counter, + |__lhs, __rhs| { (unsafe { Counter::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -178,8 +192,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 { WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, &c2,) })); - assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c2, &c1,) })); + assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); + assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; @@ -192,10 +206,4 @@ 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 c7b686a2e7..a829cfcba2 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -34,7 +34,10 @@ pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut total: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { + 'loop_: while WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&(*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 e3052cb205..08e044ed73 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -420,14 +420,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { vec_.end() }; let mut __v: Vec = Vec::new(); let mut __it = (__tmp_0).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __v.as_mut_ptr().add(__v.len() - 1), - (LvalueRefUnsafe::>::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_1 ), ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } __v }; assert!( diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 06a5114584..fee05f3e3e 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -26,14 +26,21 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { v.begin() }; let mut __tmp_3 = { v.end() }; let mut __it = (__tmp_2).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) - { + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_3), + ) && !>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&7), + ) { __it.iter_inc(); } __it }; - assert!(WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end())); + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&v.end()), + )); assert!(((*it.iter_deref()) == (7))); { let mut __tmp_4 = { v.begin() }; @@ -48,11 +55,17 @@ unsafe fn main_0() -> i32 { let __n = v.end().iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_5.iter_at(__x) as *const _; - let __b = __tmp_5.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_5.iter_at(__x) as *const i32; + let __b = __tmp_5.iter_at(__y) as *const i32; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index 56d855dadc..a10b8081da 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -32,7 +32,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { (&mut (*alias))[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = __tmp_0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_1), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), diff --git a/tests/unit/out/unsafe/emplace_receiver_order.rs b/tests/unit/out/unsafe/emplace_receiver_order.rs index 5f7496e063..907e754b3e 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -40,7 +40,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = __tmp_0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_1), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -67,8 +70,10 @@ unsafe fn main_0() -> i32 { { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = __tmp_3; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) - { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_4), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index c673c84678..9e536af4fe 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -22,6 +22,21 @@ 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 Cpp17EqualityComparableUnsafe for P { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + P, + |__lhs, __rhs| { (unsafe { P::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -47,14 +62,21 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) - { + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_3), + ) && !>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&2), + ) { __it.iter_inc(); } __it }; - let mut v_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end()); + let mut v_result_true: bool = WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&v.end()), + ); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_4: i32; @@ -79,87 +101,79 @@ 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 = WeaklyEqualityComparableWithUnsafe::not_equal(&m_begin, &m_end); + let mut m_result_true: bool = WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&m_begin), + LvalueRefUnsafe::>>::bind(&m_end), + ); assert!( ((v_result_true) && (m_result_true)) - && (WeaklyEqualityComparableWithUnsafe::equal( - &{ + && (Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ 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(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_8 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&2 ), ) { __it.iter_inc(); } __it - }, - &v.begin() + }), + LvalueRefUnsafe::>>::bind(&v.begin()), )) ); let mut w: Vec = Vec::from([1, 2, 3, 4, 5]); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_10 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&4 ), ) { __it.iter_inc(); } __it - }, - &w.begin().iter_add(3_isize) + }), + LvalueRefUnsafe::>>::bind( + &w.begin().iter_add(3_isize) + ), )); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_12) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_12 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&1 ), ) { __it.iter_inc(); } __it - }, - &w.end() + }), + LvalueRefUnsafe::>>::bind(&w.end()), )); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_14 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&5 ), ) { __it.iter_inc(); } __it - }, - &w.begin().iter_add(4_isize) + }), + LvalueRefUnsafe::>>::bind( + &w.begin().iter_add(4_isize) + ), )); let mut p: Vec

= Vec::from([P { x: 0 }, P { x: 1 }, P { x: 2 }]); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) + while + as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_16), + ) && !

>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&(P { x: 1 })), + ) { __it.iter_inc(); } __it - }, - &p.begin().iter_add(1_isize) + }), + LvalueRefUnsafe::>>::bind(&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 1572274b47..d919d2095c 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -9,10 +9,13 @@ use std::rc::Rc; pub unsafe fn get_0(v: *const V) -> i32 { return (*v).x; } -pub unsafe fn scaled_1(v: *const V, mut k: i32) -> i32 { +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 { return (((*v).x) * (k)); } -pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { +pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { return (((*v).x as f64) * (k)); } #[repr(C)] @@ -31,7 +34,22 @@ pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { pub struct V { pub x: i32, } -pub unsafe fn get_3(w: *const W_int_) -> i32 { +impl Cpp17EqualityComparableUnsafe for V { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + V, + |__lhs, __rhs| { + (unsafe { + let _a: *const V = __lhs; + operator_eq_1(_a, __rhs) + }) + } + ); +} +pub unsafe fn get_4(w: *const W_int_) -> i32 { return (*w).x; } #[repr(C)] @@ -50,7 +68,7 @@ pub unsafe fn get_3(w: *const W_int_) -> i32 { pub struct W_int_ { pub x: i32, } -pub unsafe fn get_4(w: *const W_long_) -> i64 { +pub unsafe fn get_5(w: *const W_long_) -> i64 { return (*w).x; } #[repr(C)] @@ -85,7 +103,7 @@ pub struct W_long_ { pub struct D { pub x: i32, } -pub unsafe fn declared_then_defined_5(d: *const D) -> i32 { +pub unsafe fn declared_then_defined_6(d: *const D) -> i32 { return (((*d).x) + (1)); } pub fn main() { @@ -102,28 +120,23 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const V = &a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &b) + operator_eq_1(_a, &b) }) ); assert!( !(unsafe { let _a: *const V = &a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &c) + operator_eq_1(_a, &c) }) ); - assert!(((unsafe { scaled_1(&c, 2,) }) == (8))); - assert!(((unsafe { scaled_2(&c, 1.5_f64,) }) == (6_f64))); + assert!(((unsafe { scaled_2(&c, 2,) }) == (8))); + assert!(((unsafe { scaled_3(&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_3(&wi,) }) == (5))); - assert!(((unsafe { get_4(&wl,) }) == (6_i64))); + assert!(((unsafe { get_4(&wi,) }) == (5))); + assert!(((unsafe { get_5(&wl,) }) == (6_i64))); let mut d: D = D { x: 7 }; - assert!(((unsafe { declared_then_defined_5(&d,) }) == (8))); + assert!(((unsafe { declared_then_defined_6(&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/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index 901f1d1e13..fba99d9e71 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -20,7 +20,10 @@ pub static mut selected_1: std::cell::LazyCell = std::cell::LazyCell::new(| { let __a: *const _ = &mut __tmp_0; let __b: *const _ = &mut __tmp_1; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -43,7 +46,10 @@ pub static mut assigned_4: std::cell::LazyCell = std::cell::LazyCell::new(| (*{ let __a: *const _ = &mut __tmp_2; let __b: *const _ = &mut __tmp_3; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -65,7 +71,10 @@ pub static mut accumulated_5: std::cell::LazyCell = std::cell::LazyCell::ne (*{ let __a: *const _ = &mut __tmp_4; let __b: *const _ = &mut __tmp_5; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -126,7 +135,10 @@ pub static mut aggregate_selected_9: std::cell::LazyCell = (*{ let __a: *const _ = &mut __tmp_8; let __b: *const _ = &mut __tmp_9; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -142,7 +154,10 @@ pub static mut aggregate_selected_9: std::cell::LazyCell = (*{ let __a: *const _ = &mut __tmp_11; let __b: *const _ = &mut __tmp_12; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -167,7 +182,10 @@ pub static mut mapped_selected_12: std::cell::LazyCell = let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); let __b: *const _ = &mut __tmp_13; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -187,7 +205,10 @@ static mut value_14: std::cell::LazyCell = std::cell::LazyCell::new(|| un (*{ let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); let __b: *const _ = &mut __tmp_14; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -228,7 +249,10 @@ static mut aggregate_static_15: std::cell::LazyCell = std::cell::LazyCell:: (*{ let __a: *const _ = &mut __tmp_16; let __b: *const _ = &mut __tmp_17; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -244,7 +268,10 @@ static mut aggregate_static_15: std::cell::LazyCell = std::cell::LazyCell:: (*{ let __a: *const _ = &mut __tmp_19; let __b: *const _ = &mut __tmp_20; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index e7a22f483a..14eaa7b0e1 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -225,30 +225,40 @@ 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 WeaklyEqualityComparableWithUnsafe::equal(&it, &end) { + let mut x1: u32 = if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&end), + ) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x1) == (4_u32))); - let mut x2: u32 = if WeaklyEqualityComparableWithUnsafe::equal( - &const_it, - &>::from((end).clone()), + let mut x2: u32 = if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&const_it), + LvalueRefUnsafe::>>::bind( + &>::from((end).clone()), + ), ) { 0_u32 } else { (*const_it.iter_deref()).1 }; assert!(((x2) == (0_u32))); - let mut x3: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &m.end()) { + let mut x3: u32 = if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&m.end()), + ) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x3) == (4_u32))); - let mut x4: u32 = if WeaklyEqualityComparableWithUnsafe::equal( - &const_it, - &>::from(m.end()), + let mut x4: u32 = if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&const_it), + LvalueRefUnsafe::>>::bind( + &>::from(m.end()), + ), ) { 0_u32 } else { @@ -295,15 +305,15 @@ 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!(WeaklyEqualityComparableWithUnsafe::not_equal( - &m.find(&4_i16), - &m.end() + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&m.find(&4_i16)), + LvalueRefUnsafe::>>::bind(&m.end()), )); (*r).erase(&(it4).clone()); assert!((((*r).len()) == (3_usize))); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &m.find(&4_i16), - &m.end() + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&m.find(&4_i16)), + LvalueRefUnsafe::>>::bind(&m.end()), )); { let mut __tmp_21: i16; @@ -334,18 +344,21 @@ 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!(WeaklyEqualityComparableWithUnsafe::equal( - &next, - &m.find(&8_i16) + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&next), + LvalueRefUnsafe::>>::bind(&m.find(&8_i16)), )); { next = m.erase(&(next).clone()); }; - assert!(WeaklyEqualityComparableWithUnsafe::equal(&next, &m.end())); + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&next), + LvalueRefUnsafe::>>::bind(&m.end()), + )); assert!((((*r).len()) == (3_usize))); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &m.find(&8_i16), - &m.end() + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&m.find(&8_i16)), + LvalueRefUnsafe::>>::bind(&m.end()), )); let mut other_map: UnsafeMap<(i32, i64), ((i32, i64), f64)> = UnsafeMap::new(); assert!(((other_map.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 716f383024..4de8741ccc 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -34,12 +34,20 @@ impl Key { (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } -} -impl LessThanComparableUnsafe for Key { - unsafe fn less(this: *const Self, o: *const Key) -> bool { + pub unsafe fn operator_lt(this: *const Self, o: *const Key) -> bool { return (((*this).k) < ((*o).k)); } } +impl LessThanComparableUnsafe for Key { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Key, + |__lhs, __rhs| { (unsafe { Key::operator_lt(&raw const (*__lhs), __rhs,) }) } + ); +} pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); Key::constructor_1(__return, k); diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index fe4f9c4623..581d49c8fa 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -25,10 +25,41 @@ pub struct Key { pub order: i32, pub identity: i32, } +impl Cpp17EqualityComparableUnsafe for Key { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Key, + |__lhs, __rhs| { + (unsafe { + let _a: *const Key = __lhs; + operator_eq_1(_a, __rhs) + }) + } + ); +} impl LessThanComparableUnsafe for Key { - unsafe fn less(a: *const Key, b: *const Key) -> bool { - return (((*a).order) < ((*b).order)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Key, + |__lhs, __rhs| { + (unsafe { + let _a: *const Key = __lhs; + operator_lt_2(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_2(a: *const Key, b: *const Key) -> bool { + return (((*a).order) < ((*b).order)); +} +pub unsafe fn operator_eq_1(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); } #[repr(C)] #[derive( @@ -81,7 +112,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) + operator_eq_1(_a, &distinct_b) }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); @@ -104,20 +135,35 @@ unsafe fn main_0() -> i32 { 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) - & ((WeaklyEqualityComparableWithUnsafe::equal(&a_it, &distinct.find(&distinct_a))) as i32)) + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&a_it), + LvalueRefUnsafe::>>::bind( + &distinct.find(&distinct_a), + ), + )) as i32)) != 0; ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.find(&distinct_b))) as i32)) + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&b_it), + LvalueRefUnsafe::>>::bind( + &distinct.find(&distinct_b), + ), + )) as i32)) != 0; ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::not_equal(&b_it, &distinct.end())) as i32)) + & ((WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&b_it), + LvalueRefUnsafe::>>::bind( + &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; - WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) + operator_eq_1(_a, &distinct_b) }) as i32)) != 0; let mut distinct_count: usize = 0_usize; @@ -146,7 +192,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) + operator_eq_1(_a, &equivalent_b) }) as i32)) != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -167,20 +213,34 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::not_equal(&first_it, &equivalent.end())) - as i32)) + & ((WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind( + &first_it, + ), + LvalueRefUnsafe::>>::bind( + &equivalent.end(), + ), + )) as i32)) != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::equal( - &first_it, - &equivalent.find(&equivalent_a), + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &first_it, + ), + LvalueRefUnsafe::>>::bind( + &equivalent.find(&equivalent_a), + ), )) as i32)) != 0; ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::equal( - &first_it, - &equivalent.find(&equivalent_b), + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &first_it, + ), + LvalueRefUnsafe::>>::bind( + &equivalent.find(&equivalent_b), + ), )) as i32)) != 0; ok = ((ok as i32) @@ -203,7 +263,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) + operator_eq_1(_a, &equivalent_b) }) as i32)) != 0; let later_key: Key = Key { @@ -219,9 +279,13 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; if reused { ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::equal( - &first_it, - &equivalent.find(&equivalent_a), + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &first_it, + ), + LvalueRefUnsafe::>>::bind( + &equivalent.find(&equivalent_a), + ), )) as i32)) != 0; ok = ((ok as i32) @@ -261,8 +325,12 @@ unsafe fn main_0() -> i32 { 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) - & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_b))) - as i32)) + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&matched_it), + LvalueRefUnsafe::>>::bind( + &matching.find(&matching_b), + ), + )) as i32)) != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) @@ -276,8 +344,12 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; ok = ((ok as i32) - & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_a))) - as i32)) + & ((Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&matched_it), + LvalueRefUnsafe::>>::bind( + &matching.find(&matching_a), + ), + )) as i32)) != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) @@ -285,11 +357,6 @@ unsafe fn main_0() -> i32 { 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 8e174ec643..fe8265d1b5 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -220,9 +220,27 @@ unsafe fn main_0() -> i32 { as i32)) != 0; let mut found: bool = - WeaklyEqualityComparableWithUnsafe::equal( - &result.0, - &m.find(&key), + Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::< + Const< + UnsafeBidirectionalIterator<( + i32, + i32, + )>, + >, + >::bind( + &result.0 + ), + LvalueRefUnsafe::< + Const< + UnsafeBidirectionalIterator<( + i32, + i32, + )>, + >, + >::bind( + &m.find(&key) + ), ); ok = ((ok as i32) & (found as i32)) != 0; ok = ((ok as i32) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 52daa3f512..efbaf63a08 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -46,11 +46,24 @@ impl Bag { } } impl LessThanComparableUnsafe for Bag { - unsafe fn less(a: *const Bag, b: *const Bag) -> bool { - return (((*a).n) < ((*b).n)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Bag, + |__lhs, __rhs| { + (unsafe { + let _a: *const Bag = __lhs; + operator_lt_4(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { + return (((*a).n) < ((*b).n)); } -pub unsafe fn make_4(__return: *mut Bag, mut n: i32) { +pub unsafe fn make_5(__return: *mut Bag, mut n: i32) { Bag::constructor_1(__return, n); return; } @@ -70,7 +83,10 @@ unsafe fn main_0() -> i32 { let mut r1: i32 = (*{ let __a: *const _ = &mut x1; let __b: *const _ = &mut x2; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -79,7 +95,10 @@ unsafe fn main_0() -> i32 { let mut r2: i32 = (*{ let __a: *const _ = &mut x3; let __b: *const _ = &mut x4; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -88,7 +107,10 @@ unsafe fn main_0() -> i32 { let mut r3: i32 = (*{ let __a: *const _ = p1; let __b: *const _ = &mut x2; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -97,7 +119,10 @@ unsafe fn main_0() -> i32 { let mut r4: i32 = (*{ let __a: *const _ = p2; let __b: *const _ = &mut x3; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -109,7 +134,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_0; let __b: *const _ = &mut __tmp_1; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -122,13 +150,19 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_2, &__tmp_3) { + if <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__tmp_2), + LvalueRefUnsafe::>::bind(&__tmp_3), + ) { let mut __it = __tmp_2; __it.iter_inc(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { - if LessThanComparableUnsafe::less( - __best.iter_deref() as *const _, - __it.iter_deref() as *const _, + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_3), + ) { + if ::is_less( + LvalueRefUnsafe::>::bind(__best.iter_deref()), + LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __best = __it.clone(); } @@ -142,7 +176,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = (unsafe { pick_3(0) }); let __b: *const _ = (unsafe { pick_3(1) }); - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -154,7 +191,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = (unsafe { pick_3(1) }); let __b: *const _ = (unsafe { pick_3(0) }); - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -169,18 +209,21 @@ unsafe fn main_0() -> i32 { let mut __tmp_7: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ - (unsafe { make_4(&raw mut __tmp_5, 1) }); + (unsafe { make_5(&raw mut __tmp_5, 1) }); &mut __tmp_5 } as *const Bag), ({ - (unsafe { make_4(&raw mut __tmp_7, 2) }); + (unsafe { make_5(&raw mut __tmp_7, 2) }); &mut __tmp_7 } as *const Bag), ) { (__tmp_4, __tmp_6) => { let __a: *const _ = __tmp_4; let __b: *const _ = __tmp_6; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -193,18 +236,21 @@ unsafe fn main_0() -> i32 { let mut __tmp_11: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ - (unsafe { make_4(&raw mut __tmp_9, 1) }); + (unsafe { make_5(&raw mut __tmp_9, 1) }); &mut __tmp_9 } as *const Bag), ({ - (unsafe { make_4(&raw mut __tmp_11, 2) }); + (unsafe { make_5(&raw mut __tmp_11, 2) }); &mut __tmp_11 } as *const Bag), ) { (__tmp_8, __tmp_10) => { let __a: *const _ = __tmp_8; let __b: *const _ = __tmp_10; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -226,7 +272,10 @@ unsafe fn main_0() -> i32 { (__tmp_12,) => { let __a: *const _ = &mut __tmp_13; let __b: *const _ = __tmp_12; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/min_max_ptr2ptr.rs b/tests/unit/out/unsafe/min_max_ptr2ptr.rs index da37cf5a4b..1958933cd7 100644 --- a/tests/unit/out/unsafe/min_max_ptr2ptr.rs +++ b/tests/unit/out/unsafe/min_max_ptr2ptr.rs @@ -22,7 +22,10 @@ unsafe fn main_0() -> i32 { let mut r1: i32 = (*{ let __a: *const _ = (*ppa); let __b: *const _ = (*ppb); - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -31,7 +34,10 @@ unsafe fn main_0() -> i32 { let mut r2: i32 = (*{ let __a: *const _ = (*ppa); let __b: *const _ = (*ppb); - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -45,7 +51,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = &mut low; let __b: *const _ = &mut high; - if LessThanComparableUnsafe::less(__b, __a) { + if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -56,7 +65,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = &mut high; let __b: *const _ = &mut low; - if LessThanComparableUnsafe::less(__b, __a) { + if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -67,7 +79,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = &mut low; let __b: *const _ = &mut high; - if LessThanComparableUnsafe::less(__a, __b) { + if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -78,7 +93,10 @@ unsafe fn main_0() -> i32 { ((*{ let __a: *const _ = &mut high; let __b: *const _ = &mut low; - if LessThanComparableUnsafe::less(__a, __b) { + if <*mut i32 as LessThanComparableUnsafe>::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 94ba85e9ea..672bc962c7 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -23,6 +23,31 @@ 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 Cpp17EqualityComparableUnsafe for Eq { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Eq, + |__lhs, __rhs| { (unsafe { Eq::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Eq, + |__lhs, __rhs| { !(unsafe { Eq::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} #[repr(C)] #[derive( Copy, @@ -33,18 +58,15 @@ pub struct Eq { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct Cmp { pub a: i32, pub b: i32, } -impl ThreeWayComparableUnsafe for Cmp { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const Cmp) -> libcc2rs::StrongOrdering { +impl Cmp { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Cmp) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*this).a), &((*_a0).a))); @@ -61,11 +83,81 @@ impl ThreeWayComparableUnsafe for 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 Cpp17EqualityComparableUnsafe for Cmp { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Cmp, + |__lhs, __rhs| { (unsafe { Cmp::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Cmp, + |__lhs, __rhs| { !(unsafe { Cmp::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for Cmp { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Cmp { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for Cmp { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -77,17 +169,17 @@ impl LessThanComparableUnsafe for Cmp { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct Both { pub a: i32, } -impl ThreeWayComparableUnsafe for Both { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const Both) -> libcc2rs::StrongOrdering { +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) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*this).a), &((*_a0).a))); @@ -98,10 +190,77 @@ impl ThreeWayComparableUnsafe for Both { return libcc2rs::STRONG_ORDERING_EQUAL; } } +impl Cpp17EqualityComparableUnsafe for Both { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Both, + |__lhs, __rhs| { (unsafe { Both::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Both { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Both, + |__lhs, __rhs| { !(unsafe { Both::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} impl LessThanComparableUnsafe for Both { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { Both::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Both { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Both::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Both::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Both, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { Both::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for Both { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Both::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -113,10 +272,8 @@ impl LessThanComparableUnsafe for Both { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(OrdOnly::operator_cmp)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct OrdOnly { pub a: i32, @@ -134,9 +291,48 @@ impl OrdOnly { } } impl LessThanComparableUnsafe for OrdOnly { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(OrdOnly::operator_cmp(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { OrdOnly::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for OrdOnly { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { OrdOnly::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { OrdOnly::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + OrdOnly, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { OrdOnly::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); } #[repr(C)] #[derive( @@ -148,17 +344,14 @@ impl LessThanComparableUnsafe for OrdOnly { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct Inner { pub x: i32, } -impl ThreeWayComparableUnsafe for Inner { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const Inner) -> libcc2rs::StrongOrdering { +impl Inner { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Inner) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*this).x), &((*_a0).x))); @@ -168,11 +361,81 @@ impl ThreeWayComparableUnsafe for Inner { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); + } +} +impl Cpp17EqualityComparableUnsafe for Inner { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Inner, + |__lhs, __rhs| { (unsafe { Inner::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Inner, + |__lhs, __rhs| { !(unsafe { Inner::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for Inner { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { Inner::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Inner { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Inner::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Inner::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Inner, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { Inner::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for Inner { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Inner::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -184,22 +447,19 @@ impl LessThanComparableUnsafe for Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct Outer { pub i: Inner, pub y: i32, } -impl ThreeWayComparableUnsafe for Outer { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const Outer) -> libcc2rs::StrongOrdering { +impl Outer { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Outer) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = (unsafe { let _arg0: *const Inner = &(*_a0).i; - ThreeWayComparableUnsafe::three_way(&raw const (*this).i, _arg0) + Inner::operator_cmp(&raw const (*this).i, _arg0) }); if !(libcc2rs::is_eq(cmp)) { return cmp; @@ -214,11 +474,84 @@ impl ThreeWayComparableUnsafe for 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 Cpp17EqualityComparableUnsafe for Outer { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Outer, + |__lhs, __rhs| { (unsafe { Outer::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Outer, + |__lhs, __rhs| { !(unsafe { Outer::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for Outer { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { Outer::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Outer { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Outer::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Outer::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Outer, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { Outer::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for Outer { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Outer::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -236,9 +569,17 @@ impl LessThanComparableUnsafe for Outer { pub struct Secondary { pub a: i32, } -impl ThreeWayComparableUnsafe for Secondary { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const Secondary) -> libcc2rs::StrongOrdering { +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, + ) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*this).a), &((*_a0).a))); @@ -248,13 +589,80 @@ impl ThreeWayComparableUnsafe for Secondary { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_lt(this: *const Self, _a0: *const Secondary) -> bool { + return libcc2rs::is_lt((unsafe { Secondary::operator_cmp(&raw const (*this), _a0) })); + } + pub unsafe fn operator_ge(this: *const Self, _a0: *const Secondary) -> bool { + return libcc2rs::is_gteq((unsafe { Secondary::operator_cmp(&raw const (*this), _a0) })); + } +} +impl Cpp17EqualityComparableUnsafe for Secondary { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Secondary, + |__lhs, __rhs| { (unsafe { Secondary::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Secondary { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Secondary, + |__lhs, __rhs| { (unsafe { Secondary::operator_ne(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for Secondary { - unsafe fn less(this: *const Self, _a0: *const Secondary) -> bool { - return libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const (*this), _a0) }), - ); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Secondary, + |__lhs, __rhs| { (unsafe { Secondary::operator_lt(&raw const (*__lhs), __rhs,) }) } + ); +} +impl PartiallyOrderedWithUnsafe for Secondary { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Secondary, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Secondary::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Secondary, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Secondary::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Secondary, + |__lhs, __rhs| { (unsafe { Secondary::operator_ge(&raw const (*__lhs), __rhs,) }) } + ); +} +impl ThreeWayComparableUnsafe for Secondary { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Secondary::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -266,17 +674,17 @@ impl LessThanComparableUnsafe for Secondary { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct PtrMember { pub p: *mut i32, } -impl ThreeWayComparableUnsafe for PtrMember { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, _a0: *const PtrMember) -> libcc2rs::StrongOrdering { +impl PtrMember { + pub unsafe fn operator_cmp( + this: *const Self, + _a0: *const PtrMember, + ) -> libcc2rs::StrongOrdering { { let mut cmp: libcc2rs::StrongOrdering = libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*this).p), &((*_a0).p))); @@ -286,11 +694,81 @@ impl ThreeWayComparableUnsafe for PtrMember { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); + } +} +impl Cpp17EqualityComparableUnsafe for PtrMember { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + PtrMember, + |__lhs, __rhs| { (unsafe { PtrMember::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + PtrMember, + |__lhs, __rhs| { !(unsafe { PtrMember::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for PtrMember { - unsafe fn less(this: *const Self, _a0: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, _a0)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { PtrMember::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for PtrMember { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { PtrMember::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { PtrMember::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + PtrMember, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { PtrMember::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for PtrMember { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { PtrMember::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } pub fn main() { unsafe { @@ -302,28 +780,27 @@ 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 { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e2,) })); - assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e3,) })); + assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); + assert!(!(unsafe { Eq::operator_eq(&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 }; let mut c4: Cmp = Cmp { a: 1, b: 9 }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const c1, &c2,) }) + (unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const c3, &c4,) }) + (unsafe { Cmp::operator_cmp(&raw const c3, &c4,) }) )); assert!( (unsafe { let _arg0: *const Cmp = &c1; - WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, _arg0) + Cmp::operator_eq(&raw const c1, _arg0) }) ); assert!({ - let __a = libcc2rs::PartialOrdering::from( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const c1, &c2) }), - ); + let __a = + libcc2rs::PartialOrdering::from((unsafe { Cmp::operator_cmp(&raw const c1, &c2) })); let __b = libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_LESS); libcc2rs::is_lt(__a) == libcc2rs::is_lt(__b) && libcc2rs::is_eq(__a) == libcc2rs::is_eq(__b) @@ -332,12 +809,12 @@ unsafe fn main_0() -> i32 { let mut b1: Both = Both { a: 1 }; let mut b2: Both = Both { a: 2 }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const b1, &b2,) }) + (unsafe { Both::operator_cmp(&raw const b1, &b2,) }) )); assert!( (unsafe { let _arg0: *const Both = &b2; - WeaklyEqualityComparableWithUnsafe::equal(&raw const b2, _arg0) + Both::operator_eq(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; @@ -366,13 +843,12 @@ unsafe fn main_0() -> i32 { y: 9, }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const x1, &x2,) }) + (unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) )); - assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const x1, &x3,) })); + assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); assert!({ - let __a = libcc2rs::PartialOrdering::from( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const x2, &x1) }), - ); + let __a = + libcc2rs::PartialOrdering::from((unsafe { Outer::operator_cmp(&raw const x2, &x1) })); let __b = libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_GREATER); libcc2rs::is_lt(__a) == libcc2rs::is_lt(__b) && libcc2rs::is_eq(__a) == libcc2rs::is_eq(__b) @@ -380,10 +856,10 @@ unsafe fn main_0() -> i32 { }); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const s1, &s2,) })); - assert!((unsafe { LessThanComparableUnsafe::less(&raw const s1, &s2,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::greater_equal(&raw const s2, &s1,) })); - assert!(!(unsafe { LessThanComparableUnsafe::less(&raw const s2, &s1,) })); + assert!((unsafe { Secondary::operator_ne(&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,) })); let mut arr: [i32; 2] = [0, 0]; let mut p1: PtrMember = PtrMember { p: arr.as_mut_ptr(), @@ -395,12 +871,12 @@ unsafe fn main_0() -> i32 { p: arr.as_mut_ptr(), }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const p1, &p2,) }) + (unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) )); - assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const p1, &p3,) })); + assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); assert!({ let __a = libcc2rs::PartialOrdering::from( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const p2, &p1) }), + (unsafe { PtrMember::operator_cmp(&raw const p2, &p1) }), ); let __b = libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_GREATER); libcc2rs::is_lt(__a) == libcc2rs::is_lt(__b) @@ -409,61 +885,4 @@ unsafe fn main_0() -> i32 { }); return 0; } -impl PartiallyOrderedWithUnsafe for Secondary { - unsafe fn greater_equal(this: *const Self, _a0: *const Secondary) -> bool { - return libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const (*this), _a0) }), - ); - } - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } - unsafe fn greater(lhs: *const Self, rhs: *const Self) -> bool { - libcc2rs::is_gt(ThreeWayComparableUnsafe::three_way(lhs, rhs)) - } - unsafe fn less_equal(lhs: *const Self, rhs: *const Self) -> bool { - libcc2rs::is_lteq(ThreeWayComparableUnsafe::three_way(lhs, rhs)) - } -} -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 3f29909619..91b4941e44 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -22,15 +22,144 @@ use std::rc::Rc; pub struct S { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_ne_1(_a, __rhs) + }) + } + ); +} impl LessThanComparableUnsafe for S { - unsafe fn less(a: *const S, b: *const S) -> bool { - return (((*a).v) < ((*b).v)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_lt_2(_a, __rhs) + }) + } + ); +} +impl PartiallyOrderedWithUnsafe for S { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_gt_3(_a, __rhs) + }) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_le_4(_a, __rhs) + }) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_ge_5(_a, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { + (unsafe { + let _a: *const S = __lhs; + operator_lt_6(_a, (*__rhs)) + }) + } + ); +} +impl LessThanComparableUnsafe for i32 { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = (*__lhs); + operator_lt_7(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_eq_0(a: *const S, b: *const S) -> bool { + return (((*a).v) == ((*b).v)); +} +pub unsafe fn operator_ne_1(a: *const S, b: *const S) -> bool { + return (((*a).v) != ((*b).v)); +} +pub unsafe fn operator_lt_2(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 { + return (((*a).v) > ((*b).v)); +} +pub unsafe fn operator_le_4(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 { + return (((*a).v) >= ((*b).v)); } -pub unsafe fn operator_lt_0(a: *const S, mut b: i32) -> bool { +pub unsafe fn operator_lt_6(a: *const S, mut b: i32) -> bool { return (((*a).v) < (b)); } -pub unsafe fn operator_lt_1(mut a: i32, b: *const S) -> bool { +pub unsafe fn operator_lt_7(mut a: i32, b: *const S) -> bool { return ((a) < ((*b).v)); } #[repr(C)] @@ -49,21 +178,61 @@ pub unsafe fn operator_lt_1(mut a: i32, b: *const S) -> bool { pub struct V { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for V { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + V, + |__lhs, __rhs| { + (unsafe { + let _a: V = (*__lhs); + operator_eq_8(_a, (*__rhs)) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for V { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + V, + |__lhs, __rhs| { + (unsafe { + let _a: V = (*__lhs); + operator_ne_9(_a, (*__rhs)) + }) + } + ); +} impl LessThanComparableUnsafe for V { - unsafe fn less(a: *const Self, b: *const Self) -> bool { - operator_lt_3((*a).clone(), (*b).clone()) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + V, + |__lhs, __rhs| { + (unsafe { + let _a: V = (*__lhs); + operator_lt_10(_a, (*__rhs)) + }) + } + ); } -pub unsafe fn operator_eq_4(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_2(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_ne_9(mut a: V, mut b: V) -> bool { return ((a.v) != (b.v)); } -pub unsafe fn operator_lt_3(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_lt_10(mut a: V, mut b: V) -> bool { return ((a.v) < (b.v)); } -pub unsafe fn operator_gt_5(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_gt_11(mut a: V, mut b: V) -> bool { return ((a.v) > (b.v)); } pub fn main() { @@ -79,31 +248,31 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: V = x; - operator_eq_4(_a, z) + operator_eq_8(_a, z) }) ); assert!( (unsafe { let _a: V = x; - operator_ne_2(_a, y) + operator_ne_9(_a, y) }) ); assert!( (unsafe { let _a: V = x; - operator_lt_3(_a, y) + operator_lt_10(_a, y) }) ); assert!( (unsafe { let _a: V = y; - operator_gt_5(_a, x) + operator_gt_11(_a, x) }) ); assert!( !(unsafe { let _a: V = y; - operator_lt_3(_a, x) + operator_lt_10(_a, x) }) ); let mut a: S = S { v: 1 }; @@ -112,82 +281,52 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - WeaklyEqualityComparableWithUnsafe::equal(_a, &c) + operator_eq_0(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - WeaklyEqualityComparableWithUnsafe::not_equal(_a, &b) + operator_ne_1(_a, &b) }) ); assert!( (unsafe { let _a: *const S = &a; - LessThanComparableUnsafe::less(_a, &b) + operator_lt_2(_a, &b) }) ); assert!( (unsafe { let _a: *const S = &b; - PartiallyOrderedWithUnsafe::greater(_a, &a) + operator_gt_3(_a, &a) }) ); assert!( (unsafe { let _a: *const S = &a; - PartiallyOrderedWithUnsafe::less_equal(_a, &c) + operator_le_4(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - PartiallyOrderedWithUnsafe::greater_equal(_a, &c) + operator_ge_5(_a, &c) }) ); assert!( !(unsafe { let _a: *const S = &b; - LessThanComparableUnsafe::less(_a, &a) + operator_lt_2(_a, &a) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_lt_0(_a, 5) + operator_lt_6(_a, 5) }) ); - assert!((unsafe { operator_lt_1(0, &a,) })); + assert!((unsafe { operator_lt_7(0, &a,) })); return 0; } -impl PartiallyOrderedWithUnsafe for S { - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } - unsafe fn greater(a: *const S, b: *const S) -> bool { - return (((*a).v) > ((*b).v)); - } - unsafe fn less_equal(a: *const S, b: *const S) -> bool { - return (((*a).v) <= ((*b).v)); - } - unsafe fn greater_equal(a: *const S, b: *const S) -> bool { - return (((*a).v) >= ((*b).v)); - } -} -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_2((*a).clone(), (*b).clone()) - } - unsafe fn equal(a: *const Self, b: *const Self) -> bool { - operator_eq_4((*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 4e3b54c8b4..e7c8542c87 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -23,14 +23,93 @@ 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)); + } + pub unsafe fn operator_gt(this: *const Self, o: *const S) -> bool { + return (((*this).v) > ((*o).v)); + } + pub unsafe fn operator_le(this: *const Self, o: *const S) -> bool { + return (((*this).v) <= ((*o).v)); + } + pub unsafe fn operator_ge(this: *const Self, o: *const S) -> bool { + return (((*this).v) >= ((*o).v)); + } pub unsafe fn operator_lt_7(this: *const Self, mut o: i32) -> bool { return (((*this).v) < (o)); } } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_ne(&raw const (*__lhs), __rhs,) }) } + ); +} impl LessThanComparableUnsafe for S { - unsafe fn less(this: *const Self, o: *const S) -> bool { - return (((*this).v) < ((*o).v)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_lt_3(&raw const (*__lhs), __rhs,) }) } + ); +} +impl PartiallyOrderedWithUnsafe for S { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_gt(&raw const (*__lhs), __rhs,) }) } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_le(&raw const (*__lhs), __rhs,) }) } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_ge(&raw const (*__lhs), __rhs,) }) } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { (unsafe { S::operator_lt_7(&raw const (*__lhs), (*__rhs),) }) } + ); } pub fn main() { unsafe { @@ -42,36 +121,14 @@ 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 { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &c,) })); - assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const a, &b,) })); - assert!((unsafe { LessThanComparableUnsafe::less(&raw const a, &b,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::greater(&raw const b, &a,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::less_equal(&raw const a, &c,) })); - assert!((unsafe { PartiallyOrderedWithUnsafe::greater_equal(&raw const a, &c,) })); - assert!(!(unsafe { LessThanComparableUnsafe::less(&raw const b, &a,) })); + assert!((unsafe { S::operator_eq(&raw const a, &c,) })); + assert!((unsafe { S::operator_ne(&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,) })); + assert!((unsafe { S::operator_ge(&raw const a, &c,) })); + assert!(!(unsafe { S::operator_lt_3(&raw const b, &a,) })); assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } -impl PartiallyOrderedWithUnsafe for S { - unsafe fn greater(this: *const Self, o: *const S) -> bool { - return (((*this).v) > ((*o).v)); - } - unsafe fn less_equal(this: *const Self, o: *const S) -> bool { - return (((*this).v) <= ((*o).v)); - } - unsafe fn greater_equal(this: *const Self, o: *const S) -> bool { - return (((*this).v) >= ((*o).v)); - } - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } -} -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_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index a19dca88fe..7abfb2205b 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -42,6 +42,231 @@ impl S { return (((*this).v) >= (((*o) as i32) - (('0' as libc::c_char) as i32))); } } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + i32, + |__lhs, __rhs| { (unsafe { S::operator_eq(&raw const (*__lhs), (*__rhs),) }) } + ); +} +impl Cpp17EqualityComparableUnsafe for i32 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = (*__lhs); + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + i32, + |__lhs, __rhs| { (unsafe { S::operator_ne(&raw const (*__lhs), (*__rhs),) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = (*__lhs); + operator_ne_1(_a, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + i32, + |__lhs, __rhs| { (unsafe { S::operator_lt(&raw const (*__lhs), (*__rhs),) }) } + ); +} +impl LessThanComparableUnsafe for i32 { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = (*__lhs); + operator_lt_2(_a, __rhs) + }) + } + ); +} +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + f64, + |__lhs, __rhs| { (unsafe { S::operator_eq(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl Cpp17EqualityComparableUnsafe for f64 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + f64, + |__lhs, __rhs| { (unsafe { S::operator_ne(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for f64 { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_ne_1(_a, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + f64, + |__lhs, __rhs| { (unsafe { S::operator_lt(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl LessThanComparableUnsafe for f64 { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_lt_2(_a, __rhs) + }) + } + ); +} +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + i64, + |__lhs, __rhs| { (unsafe { S::operator_eq(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl Cpp17EqualityComparableUnsafe for i64 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + i64, + |__lhs, __rhs| { (unsafe { S::operator_ne(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for i64 { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_ne_1(_a, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + i64, + |__lhs, __rhs| { (unsafe { S::operator_lt(&raw const (*__lhs), ((*__rhs) as i32),) }) } + ); +} +impl LessThanComparableUnsafe for i64 { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _a: i32 = ((*__lhs) as i32); + operator_lt_2(_a, __rhs) + }) + } + ); +} pub unsafe fn operator_eq_0(mut a: i32, b: *const S) -> bool { return ((a) == ((*b).v)); } diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index d267606bf5..b379e47a2e 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -22,27 +22,156 @@ use std::rc::Rc; pub struct X { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for X { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_eq_0(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_eq_0(_a, (*__rhs)) + }) != 0) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for X { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_ne_1(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_ne_1(_a, (*__rhs)) + }) != 0) + } + ); +} impl LessThanComparableUnsafe for X { - unsafe fn less(a: *const Self, b: *const Self) -> bool { - ((operator_lt_4((*a).clone(), (*b).clone())) != 0) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_lt_2(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_lt_2(_a, (*__rhs)) + }) != 0) + } + ); +} +impl PartiallyOrderedWithUnsafe for X { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_gt_3(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_gt_3(_a, (*__rhs)) + }) != 0) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_le_4(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_le_4(_a, (*__rhs)) + }) != 0) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = i32, + X, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: X = (*__lhs); + operator_ge_5(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: X = (*__lhs); + operator_ge_5(_a, (*__rhs)) + }) != 0) + } + ); } -pub unsafe fn operator_eq_5(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_eq_0(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } -pub unsafe fn operator_ne_0(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_ne_1(mut a: X, mut b: X) -> i32 { return if ((a.v) != (b.v)) { 3 } else { 0 }; } -pub unsafe fn operator_lt_4(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_lt_2(mut a: X, mut b: X) -> i32 { return if ((a.v) < (b.v)) { 4 } else { 0 }; } -pub unsafe fn operator_gt_1(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_gt_3(mut a: X, mut b: X) -> i32 { return if ((a.v) > (b.v)) { 5 } else { 0 }; } -pub unsafe fn operator_le_2(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_le_4(mut a: X, mut b: X) -> i32 { return if ((a.v) <= (b.v)) { 6 } else { 0 }; } -pub unsafe fn operator_ge_3(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_ge_5(mut a: X, mut b: X) -> i32 { return if ((a.v) >= (b.v)) { 7 } else { 0 }; } #[repr(C)] @@ -113,10 +242,31 @@ impl Mixed { return if (((*this).v) == ((*o).v)) { 9 } else { 0 }; } } +impl Cpp17EqualityComparableUnsafe for Mixed { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + Mixed, + |__return, __lhs, __rhs| { + __return.write((unsafe { Mixed::operator_eq(&raw const (*__lhs), __rhs) })); + }, + |__lhs, __rhs| { ((unsafe { Mixed::operator_eq(&raw const (*__lhs), __rhs,) }) != 0) } + ); +} impl LessThanComparableUnsafe for Mixed { - unsafe fn less(this: *const Self, o: *const Self) -> bool { - ((Mixed::operator_lt(this, o)) != 0) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = i32, + Mixed, + |__return, __lhs, __rhs| { + __return.write((unsafe { Mixed::operator_lt(&raw const (*__lhs), __rhs) })); + }, + |__lhs, __rhs| { ((unsafe { Mixed::operator_lt(&raw const (*__lhs), __rhs,) }) != 0) } + ); } #[repr(C)] #[derive( @@ -144,6 +294,93 @@ impl MyBool { return (*this).value; } } +impl Cpp17EqualityComparableUnsafe for MyBool { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + == ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for MyBool { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + != ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl LessThanComparableUnsafe for MyBool { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + < ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl PartiallyOrderedWithUnsafe for MyBool { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + > ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + <= ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + MyBool, + |__lhs, __rhs| { + (((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32) + >= ((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl ThreeWayComparableUnsafe for MyBool { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &((unsafe { MyBool::to_bool(&raw const (*__lhs)) }) as i32), + &((unsafe { MyBool::to_bool(&raw const (*__rhs)) }) as i32), + )) + } + ); +} #[repr(C)] #[derive( Copy, @@ -160,22 +397,68 @@ impl MyBool { pub struct Boolish { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for Boolish { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = MyBool, + Boolish, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: Boolish = (*__lhs); + operator_eq_6(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + (unsafe { + MyBool::to_bool( + &(unsafe { + let _a: Boolish = (*__lhs); + operator_eq_6(_a, (*__rhs)) + }), + ) + }) + } + ); +} impl LessThanComparableUnsafe for Boolish { - unsafe fn less(a: *const Self, b: *const Self) -> bool { - { - let __cmp = operator_lt_6((*a).clone(), (*b).clone()); - MyBool::to_bool((&raw const __cmp)) + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = MyBool, + Boolish, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: Boolish = (*__lhs); + operator_lt_7(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + (unsafe { + MyBool::to_bool( + &(unsafe { + let _a: Boolish = (*__lhs); + operator_lt_7(_a, (*__rhs)) + }), + ) + }) } - } + ); } -pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { +pub unsafe fn operator_eq_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); MyBool::constructor_1(&raw mut __v, ((a.v) == (b.v))); __v }; } -pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { +pub unsafe fn operator_lt_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); MyBool::constructor_1(&raw mut __v, ((a.v) < (b.v))); @@ -206,6 +489,93 @@ impl RefBool { return (*this).value; } } +impl Cpp17EqualityComparableUnsafe for RefBool { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + == ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for RefBool { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + != ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl LessThanComparableUnsafe for RefBool { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + < ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl PartiallyOrderedWithUnsafe for RefBool { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + > ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + <= ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + RefBool, + |__lhs, __rhs| { + (((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32) + >= ((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32)) + } + ); +} +impl ThreeWayComparableUnsafe for RefBool { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp( + &((unsafe { RefBool::to_bool(&raw const (*__lhs)) }) as i32), + &((unsafe { RefBool::to_bool(&raw const (*__rhs)) }) as i32), + )) + } + ); +} pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: RefBool = ZeroInitializationUnsafe::zero_init(); @@ -234,6 +604,10 @@ impl RefInt { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } +impl Cpp17EqualityComparableUnsafe for RefInt { + comparison_unsafe! ( Cpp17EqualityComparableUnsafe , equal , is_equal , EqualResult = LvalueRefUnsafe , RefInt , |__return, __lhs, __rhs| { __return .write ( LvalueRefUnsafe ::bind ( & mut ( * ( unsafe { RefInt :: operator_eq ( &raw const ( * __lhs ) , __rhs , ) } ) ) ) ) ; +} , |__lhs, __rhs| { ( unsafe { RefBool :: to_bool ( &raw const ( * ( unsafe { RefInt :: operator_eq ( &raw const ( * __lhs ) , __rhs , ) } ) ) , ) } ) } ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -247,43 +621,43 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _a: X = a; - operator_eq_5(_a, c) + operator_eq_0(_a, c) }) == (2)) ); assert!( ((unsafe { let _a: X = a; - operator_eq_5(_a, b) + operator_eq_0(_a, b) }) == (0)) ); assert!( ((unsafe { let _a: X = a; - operator_ne_0(_a, b) + operator_ne_1(_a, b) }) == (3)) ); assert!( ((unsafe { let _a: X = a; - operator_lt_4(_a, b) + operator_lt_2(_a, b) }) == (4)) ); assert!( ((unsafe { let _a: X = b; - operator_gt_1(_a, a) + operator_gt_3(_a, a) }) == (5)) ); assert!( ((unsafe { let _a: X = a; - operator_le_2(_a, c) + operator_le_4(_a, c) }) == (6)) ); assert!( ((unsafe { let _a: X = a; - operator_ge_3(_a, c) + operator_ge_5(_a, c) }) == (7)) ); let mut xs: [X; 3] = [X { v: 3 }, X { v: 1 }, X { v: 2 }]; @@ -292,11 +666,17 @@ unsafe fn main_0() -> i32 { let __n = xs.as_mut_ptr().offset((3) as isize).iter_distance(&__tmp_0); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_0.iter_at(__x) as *const X; + let __b = __tmp_0.iter_at(__y) as *const X; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -328,11 +708,17 @@ unsafe fn main_0() -> i32 { let __n = ms.as_mut_ptr().offset((3) as isize).iter_distance(&__tmp_1); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_1.iter_at(__x) as *const _; - let __b = __tmp_1.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_1.iter_at(__x) as *const Mixed; + let __b = __tmp_1.iter_at(__y) as *const Mixed; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -363,7 +749,7 @@ unsafe fn main_0() -> i32 { MyBool::to_bool( &(unsafe { let _a: Boolish = b1; - operator_eq_7(_a, Boolish { v: 1 }) + operator_eq_6(_a, Boolish { v: 1 }) }), ) }) @@ -373,14 +759,14 @@ unsafe fn main_0() -> i32 { MyBool::to_bool( &(unsafe { let _a: Boolish = b2; - operator_lt_6(_a, b1) + operator_lt_7(_a, b1) }), ) }) ); let mut lt: MyBool = (unsafe { let _a: Boolish = b1; - operator_lt_6(_a, b2) + operator_lt_7(_a, b2) }); assert!(lt.value); let mut bs: [Boolish; 3] = [Boolish { v: 3 }, Boolish { v: 1 }, Boolish { v: 2 }]; @@ -389,11 +775,17 @@ unsafe fn main_0() -> i32 { let __n = bs.as_mut_ptr().offset((3) as isize).iter_distance(&__tmp_2); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_2.iter_at(__x) as *const _; - let __b = __tmp_2.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_2.iter_at(__x) as *const Boolish; + let __b = __tmp_2.iter_at(__y) as *const Boolish; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -423,9 +815,13 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) - { + while <*mut RefInt as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_3), + ) && !>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&ri2), + ) { __it.iter_inc(); } __it @@ -433,49 +829,6 @@ unsafe fn main_0() -> i32 { ); return 0; } -impl PartiallyOrderedWithUnsafe for X { - unsafe fn less(lhs: *const Self, rhs: *const Self) -> bool { - ::less(lhs, rhs) - } - unsafe fn greater(lhs: *const Self, rhs: *const Self) -> bool { - ((operator_gt_1((*lhs).clone(), (*rhs).clone())) != 0) - } - unsafe fn less_equal(lhs: *const Self, rhs: *const Self) -> bool { - ((operator_le_2((*lhs).clone(), (*rhs).clone())) != 0) - } - unsafe fn greater_equal(lhs: *const Self, rhs: *const Self) -> bool { - ((operator_ge_3((*lhs).clone(), (*rhs).clone())) != 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_5((*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 d2172b3b03..19ab6e2a87 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,10 +6,11 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -impl LessThanComparableUnsafe for S { - unsafe fn less(x: *const S, y: *const S) -> bool { - return (((*x).data_) < ((*y).data_)); - } +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 { + return (((*x).data_) < ((*y).data_)); } #[repr(C)] #[derive( @@ -27,6 +28,36 @@ impl S { (&raw mut (*this).data_).write(data); } } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _x: *const S = __lhs; + operator_eq_0(_x, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + (unsafe { + let _x: *const S = __lhs; + operator_lt_1(_x, __rhs) + }) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -40,26 +71,21 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &a; - WeaklyEqualityComparableWithUnsafe::equal(_x, &c) + operator_eq_0(_x, &c) }) ); assert!( (unsafe { let _x: *const S = &a; - LessThanComparableUnsafe::less(_x, &b) + operator_lt_1(_x, &b) }) ); assert!( !(unsafe { let _x: *const S = &b; - LessThanComparableUnsafe::less(_x, &a) + operator_lt_1(_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 1d43aabf16..9d6722291e 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -6,6 +6,9 @@ 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, @@ -23,21 +26,51 @@ pub struct Defaulted { pub a: i32, pub b: i32, } -impl ThreeWayComparableUnsafe for DefaultedOrd { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way( - _a0: *const DefaultedOrd, - _a1: *const DefaultedOrd, - ) -> libcc2rs::StrongOrdering { - { - let mut cmp: libcc2rs::StrongOrdering = - libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*_a0).a), &((*_a1).a))); - if !(libcc2rs::is_eq(cmp)) { - return cmp; - } +impl Cpp17EqualityComparableUnsafe for Defaulted { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Defaulted, + |__lhs, __rhs| { + (unsafe { + let _arg0: *const Defaulted = __lhs; + operator_eq_0(_arg0, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Defaulted { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Defaulted, + |__lhs, __rhs| { + !(unsafe { + let _arg0: *const Defaulted = __lhs; + operator_eq_0(_arg0, __rhs) + }) + } + ); +} +pub unsafe fn operator_cmp_1( + _a0: *const DefaultedOrd, + _a1: *const DefaultedOrd, +) -> libcc2rs::StrongOrdering { + { + let mut cmp: libcc2rs::StrongOrdering = + libcc2rs::StrongOrdering::from(std::cmp::Ord::cmp(&((*_a0).a), &((*_a1).a))); + if !(libcc2rs::is_eq(cmp)) { + return cmp; } - return libcc2rs::STRONG_ORDERING_EQUAL; } + 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( @@ -49,25 +82,126 @@ impl ThreeWayComparableUnsafe for DefaultedOrd { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct DefaultedOrd { pub a: i32, } +impl Cpp17EqualityComparableUnsafe for DefaultedOrd { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_eq_2(_arg0, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + !(unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_eq_2(_arg0, __rhs) + }) + } + ); +} impl LessThanComparableUnsafe for DefaultedOrd { - unsafe fn less(_a0: *const Self, _a1: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(_a0, _a1)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_lt( + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_cmp_1(_arg0, __rhs) + }), + ) + } + ); } -impl LessThanComparableUnsafe for Inline { - unsafe fn less(x: *const Inline, y: *const Inline) -> bool { - return (((*x).a) < ((*y).a)); - } +impl PartiallyOrderedWithUnsafe for DefaultedOrd { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_gt( + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_cmp_1(_arg0, __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_lteq( + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_cmp_1(_arg0, __rhs) + }), + ) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + DefaultedOrd, + |__lhs, __rhs| { + libcc2rs::is_gteq( + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_cmp_1(_arg0, __rhs) + }), + ) + } + ); } -pub unsafe fn operator_add_0(x: *const Inline, y: *const Inline) -> Inline { +impl ThreeWayComparableUnsafe for DefaultedOrd { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { + (unsafe { + let _arg0: *const DefaultedOrd = __lhs; + operator_cmp_1(_arg0, __rhs) + }) + } + ); +} +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 { + return (((*x).a) < ((*y).a)); +} +pub unsafe fn operator_add_5(x: *const Inline, y: *const Inline) -> Inline { return Inline { a: (((*x).a) + ((*y).a)), }; @@ -88,6 +222,51 @@ pub unsafe fn operator_add_0(x: *const Inline, y: *const Inline) -> Inline { pub struct Inline { pub a: i32, } +impl Cpp17EqualityComparableUnsafe for Inline { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Inline, + |__lhs, __rhs| { + (unsafe { + let _x: *const Inline = __lhs; + operator_eq_3(_x, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Inline { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Inline, + |__lhs, __rhs| { + !(unsafe { + let _x: *const Inline = __lhs; + operator_eq_3(_x, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for Inline { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Inline, + |__lhs, __rhs| { + (unsafe { + let _x: *const Inline = __lhs; + operator_lt_4(_x, __rhs) + }) + } + ); +} #[repr(C)] #[derive( Copy, @@ -104,10 +283,53 @@ pub struct Inline { pub struct OutOfLine { pub a: i32, } -impl LessThanComparableUnsafe for Tmpl_int_ { - unsafe fn less(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { - return (((*x).v) < ((*y).v)); - } +impl Cpp17EqualityComparableUnsafe for OutOfLine { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + OutOfLine, + |__lhs, __rhs| { + (unsafe { + let _x: *const OutOfLine = __lhs; + operator_eq_6(_x, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for OutOfLine { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + OutOfLine, + |__lhs, __rhs| { + (unsafe { + let _x: *const OutOfLine = __lhs; + operator_ne_7(_x, __rhs) + }) + } + ); +} +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 { + 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( @@ -125,6 +347,57 @@ impl LessThanComparableUnsafe for Tmpl_int_ { pub struct Tmpl_int_ { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for Tmpl_int_ { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Tmpl_int_, + |__lhs, __rhs| { + (unsafe { + let _x: *const Tmpl_int_ = __lhs; + operator_eq_8(_x, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Tmpl_int_, + |__lhs, __rhs| { + !(unsafe { + let _x: *const Tmpl_int_ = __lhs; + operator_eq_8(_x, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for Tmpl_int_ { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Tmpl_int_, + |__lhs, __rhs| { + (unsafe { + let _x: *const Tmpl_int_ = __lhs; + operator_lt_9(_x, __rhs) + }) + } + ); +} +pub unsafe fn operator_eq_11(x: *const Tmpl_long_, y: *const Tmpl_long_) -> bool { + return (((*x).v) == ((*y).v)); +} +pub unsafe fn operator_lt_12(x: *const Tmpl_long_, y: *const Tmpl_long_) -> bool { + return (((*x).v) < ((*y).v)); +} #[repr(C)] #[derive( Copy, @@ -141,6 +414,57 @@ pub struct Tmpl_int_ { pub struct Tmpl_long_ { pub v: i64, } +impl Cpp17EqualityComparableUnsafe for Tmpl_long_ { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Tmpl_long_, + |__lhs, __rhs| { + (unsafe { + let _x: *const Tmpl_long_ = __lhs; + operator_eq_11(_x, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_long_ { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Tmpl_long_, + |__lhs, __rhs| { + !(unsafe { + let _x: *const Tmpl_long_ = __lhs; + operator_eq_11(_x, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for Tmpl_long_ { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Tmpl_long_, + |__lhs, __rhs| { + (unsafe { + let _x: *const Tmpl_long_ = __lhs; + operator_lt_12(_x, __rhs) + }) + } + ); +} +pub unsafe fn operator_eq_13( + _a0: *const TmplDefaulted_int_, + _a1: *const TmplDefaulted_int_, +) -> bool { + return (((*_a0).v) == ((*_a1).v)); +} #[repr(C)] #[derive( Copy, @@ -157,6 +481,36 @@ pub struct Tmpl_long_ { pub struct TmplDefaulted_int_ { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for TmplDefaulted_int_ { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + TmplDefaulted_int_, + |__lhs, __rhs| { + (unsafe { + let _arg0: *const TmplDefaulted_int_ = __lhs; + operator_eq_13(_arg0, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + TmplDefaulted_int_, + |__lhs, __rhs| { + !(unsafe { + let _arg0: *const TmplDefaulted_int_ = __lhs; + operator_eq_13(_arg0, __rhs) + }) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -170,19 +524,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d2) + operator_eq_0(_arg0, &d2) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) + operator_eq_0(_arg0, &d3) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) + operator_eq_0(_arg0, &d3) }) ); let mut o1: DefaultedOrd = DefaultedOrd { a: 1 }; @@ -190,27 +544,27 @@ unsafe fn main_0() -> i32 { assert!(libcc2rs::is_lt( (unsafe { let _arg0: *const DefaultedOrd = &o1; - ThreeWayComparableUnsafe::three_way(_arg0, &o2) + operator_cmp_1(_arg0, &o2) }) )); assert!(libcc2rs::is_gt( (unsafe { let _arg0: *const DefaultedOrd = &o2; - ThreeWayComparableUnsafe::three_way(_arg0, &o1) + operator_cmp_1(_arg0, &o1) }) )); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; let _arg1: *const DefaultedOrd = &o1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, _arg1) + operator_eq_2(_arg0, _arg1) }) ); assert!({ let __a = libcc2rs::PartialOrdering::from( (unsafe { let _arg0: *const DefaultedOrd = &o1; - ThreeWayComparableUnsafe::three_way(_arg0, &o2) + operator_cmp_1(_arg0, &o2) }), ); let __b = libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_LESS); @@ -224,35 +578,35 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Inline = &i1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &i3) + operator_eq_3(_x, &i3) }) ); assert!( !(unsafe { let _x: *const Inline = &i1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &i2) + operator_eq_3(_x, &i2) }) ); assert!( (unsafe { let _x: *const Inline = &i1; - LessThanComparableUnsafe::less(_x, &i2) + operator_lt_4(_x, &i2) }) ); assert!( !(unsafe { let _x: *const Inline = &i2; - LessThanComparableUnsafe::less(_x, &i1) + operator_lt_4(_x, &i1) }) ); assert!( (unsafe { let mut _x: Inline = (unsafe { let _x: *const Inline = &i1; - operator_add_0(_x, &i2) + operator_add_5(_x, &i2) }); let mut _y: Inline = Inline { a: 3 }; - WeaklyEqualityComparableWithUnsafe::equal(&mut _x, &mut _y) + operator_eq_3(&mut _x, &mut _y) }) ); let mut f1: OutOfLine = OutOfLine { a: 4 }; @@ -261,19 +615,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const OutOfLine = &f1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &f2) + operator_eq_6(_x, &f2) }) ); assert!( (unsafe { let _x: *const OutOfLine = &f1; - WeaklyEqualityComparableWithUnsafe::not_equal(_x, &f3) + operator_ne_7(_x, &f3) }) ); assert!( !(unsafe { let _x: *const OutOfLine = &f1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &f3) + operator_eq_6(_x, &f3) }) ); let mut t1: Tmpl_int_ = Tmpl_int_ { v: 1 }; @@ -282,19 +636,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &t3) + operator_eq_8(_x, &t3) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &t2) + operator_eq_8(_x, &t2) }) ); assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - LessThanComparableUnsafe::less(_x, &t2) + operator_lt_9(_x, &t2) }) ); let mut u1: Tmpl_long_ = Tmpl_long_ { v: 1_i64 }; @@ -302,13 +656,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &u1) + operator_eq_10(_x, &u1) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(_x, &u2) + operator_eq_10(_x, &u2) }) ); let mut v1: TmplDefaulted_int_ = TmplDefaulted_int_ { v: 7 }; @@ -317,67 +671,21 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v2) + operator_eq_13(_arg0, &v2) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) + operator_eq_13(_arg0, &v3) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) + operator_eq_13(_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 a80f6bd106..21228414ef 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -29,11 +29,6 @@ impl Pair { || ((((*this).x) == ((*other).x)) && (((*this).y) < ((*other).y))); } } -impl LessThanComparableUnsafe for Pair { - unsafe fn less(this: *const Self, other: *const Self) -> bool { - Pair::operator_lt(this.cast_mut(), other) - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index d14ee5c86c..35306a244c 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -65,6 +65,80 @@ impl S { return (((*this).v) != (0)); } } +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + == (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + != (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl LessThanComparableUnsafe for S { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + < (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for S { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + > (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + <= (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { + ((unsafe { S::to_i32(&raw const (*__lhs)) }) + >= (unsafe { S::to_i32(&raw const (*__rhs)) })) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index 1f690397e0..2866133b35 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -45,22 +45,107 @@ impl S { return ((((*this).v) * (o)) + (1)); } } -pub unsafe fn operator_div_0(a: *const S, b: *const S) -> i32 { +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + i32, + |__return, __lhs, __rhs| { + __return.write((unsafe { S::operator_eq_1(&raw const (*__lhs), (*__rhs)) })); + }, + |__lhs, __rhs| { ((unsafe { S::operator_eq_1(&raw const (*__lhs), (*__rhs),) }) != 0) } + ); +} +impl Cpp17EqualityComparableUnsafe for i32 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + S, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: i32 = (*__lhs); + operator_eq_0(_a, (*__rhs)) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: i32 = (*__lhs); + operator_eq_0(_a, (*__rhs)) + }) != 0) + } + ); +} +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + i64, + |__return, __lhs, __rhs| { + __return.write((unsafe { S::operator_eq_2(&raw const (*__lhs), (*__rhs)) })); + }, + |__lhs, __rhs| { ((unsafe { S::operator_eq_2(&raw const (*__lhs), (*__rhs),) }) != 0) } + ); +} +impl Cpp17EqualityComparableUnsafe for i64 { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + S, + |__return, __lhs, __rhs| { + __return.write( + (unsafe { + let _a: i64 = (*__lhs); + operator_eq_1(_a, __rhs) + }), + ); + }, + |__lhs, __rhs| { + ((unsafe { + let _a: i64 = (*__lhs); + operator_eq_1(_a, __rhs) + }) != 0) + } + ); +} +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = i32, + f64, + |__return, __lhs, __rhs| { + __return.write((unsafe { S::operator_eq_3(&raw const (*__lhs), (*__rhs)) })); + }, + |__lhs, __rhs| { ((unsafe { S::operator_eq_3(&raw const (*__lhs), (*__rhs),) }) != 0) } + ); +} +pub unsafe fn operator_div_2(a: *const S, b: *const S) -> i32 { return (((*a).v) / ((*b).v)); } -pub unsafe fn operator_div_1(mut a: S, mut b: i32) -> i32 { +pub unsafe fn operator_div_3(mut a: S, mut b: i32) -> i32 { return (((a.v) / (b)) + (1)); } -pub unsafe fn operator_rem_2(mut a: S, mut b: S) -> i32 { +pub unsafe fn operator_rem_4(mut a: S, mut b: S) -> i32 { return ((a.v) % (b.v)); } -pub unsafe fn operator_rem_3(a: *const S, mut b: i32) -> i32 { +pub unsafe fn operator_rem_5(a: *const S, mut b: i32) -> i32 { return ((((*a).v) % (b)) + (1)); } -pub unsafe fn operator_eq_4(mut a: i32, mut b: S) -> i32 { +pub unsafe fn operator_eq_0(mut a: i32, mut b: S) -> i32 { return if ((a) == (b.v)) { 4 } else { 0 }; } -pub unsafe fn operator_eq_5(mut a: i64, b: *const S) -> i32 { +pub unsafe fn operator_eq_1(mut a: i64, b: *const S) -> i32 { return if ((a) == ((*b).v as i64)) { 5 } else { 0 }; } pub fn main() { @@ -83,29 +168,29 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _a: *const S = &s; - operator_div_0(_a, &t) + operator_div_2(_a, &t) }) == (1)) ); assert!( ((unsafe { let _a: S = s; - operator_div_1(_a, 4) + operator_div_3(_a, 4) }) == (2)) ); assert!( ((unsafe { let _a: S = s; - operator_rem_2(_a, t) + operator_rem_4(_a, t) }) == (2)) ); assert!( ((unsafe { let _a: *const S = &s; - operator_rem_3(_a, 4) + operator_rem_5(_a, 4) }) == (3)) ); - assert!(((unsafe { operator_eq_4(6, s,) }) == (4))); - assert!(((unsafe { operator_eq_5(6_i64, &s,) }) == (5))); + assert!(((unsafe { operator_eq_0(6, s,) }) == (4))); + assert!(((unsafe { operator_eq_1(6_i64, &s,) }) == (5))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index adab99e390..5a93451f72 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -16,17 +16,14 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct S { pub v: i32, } -impl ThreeWayComparableUnsafe for S { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, o: *const S) -> libcc2rs::StrongOrdering { +impl S { + pub unsafe fn operator_cmp(this: *const Self, o: *const S) -> libcc2rs::StrongOrdering { if (((*this).v) < ((*o).v)) { return libcc2rs::STRONG_ORDERING_LESS; } @@ -35,11 +32,81 @@ impl ThreeWayComparableUnsafe for S { } return libcc2rs::STRONG_ORDERING_EQUAL; } + pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl Cpp17EqualityComparableUnsafe for S { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + S, + |__lhs, __rhs| { (unsafe { S::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for S { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + S, + |__lhs, __rhs| { !(unsafe { S::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for S { - unsafe fn less(this: *const Self, o: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, o)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { S::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for S { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { S::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { S::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + S, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { S::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for S { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { S::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } pub fn main() { unsafe { @@ -51,22 +118,20 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; assert!(libcc2rs::is_lt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const a, &b,) }) + (unsafe { S::operator_cmp(&raw const a, &b,) }) )); assert!(libcc2rs::is_gt( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const b, &a,) }) + (unsafe { S::operator_cmp(&raw const b, &a,) }) )); assert!(libcc2rs::is_lteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const a, &b,) }) + (unsafe { S::operator_cmp(&raw const a, &b,) }) )); assert!(libcc2rs::is_gteq( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const b, &a,) }) + (unsafe { S::operator_cmp(&raw const b, &a,) }) )); - assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &b,) })); + assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); assert!({ - let __a = libcc2rs::PartialOrdering::from( - (unsafe { ThreeWayComparableUnsafe::three_way(&raw const a, &b) }), - ); + let __a = libcc2rs::PartialOrdering::from((unsafe { S::operator_cmp(&raw const a, &b) })); let __b = libcc2rs::PartialOrdering::from(libcc2rs::STRONG_ORDERING_LESS); libcc2rs::is_lt(__a) == libcc2rs::is_lt(__b) && libcc2rs::is_eq(__a) == libcc2rs::is_eq(__b) @@ -74,9 +139,4 @@ unsafe fn main_0() -> i32 { }); 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 befbfad472..c5b2f53a6e 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -22,11 +22,21 @@ use std::rc::Rc; pub struct Lt { pub v: i32, } -impl LessThanComparableUnsafe for Lt { - unsafe fn less(this: *const Self, o: *const Lt) -> bool { +impl Lt { + pub unsafe fn operator_lt(this: *const Self, o: *const Lt) -> bool { return (((*this).v) < ((*o).v)); } } +impl LessThanComparableUnsafe for Lt { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Lt, + |__lhs, __rhs| { (unsafe { Lt::operator_lt(&raw const (*__lhs), __rhs,) }) } + ); +} #[repr(C)] #[derive( Copy, @@ -43,6 +53,31 @@ impl LessThanComparableUnsafe 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 Cpp17EqualityComparableUnsafe for Eq { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Eq, + |__lhs, __rhs| { (unsafe { Eq::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Eq, + |__lhs, __rhs| { !(unsafe { Eq::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} #[repr(C)] #[derive( Copy, @@ -53,24 +88,91 @@ pub struct Eq { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, - PartiallyOrderedWithUnsafe, + ConversionsUnsafe, )] -#[three_way(ThreeWayComparableUnsafe::three_way)] -#[derive(ConversionsUnsafe)] #[conversions(copy, move)] pub struct Cmp { pub v: i32, } -impl ThreeWayComparableUnsafe for Cmp { - type Category = libcc2rs::StrongOrdering; - unsafe fn three_way(this: *const Self, o: *const Cmp) -> libcc2rs::StrongOrdering { +impl Cmp { + pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> libcc2rs::StrongOrdering { return libcc2rs::StrongOrdering::from(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 Cpp17EqualityComparableUnsafe for Cmp { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Cmp, + |__lhs, __rhs| { (unsafe { Cmp::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Cmp, + |__lhs, __rhs| { !(unsafe { Cmp::operator_eq(&raw const (*__lhs), __rhs,) }) } + ); } impl LessThanComparableUnsafe for Cmp { - unsafe fn less(this: *const Self, o: *const Self) -> bool { - libcc2rs::is_lt(ThreeWayComparableUnsafe::three_way(this, o)) - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lt((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Cmp { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gt((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_lteq((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Cmp, + |__lhs, __rhs| { + libcc2rs::is_gteq((unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs) })) + } + ); +} +impl ThreeWayComparableUnsafe for Cmp { + comparison_unsafe!( + ThreeWayComparableUnsafe, + three_way, + Category = libcc2rs::StrongOrdering, + |__lhs, __rhs| { (unsafe { Cmp::operator_cmp(&raw const (*__lhs), __rhs,) }) } + ); } #[repr(C)] #[derive( @@ -88,10 +190,62 @@ impl LessThanComparableUnsafe for Cmp { pub struct Free { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for Free { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Free, + |__lhs, __rhs| { + (unsafe { + let _a: *const Free = __lhs; + operator_eq_0(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Free { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Free, + |__lhs, __rhs| { + !(unsafe { + let _a: *const Free = __lhs; + operator_eq_0(_a, __rhs) + }) + } + ); +} impl LessThanComparableUnsafe for Free { - unsafe fn less(a: *const Free, b: *const Free) -> bool { - return (((*a).v) < ((*b).v)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Free, + |__lhs, __rhs| { + (unsafe { + let _a: *const Free = __lhs; + operator_lt_1(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_1(a: *const Free, b: *const Free) -> bool { + return (((*a).v) < ((*b).v)); +} +pub unsafe fn operator_eq_0(a: *const Free, b: *const Free) -> bool { + return (((*a).v) == ((*b).v)); +} +pub unsafe fn operator_eq_2(a: *const Wrapped_int_, b: *const Wrapped_int_) -> bool { + return (((*a).v) == ((*b).v)); +} +pub unsafe fn operator_lt_3(a: *const Wrapped_int_, b: *const Wrapped_int_) -> bool { + return (((*a).v) < ((*b).v)); } #[repr(C)] #[derive( @@ -109,6 +263,51 @@ impl LessThanComparableUnsafe for Free { pub struct Wrapped_int_ { pub v: i32, } +impl Cpp17EqualityComparableUnsafe for Wrapped_int_ { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Wrapped_int_, + |__lhs, __rhs| { + (unsafe { + let _a: *const Wrapped_int_ = __lhs; + operator_eq_2(_a, __rhs) + }) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Wrapped_int_ { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Wrapped_int_, + |__lhs, __rhs| { + !(unsafe { + let _a: *const Wrapped_int_ = __lhs; + operator_eq_2(_a, __rhs) + }) + } + ); +} +impl LessThanComparableUnsafe for Wrapped_int_ { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Wrapped_int_, + |__lhs, __rhs| { + (unsafe { + let _a: *const Wrapped_int_ = __lhs; + operator_lt_3(_a, __rhs) + }) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -124,11 +323,17 @@ unsafe fn main_0() -> i32 { let __n = lts.end().iter_distance(&__tmp_0); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_0.iter_at(__x) as *const Lt; + let __b = __tmp_0.iter_at(__y) as *const Lt; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -148,34 +353,26 @@ unsafe fn main_0() -> i32 { let mut eqs: Vec = Vec::from([Eq { v: 1 }, Eq { v: 2 }, Eq { v: 3 }]); let mut two: Eq = Eq { v: 2 }; let mut nine: Eq = Eq { v: 9 }; - assert!( - (((*{ - let mut __tmp_1 = { eqs.begin() }; - let mut __tmp_2 = { eqs.end() }; - let mut __it = (__tmp_1).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) - { - __it.iter_inc(); - } - __it - } - .iter_deref()) - .v) == (2)) - ); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(( ( ( * { let mut __tmp_1 = { eqs .begin() };let mut __tmp_2 = { eqs .end() }; let mut __it = (__tmp_1 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_2 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&two ), ) { __it.iter_inc(); } __it } .iter_deref() ) . v ) == ( 2 ) ) ); + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) + while + as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_4), + ) && !>::is_equal( + LvalueRefUnsafe::>::bind(__it.iter_deref()), + LvalueRefUnsafe::>::bind(&nine), + ) { __it.iter_inc(); } __it - }, - &eqs.end() + }), + LvalueRefUnsafe::>>::bind(&eqs.end()), )); let mut cmps: Vec = Vec::from([Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }]); { @@ -183,11 +380,17 @@ unsafe fn main_0() -> i32 { let __n = cmps.end().iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_5.iter_at(__x) as *const _; - let __b = __tmp_5.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_5.iter_at(__x) as *const Cmp; + let __b = __tmp_5.iter_at(__y) as *const Cmp; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -203,32 +406,24 @@ unsafe fn main_0() -> i32 { }; assert!(((cmps[(0_usize)].v) == (1)) && ((cmps[(2_usize)].v) == (3))); let mut three: Cmp = Cmp { v: 3 }; - assert!( - (((*{ - let mut __tmp_6 = { cmps.begin() }; - let mut __tmp_7 = { cmps.end() }; - let mut __it = (__tmp_6).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_7) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) - { - __it.iter_inc(); - } - __it - } - .iter_deref()) - .v) == (3)) - ); + assert!(( ( ( * { let mut __tmp_6 = { cmps .begin() };let mut __tmp_7 = { cmps .end() }; let mut __it = (__tmp_6 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_7 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&three ), ) { __it.iter_inc(); } __it } .iter_deref() ) . v ) == ( 3 ) ) ); let mut frees: Vec = Vec::from([Free { v: 2 }, Free { v: 1 }]); { let mut __tmp_8 = { frees.begin() }; let __n = frees.end().iter_distance(&__tmp_8); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_8.iter_at(__x) as *const _; - let __b = __tmp_8.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_8.iter_at(__x) as *const Free; + let __b = __tmp_8.iter_at(__y) as *const Free; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -244,21 +439,7 @@ unsafe fn main_0() -> i32 { }; assert!(((frees[(0_usize)].v) == (1))); let mut ftwo: Free = Free { v: 2 }; - assert!( - (((*{ - let mut __tmp_9 = { frees.begin() }; - let mut __tmp_10 = { frees.end() }; - let mut __it = (__tmp_9).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) - { - __it.iter_inc(); - } - __it - } - .iter_deref()) - .v) == (2)) - ); + assert!(( ( ( * { let mut __tmp_9 = { frees .begin() };let mut __tmp_10 = { frees .end() }; let mut __it = (__tmp_9 ).clone(); while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_10 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&ftwo ), ) { __it.iter_inc(); } __it } .iter_deref() ) . v ) == ( 2 ) ) ); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_11: Lt; @@ -286,19 +467,4 @@ 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/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 2674a4d16b..5e996e7a47 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -50,6 +50,80 @@ impl Meters { return (*this).value; } } +impl Cpp17EqualityComparableUnsafe for Meters { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + == (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Meters { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + != (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl LessThanComparableUnsafe for Meters { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + < (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Meters { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + > (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + <= (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Meters, + |__lhs, __rhs| { + ((unsafe { Meters::to_i32(&raw const (*__lhs)) }) + >= (unsafe { Meters::to_i32(&raw const (*__rhs)) })) + } + ); +} #[repr(C)] #[derive( Copy, diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index 3c4e44ba37..5e8eecc6fa 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -82,7 +82,10 @@ 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 = Vec::new(); let mut __it = head.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { + while <*mut u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_2), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -114,7 +117,10 @@ 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 = Vec::new(); let mut __it = head.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { + while <*mut u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_3), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -276,7 +282,10 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut __tmp_4 = { p.offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = p; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { + while <*mut u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_4), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -352,7 +361,10 @@ pub unsafe fn emplace_from_sibling_18(mut s: *mut Bytes) { let mut __tmp_5 = { p.offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = p; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { + while <*mut u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_5), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), diff --git a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs index 3e97994247..462b0b24c4 100644 --- a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs +++ b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs @@ -9,9 +9,11 @@ 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 WeaklyEqualityComparableWithUnsafe::equal( - &cit, - &>::from((it).clone()), + return if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&cit), + LvalueRefUnsafe::>>::bind( + &>::from((it).clone()), + ), ) { (*it.iter_deref()).1 } else { @@ -37,16 +39,21 @@ 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 WeaklyEqualityComparableWithUnsafe::equal( - &const_it, - &>::from((end).clone()), + let mut r: i32 = if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&const_it), + LvalueRefUnsafe::>>::bind( + &>::from((end).clone()), + ), ) { 0 } else { 1 }; r += (unsafe { sink_0((it0).clone()) }); - r += if WeaklyEqualityComparableWithUnsafe::equal(&end, &end) { + r += if Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&end), + LvalueRefUnsafe::>>::bind(&end), + ) { 0 } else { 1 @@ -57,9 +64,9 @@ unsafe fn main_0() -> i32 { let mut const_middle: UnsafeRandomAccessIterator = >::from((middle).clone()); assert!(((*const_middle.iter_deref()) == (8_u32))); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &const_middle, - &middle + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&const_middle), + LvalueRefUnsafe::>>::bind(&middle), )); return 0; } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index b9541e72a6..de1f9e90c1 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -36,7 +36,10 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&__tmp_0), + ) { object_unsafe!(__value, u64, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this @@ -82,9 +85,9 @@ pub unsafe fn size_t_in_rules_3() { |__k| cpp_move_unsafe!(__k), || 0_u64, )) = 4_u64; - assert!(WeaklyEqualityComparableWithUnsafe::not_equal( - &m.find(&1_u64), - &m.end() + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&m.find(&1_u64)), + LvalueRefUnsafe::>>::bind(&m.end()), )); assert!((((*m.begin().iter_deref()).0) == (1_u64))); let mut m2: UnsafeMap = std::mem::take(&mut m); @@ -204,7 +207,10 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_6 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_6) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_6), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -225,7 +231,10 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_8 = { v.begin() }; let mut __tmp_9 = { v.end() }; let mut __it = (__tmp_8).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_9), + ) { *__it.iter_deref() = Clone::clone(&(k as u64)); __it.iter_inc(); } @@ -240,7 +249,10 @@ pub unsafe fn size_t_in_rules_3() { (*{ let __a: *const _ = &mut v[(1_usize)]; let __b: *const _ = &mut __tmp_10; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -291,19 +303,15 @@ pub unsafe fn size_t_in_rules_3() { v3.push(__a2) } }; - assert!(WeaklyEqualityComparableWithUnsafe::not_equal( - &{ + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_13 = { v3.begin() }; let mut __tmp_14 = { v3.end() }; let mut __it = (__tmp_13).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(k as u64)) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_14 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&( k as u64 ) ), ) { __it.iter_inc(); } __it - }, - &v3.end() + }), + LvalueRefUnsafe::>>::bind(&v3.end()), )); assert!((((v3.len()) == (5_usize)) && ((big) >= (k))) && (((pk.1) as usize) == (k))); let mut ci: UnsafeRandomAccessIterator = @@ -364,7 +372,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_15; let __b: *const _ = &mut __tmp_16; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -376,7 +387,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_17; let __b: *const _ = &mut ul; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -391,7 +405,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_18; let __b: *const _ = &mut __tmp_19; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -450,7 +467,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_20; let __b: *const _ = &mut __tmp_21; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -463,7 +483,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_22; let __b: *const _ = &mut __tmp_23; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -493,7 +516,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_24; let __b: *const _ = &mut __tmp_25; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -506,7 +532,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut __tmp_26; let __b: *const _ = &mut __tmp_27; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/sort.rs b/tests/unit/out/unsafe/sort.rs index 43cdf5c306..3ce8b977bb 100644 --- a/tests/unit/out/unsafe/sort.rs +++ b/tests/unit/out/unsafe/sort.rs @@ -59,11 +59,17 @@ unsafe fn main_0() -> i32 { let __n = v.end().iter_distance(&__tmp_10); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_10.iter_at(__x) as *const _; - let __b = __tmp_10.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_10.iter_at(__x) as *const i32; + let __b = __tmp_10.iter_at(__y) as *const i32; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index c58ce47980..a9334dd867 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -51,6 +51,21 @@ impl MoveAssignableUnsafe for Tracked { return &mut (*this); } } +impl LessThanComparableUnsafe for Tracked { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Tracked, + |__lhs, __rhs| { + (unsafe { + let _a: *const Tracked = __lhs; + operator_lt_1(_a, __rhs) + }) + } + ); +} impl Default for Tracked { fn default() -> Self { unsafe { @@ -62,12 +77,10 @@ impl Default for Tracked { } } } -impl LessThanComparableUnsafe for Tracked { - unsafe fn less(a: *const Tracked, b: *const Tracked) -> bool { - return (((*a).v) < ((*b).v)); - } +pub unsafe fn operator_lt_1(a: *const Tracked, b: *const Tracked) -> bool { + return (((*a).v) < ((*b).v)); } -pub unsafe fn greater_1(a: *const Tracked, b: *const Tracked) -> bool { +pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool { return (((*a).v) > ((*b).v)); } #[repr(C)] @@ -92,9 +105,22 @@ impl MoveOnly { } } impl LessThanComparableUnsafe for MoveOnly { - unsafe fn less(a: *const MoveOnly, b: *const MoveOnly) -> bool { - return (((*a).v) < ((*b).v)); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + MoveOnly, + |__lhs, __rhs| { + (unsafe { + let _a: *const MoveOnly = __lhs; + operator_lt_3(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_3(a: *const MoveOnly, b: *const MoveOnly) -> bool { + return (((*a).v) < ((*b).v)); } #[repr(C)] #[derive( @@ -117,10 +143,41 @@ impl Bag { (&raw mut (*this).items).write(Vec::new()); } } +impl Cpp17EqualityComparableUnsafe for Bag { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Bag, + |__lhs, __rhs| { + (unsafe { + let _a: *const Bag = __lhs; + operator_eq_4(_a, __rhs) + }) + } + ); +} impl LessThanComparableUnsafe for Bag { - unsafe fn less(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) < ((*b).items.len())); - } + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Bag, + |__lhs, __rhs| { + (unsafe { + let _a: *const Bag = __lhs; + operator_lt_5(_a, __rhs) + }) + } + ); +} +pub unsafe fn operator_lt_5(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) < ((*b).items.len())); +} +pub unsafe fn operator_eq_4(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) == ((*b).items.len())); } pub fn main() { unsafe { @@ -164,11 +221,17 @@ unsafe fn main_0() -> i32 { .iter_distance(&__tmp_0); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_0.iter_at(__x) as *const Tracked; + let __b = __tmp_0.iter_at(__y) as *const Tracked; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -219,11 +282,17 @@ unsafe fn main_0() -> i32 { let __n = vec_.end().iter_distance(&__tmp_1); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_1.iter_at(__x) as *const _; - let __b = __tmp_1.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_1.iter_at(__x) as *const Tracked; + let __b = __tmp_1.iter_at(__y) as *const Tracked; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -250,9 +319,9 @@ unsafe fn main_0() -> i32 { __order.sort_by(|&__x, &__y| { let __a = __tmp_2.iter_at(__x) as *const _; let __b = __tmp_2.iter_at(__y) as *const _; - if (greater_1 as unsafe fn(*const Tracked, *const Tracked) -> bool).call(__a, __b) { + if (greater_2 as unsafe fn(*const Tracked, *const Tracked) -> bool).call(__a, __b) { std::cmp::Ordering::Less - } else if (greater_1 as unsafe fn(*const Tracked, *const Tracked) -> bool) + } else if (greater_2 as unsafe fn(*const Tracked, *const Tracked) -> bool) .call(__b, __a) { std::cmp::Ordering::Greater @@ -318,9 +387,9 @@ unsafe fn main_0() -> i32 { __order.sort_by(|&__x, &__y| { let __a = __tmp_4.iter_at(__x) as *const _; let __b = __tmp_4.iter_at(__y) as *const _; - if (greater_1 as unsafe fn(*const Tracked, *const Tracked) -> bool).call(__a, __b) { + if (greater_2 as unsafe fn(*const Tracked, *const Tracked) -> bool).call(__a, __b) { std::cmp::Ordering::Less - } else if (greater_1 as unsafe fn(*const Tracked, *const Tracked) -> bool) + } else if (greater_2 as unsafe fn(*const Tracked, *const Tracked) -> bool) .call(__b, __a) { std::cmp::Ordering::Greater @@ -369,11 +438,17 @@ unsafe fn main_0() -> i32 { .iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_5.iter_at(__x) as *const _; - let __b = __tmp_5.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_5.iter_at(__x) as *const Bag; + let __b = __tmp_5.iter_at(__y) as *const Bag; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -413,11 +488,17 @@ unsafe fn main_0() -> i32 { let __n = bag_vec.end().iter_distance(&__tmp_6); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_6.iter_at(__x) as *const _; - let __b = __tmp_6.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_6.iter_at(__x) as *const Bag; + let __b = __tmp_6.iter_at(__y) as *const Bag; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -436,50 +517,45 @@ 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!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) - && !WeaklyEqualityComparableWithUnsafe::equal( - &*__it.iter_deref(), - &bags[(1) as usize], - ) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_8 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&bags [ ( 1 ) as usize ] ), ) { __it.iter_inc(); } __it - }, - &bag_vec.begin().iter_add(1_isize) + }), + LvalueRefUnsafe::>>::bind( + &bag_vec.begin().iter_add(1_isize) + ), )); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &{ + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind(&{ let mut __tmp_9 = { bag_vec.begin() }; let mut __tmp_10 = { bag_vec.end() }; let mut __best = __tmp_9.clone(); - if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_9, &__tmp_10) { + if as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__tmp_9), + LvalueRefUnsafe::>>::bind(&__tmp_10), + ) { let mut __it = (__tmp_9).clone(); __it.iter_inc(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { - if LessThanComparableUnsafe::less( - __best.iter_deref() as *const _, - __it.iter_deref() as *const _, - ) { - __best = __it.clone(); - } - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_10 ), ) { if ::is_less( LvalueRefUnsafe::>::bind(__best.iter_deref()), LvalueRefUnsafe::>::bind(__it.iter_deref()), ) { __best = __it.clone(); } __it.iter_inc(); } } __best - }, - &bag_vec.begin().iter_add(2_isize) + }), + LvalueRefUnsafe::>>::bind( + &bag_vec.begin().iter_add(2_isize) + ), )); assert!( (({ let __a: *const _ = &mut bags[(0) as usize]; let __b: *const _ = &mut bags[(2) as usize]; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a @@ -490,7 +566,10 @@ unsafe fn main_0() -> i32 { (({ let __a: *const _ = &mut bags[(0) as usize]; let __b: *const _ = &mut bags[(2) as usize]; - if LessThanComparableUnsafe::less(__a, __b) { + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { __b } else { __a @@ -510,9 +589,11 @@ unsafe fn main_0() -> i32 { || 0_i32, )) = 0; assert!((((*bag_map.find(&bags[(2) as usize]).iter_deref()).1) == (2))); - assert!(WeaklyEqualityComparableWithUnsafe::equal( - &bag_map.find(&bags[(1) as usize]), - &bag_map.end() + assert!(Cpp17EqualityComparableUnsafe::is_equal( + LvalueRefUnsafe::>>::bind( + &bag_map.find(&bags[(1) as usize]) + ), + LvalueRefUnsafe::>>::bind(&bag_map.end()), )); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut moves: Vec = Vec::new(); @@ -536,11 +617,17 @@ unsafe fn main_0() -> i32 { let __n = moves.end().iter_distance(&__tmp_11); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_11.iter_at(__x) as *const _; - let __b = __tmp_11.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_11.iter_at(__x) as *const MoveOnly; + let __b = __tmp_11.iter_at(__y) as *const MoveOnly; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -603,11 +690,6 @@ 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 7ca1020bed..1d4887e4dc 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -41,7 +41,10 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&__tmp_0), + ) { object_unsafe!(__value, i32, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this @@ -60,7 +63,10 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_1) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&__tmp_1), + ) { object_unsafe!(__value, i64, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this @@ -89,7 +95,10 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_4) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&__tmp_4), + ) { object_unsafe!(__value, Degrees, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this @@ -110,7 +119,10 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_5) { + while <*mut i64 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__first), + LvalueRefUnsafe::>::bind(&__tmp_5), + ) { object_unsafe!(__value, f64, |__this| ConvertibleToUnsafe::convert( LvalueRefUnsafe::::bind(__first.iter_deref()), __this diff --git a/tests/unit/out/unsafe/stdcopy_ostream.rs b/tests/unit/out/unsafe/stdcopy_ostream.rs index de2abdc633..1c1e155d91 100644 --- a/tests/unit/out/unsafe/stdcopy_ostream.rs +++ b/tests/unit/out/unsafe/stdcopy_ostream.rs @@ -37,10 +37,7 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_0).clone(); let __out = &mut ofs; let mut __bytes: Vec = Vec::new(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __bytes.push(*__it.iter_deref() as u8); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_1 ), ) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } __out.write_all(&__bytes); __out.try_clone().unwrap() }; diff --git a/tests/unit/out/unsafe/stdmin_fpoint.rs b/tests/unit/out/unsafe/stdmin_fpoint.rs index d4071745ca..1be411d216 100644 --- a/tests/unit/out/unsafe/stdmin_fpoint.rs +++ b/tests/unit/out/unsafe/stdmin_fpoint.rs @@ -18,7 +18,10 @@ unsafe fn main_0() -> i32 { { let __a: *const _ = &mut a0; let __b: *const _ = &mut a1; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index 48dfc6485f..4713d31ee4 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -55,19 +55,12 @@ 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 WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) - && !WeaklyEqualityComparableWithUnsafe::equal( - &*__it.iter_deref(), - &(*sigma.offset((i) as isize)), - ) - { - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_1 ), ) && !>::is_equal( LvalueRefUnsafe::>::bind(__it.iter_deref()), LvalueRefUnsafe::>::bind(&( * sigma . offset ( ( i ) as isize ) ) ), ) { __it.iter_inc(); } __it }; - assert!(WeaklyEqualityComparableWithUnsafe::not_equal( - &it, - &items.end() + assert!(WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&items.end()), )); (*code.offset((i) as isize)) = ((it.iter_distance(&items.begin())) as u32); { @@ -87,7 +80,10 @@ pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut s: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { + 'loop_: while WeaklyEqualityComparableWithUnsafe::is_not_equal( + LvalueRefUnsafe::>>::bind(&it), + LvalueRefUnsafe::>>::bind(&(*v).end()), + ) { 'for_body: { s += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index 748a99e85b..4ea2334302 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -170,7 +170,10 @@ unsafe fn main_0() -> i32 { (*{ let __a: *const _ = &mut high; let __b: *const _ = &mut __tmp_0; - if LessThanComparableUnsafe::less(__b, __a) { + if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { __b } else { __a diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 44560dac26..8642aa9237 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -191,7 +191,10 @@ unsafe fn main_0() -> i32 { __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_8).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>>::bind(&__it), + LvalueRefUnsafe::>>::bind(&__tmp_9), + ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), @@ -519,7 +522,10 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_20), + ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), @@ -544,14 +550,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_22).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::>::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_23 ), ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } longs.splice(__off..__off, __tmp); UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr().add(__off)) }; @@ -565,7 +564,10 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_25), + ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), @@ -586,7 +588,10 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_27), + ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), @@ -607,14 +612,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_29).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::>::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_30 ), ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } same.splice(__off..__off, __tmp); UnsafeRandomAccessIterator::Vec(same.as_mut_ptr().add(__off)) }; diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 202b307dc7..25a02a8550 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -50,6 +50,80 @@ impl Reading { return (((*this).raw_ as i64) * (10_i64)); } } +impl Cpp17EqualityComparableUnsafe for Reading { + comparison_unsafe!( + Cpp17EqualityComparableUnsafe, + equal, + is_equal, + EqualResult = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + == (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); +} +impl WeaklyEqualityComparableWithUnsafe for Reading { + comparison_unsafe!( + WeaklyEqualityComparableWithUnsafe, + not_equal, + is_not_equal, + NotEqualResult = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + != (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); +} +impl LessThanComparableUnsafe for Reading { + comparison_unsafe!( + LessThanComparableUnsafe, + less, + is_less, + Result = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + < (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); +} +impl PartiallyOrderedWithUnsafe for Reading { + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater, + is_greater, + GreaterResult = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + > (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + less_equal, + is_less_equal, + LessEqualResult = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + <= (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); + comparison_unsafe!( + PartiallyOrderedWithUnsafe, + greater_equal, + is_greater_equal, + GreaterEqualResult = bool, + Reading, + |__lhs, __rhs| { + ((unsafe { Reading::to_i64(&raw const (*__lhs)) }) + >= (unsafe { Reading::to_i64(&raw const (*__rhs)) })) + } + ); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -62,7 +136,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_0), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -81,7 +158,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_1), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -100,7 +180,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_2), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -117,7 +200,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; let mut __v: Vec = Vec::new(); let mut __it = src1.as_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { + while <*const u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_3), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -145,7 +231,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { start.offset((len) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = start; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { + while <*const u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_5), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -184,16 +273,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_10 = { m.end() }; let mut __v: Vec<(i32, i32)> = Vec::new(); let mut __it = (__tmp_9).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { - __v.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __v.as_mut_ptr().add(__v.len() - 1), - (LvalueRefUnsafe::>::bind( - __it.iter_deref(), - ),), - ); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_10 ), ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } __v }; assert!(((v6.len()) == (3_usize))); @@ -208,16 +288,7 @@ unsafe fn main_0() -> i32 { __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; let mut __tmp: Vec<(i32, i32)> = Vec::new(); let mut __it = (__tmp_12).clone(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::>::bind( - __it.iter_deref(), - ),), - ); - __it.iter_inc(); - } + while as WeaklyEqualityComparableWithUnsafe>::is_not_equal( LvalueRefUnsafe:: >>::bind(&__it), LvalueRefUnsafe:: >>::bind(&__tmp_13 ), ) { __tmp.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } v6.splice(__off..__off, __tmp); UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr().add(__off)) }; @@ -230,7 +301,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { + while <*mut i32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_14), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -246,7 +320,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = readings.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { + while <*mut Reading as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_15), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 1ba3b4e042..af35e8f0bc 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -321,7 +321,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_16), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -340,7 +343,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_17), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -359,7 +365,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { + while <*mut u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_18), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -376,7 +385,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; let mut __v: Vec = Vec::new(); let mut __it = src1.as_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { + while <*const u32 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_19), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), @@ -398,7 +410,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { start.offset((len) as isize) }; let mut __v: Vec = Vec::new(); let mut __it = start; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { + while <*const u8 as WeaklyEqualityComparableWithUnsafe>::is_not_equal( + LvalueRefUnsafe::>::bind(&__it), + LvalueRefUnsafe::>::bind(&__tmp_20), + ) { __v.push(ZeroInitializationUnsafe::zero_init()); ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), diff --git a/tests/unit/out/unsafe/void_return.rs b/tests/unit/out/unsafe/void_return.rs index 2a9f3c23a6..def230c35e 100644 --- a/tests/unit/out/unsafe/void_return.rs +++ b/tests/unit/out/unsafe/void_return.rs @@ -15,11 +15,17 @@ pub unsafe fn f1_0( let __n = (last).clone().iter_distance(&__tmp_0); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_0.iter_at(__x) as *const _; - let __b = __tmp_0.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = __tmp_0.iter_at(__x) as *const i32; + let __b = __tmp_0.iter_at(__y) as *const i32; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,11 +46,17 @@ pub unsafe fn f1_1(mut first: *mut i32, mut last: *mut i32) { let __n = last.iter_distance(&first); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = first.iter_at(__x) as *const _; - let __b = first.iter_at(__y) as *const _; - if LessThanComparableUnsafe::less(__a, __b) { + let __a = first.iter_at(__x) as *const i32; + let __b = first.iter_at(__y) as *const i32; + if ::is_less( + LvalueRefUnsafe::>::bind(__a), + LvalueRefUnsafe::>::bind(__b), + ) { std::cmp::Ordering::Less - } else if LessThanComparableUnsafe::less(__b, __a) { + } else if ::is_less( + LvalueRefUnsafe::>::bind(__b), + LvalueRefUnsafe::>::bind(__a), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal