Skip to content

Commit 7fc1aa9

Browse files
committed
Drop the IsIteratorType check
1 parent 4b82edd commit 7fc1aa9

3 files changed

Lines changed: 8 additions & 22 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
27702770
(ctor->isConvertingConstructor(false) && ctor->getNumParams() == 1 &&
27712771
ctor->getParamDecl(0)->getType()->isRValueReferenceType())) {
27722772
// Take supress before recursing into the child.
2773-
bool suppress = PushSuppressIteratorClone::take(*this, expr);
2773+
bool suppress = PushSuppressIteratorClone::take(*this);
27742774
Convert(expr->getArg(0));
27752775
if (ctor->isCopyConstructor() && !suppress) {
27762776
StrCat(".clone()");

cpp2rust/converter/converter.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <string>
1414
#include <unordered_map>
1515
#include <unordered_set>
16+
#include <utility>
1617
#include <vector>
1718

1819
#include "converter/lex.h"
@@ -547,8 +548,9 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
547548
PushSuppressIteratorClone(Converter &c, clang::CXXConstructExpr *expr)
548549
: c(c), prev(c.suppress_iterator_clone_) {
549550
auto *ctor = expr->getConstructor();
550-
if (ctor->isConvertingConstructor(/*AllowExplicit=*/false) &&
551-
ctor->getNumParams() == 1 && IsIteratorType(expr->getType())) {
551+
if (!ctor->isCopyOrMoveConstructor() &&
552+
ctor->isConvertingConstructor(/*AllowExplicit=*/false) &&
553+
ctor->getNumParams() == 1) {
552554
c.suppress_iterator_clone_ = true;
553555
}
554556
}
@@ -557,24 +559,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
557559
PushSuppressIteratorClone &
558560
operator=(const PushSuppressIteratorClone &) = delete;
559561

560-
static bool take(Converter &c, clang::CXXConstructExpr *inner) {
561-
bool suppress =
562-
c.suppress_iterator_clone_ && IsIteratorType(inner->getType());
563-
c.suppress_iterator_clone_ = false;
564-
return suppress;
565-
}
566-
567-
private:
568-
static bool IsIteratorType(clang::QualType qt) {
569-
if (auto *record = qt->getAsCXXRecordDecl()) {
570-
for (auto *d : record->decls()) {
571-
if (auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(d)) {
572-
if (tnd->getName() == "iterator_category")
573-
return true;
574-
}
575-
}
576-
}
577-
return false;
562+
static bool take(Converter &c) {
563+
return std::exchange(c.suppress_iterator_clone_, false);
578564
}
579565
};
580566

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
15651565
}
15661566

15671567
if (ctor->isCopyConstructor()) {
1568-
StrCat(PushSuppressIteratorClone::take(*this, expr)
1568+
StrCat(PushSuppressIteratorClone::take(*this)
15691569
? ConvertRValue(expr->getArg(0))
15701570
: ConvertFreshRValue(expr->getArg(0)));
15711571
return false;

0 commit comments

Comments
 (0)