Skip to content

Commit 5f28bd8

Browse files
committed
IsSameRustType -> IsCastRedundantInRust
1 parent 3a87600 commit 5f28bd8

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,17 +1769,12 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) {
17691769
}
17701770
}
17711771

1772-
bool Converter::IsSameRustType(clang::Expr *a, clang::Expr *b) {
1773-
auto get_converted_type_or_mapped_type = [&](clang::Expr *expr) {
1774-
if (!clang::isa<clang::ImplicitCastExpr>(expr)) {
1775-
if (const auto *rule = Mapper::GetExprRule(expr)) {
1776-
return rule->return_type.type;
1777-
}
1778-
}
1779-
return GetUnsafeTypeAsString(expr->getType());
1780-
};
1781-
return get_converted_type_or_mapped_type(a) ==
1782-
get_converted_type_or_mapped_type(b);
1772+
bool Converter::IsCastRedundantInRust(clang::Expr *expr, clang::QualType target_type) {
1773+
auto target = GetUnsafeTypeAsString(target_type);
1774+
if (const auto *rule = Mapper::GetExprRule(expr)) {
1775+
return rule->return_type.type == target;
1776+
}
1777+
return GetUnsafeTypeAsString(expr->getType()) == target;
17831778
}
17841779

17851780
bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
@@ -1879,7 +1874,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18791874
break;
18801875
}
18811876
// Skip cast if source and target map to the same Rust type.
1882-
if (IsSameRustType(sub_expr, expr)) {
1877+
if (IsCastRedundantInRust(sub_expr, type)) {
18831878
Convert(sub_expr);
18841879
break;
18851880
}

cpp2rust/converter/converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
686686

687687
TempMaterializationCtx CollectPrvalueToLRefArgs(clang::CallExpr *expr);
688688

689-
bool IsSameRustType(clang::Expr *a, clang::Expr *b);
689+
bool IsCastRedundantInRust(clang::Expr *expr, clang::QualType target_type);
690690

691691
private:
692692
void materializeTemplateSpecialization(clang::CXXRecordDecl *decl);

0 commit comments

Comments
 (0)