Skip to content

Commit 770f07e

Browse files
committed
Remove PushSuppressIteratorClone
1 parent 0d55e4c commit 770f07e

5 files changed

Lines changed: 4 additions & 47 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,8 +3912,6 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) {
39123912
}
39133913

39143914
bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
3915-
PushSuppressIteratorClone push(*this, expr);
3916-
39173915
if (expr->isElidable()) {
39183916
Convert(expr->getArg(0));
39193917
return false;
@@ -3936,11 +3934,9 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
39363934
return false;
39373935
}
39383936
if (IsPassThroughConstructor(ctor)) {
3939-
// Take suppress before recursing into the child.
3940-
bool suppress = PushSuppressIteratorClone::take(*this);
39413937
Convert(expr->getArg(0));
39423938
if ((ctor->isCopyConstructor() || IsDefaultedMoveConstructor(ctor)) &&
3943-
!suppress && !TypeIsCopyable(expr->getType())) {
3939+
!TypeIsCopyable(expr->getType())) {
39443940
StrCat(".clone()");
39453941
SetFreshType(expr->getType());
39463942
}

‎cpp2rust/converter/converter.h‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,6 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
841841
std::string ufcs_receiver_;
842842
bool in_const_initializer_ = false;
843843
std::optional<bool> autoref_mut_;
844-
bool suppress_iterator_clone_ = false;
845844

846845
struct PushExplicitAutoref {
847846
Converter &c;
@@ -853,41 +852,6 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
853852
~PushExplicitAutoref() { c.autoref_mut_ = prev; }
854853
};
855854

856-
struct PushSuppressIteratorClone {
857-
Converter &c;
858-
bool prev;
859-
PushSuppressIteratorClone(Converter &c, clang::CXXConstructExpr *expr)
860-
: c(c), prev(c.suppress_iterator_clone_) {
861-
auto *ctor = expr->getConstructor();
862-
if (!ctor->isCopyOrMoveConstructor() &&
863-
ctor->isConvertingConstructor(/*AllowExplicit=*/false) &&
864-
ctor->getNumParams() == 1 && IsIteratorType(expr->getType())) {
865-
c.suppress_iterator_clone_ = true;
866-
}
867-
}
868-
~PushSuppressIteratorClone() { c.suppress_iterator_clone_ = prev; }
869-
PushSuppressIteratorClone(const PushSuppressIteratorClone &) = delete;
870-
PushSuppressIteratorClone &
871-
operator=(const PushSuppressIteratorClone &) = delete;
872-
873-
static bool take(Converter &c) {
874-
return std::exchange(c.suppress_iterator_clone_, false);
875-
}
876-
877-
private:
878-
static bool IsIteratorType(clang::QualType qt) {
879-
if (auto *record = qt->getAsCXXRecordDecl()) {
880-
for (auto *d : record->decls()) {
881-
if (auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(d)) {
882-
if (tnd->getName() == "iterator_category")
883-
return true;
884-
}
885-
}
886-
}
887-
return false;
888-
}
889-
};
890-
891855
struct PushConstInitializer {
892856
Converter &c;
893857
bool prev;

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,6 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
23752375
getConversionKind() != ConversionKind::Unboxed;
23762376
PushConversionKind push(*this, boxed_array ? ConversionKind::Pointee
23772377
: ConversionKind::Unboxed);
2378-
PushSuppressIteratorClone push_suppress(*this, expr);
23792378

23802379
if (auto str = GetMappedAsString(expr, expr->getArgs(), expr->getNumArgs());
23812380
!str.empty()) {
@@ -2408,9 +2407,7 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
24082407

24092408
if (ctor->isCopyOrMoveConstructor() &&
24102409
!IsConvertibleCopyOrMoveConstructor(ctor)) {
2411-
StrCat(PushSuppressIteratorClone::take(*this)
2412-
? ConvertRValue(expr->getArg(0))
2413-
: ConvertFreshRValue(expr->getArg(0)));
2410+
StrCat(ConvertFreshRValue(expr->getArg(0)));
24142411
return false;
24152412
}
24162413

‎rules/iterator_category/tgt_refcount.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn t5<T1>() -> RandomAccessIterator<T1> {
2424
}
2525

2626
fn f1<T1: CppIterator<T2>, T2>(a0: T1) -> T1 {
27-
a0.clone()
27+
(a0).clone()
2828
}
2929

3030
fn f2<T1: CppIterator<T2>, T2>(a0: T1) -> T1 {

‎rules/iterator_category/tgt_unsafe.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn t5<T1>() -> UnsafeRandomAccessIterator<T1> {
2424
}
2525

2626
unsafe fn f1<T1: UnsafeCppIterator<T2>, T2>(a0: T1) -> T1 {
27-
a0.clone()
27+
(a0).clone()
2828
}
2929

3030
unsafe fn f2<T1: UnsafeCppIterator<T2>, T2>(a0: T1) -> T1 {

0 commit comments

Comments
 (0)