Skip to content

Commit 060c6ab

Browse files
authored
fix ord comparator second branch self argument
1 parent ccd64a6 commit 060c6ab

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,7 +3678,7 @@ void Converter::ConvertOrdAndPartialOrdTraits(const clang::CXXRecordDecl *decl,
36783678
case clang::OO_Less:
36793679
if (clang::isa<clang::CXXMethodDecl>(op)) {
36803680
first_branch = std::format("self.{}(other)", GetOverloadedOperator(op));
3681-
second_branch = std::format("other.{}(other)", GetOverloadedOperator(op));
3681+
second_branch = std::format("other.{}(self)", GetOverloadedOperator(op));
36823682
} else {
36833683
first_branch = std::format("{}(self, other)", GetOverloadedOperator(op));
36843684
second_branch = std::format("{}(other, self)", GetOverloadedOperator(op));

tests/unit/out/unsafe/operator_less_than.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Ord for Pair {
2323
unsafe {
2424
if self.lt(other) {
2525
std::cmp::Ordering::Less
26-
} else if other.lt(other) {
26+
} else if other.lt(self) {
2727
std::cmp::Ordering::Greater
2828
} else {
2929
std::cmp::Ordering::Equal
@@ -38,7 +38,7 @@ impl PartialOrd for Pair {
3838
}
3939
impl PartialEq for Pair {
4040
fn eq(&self, other: &Self) -> bool {
41-
unsafe { !(self.lt(other)) && !(other.lt(other)) }
41+
unsafe { !(self.lt(other)) && !(other.lt(self)) }
4242
}
4343
}
4444
impl Eq for Pair {}

0 commit comments

Comments
 (0)