Skip to content

Commit df3a3eb

Browse files
committed
IsSameRustType -> IsCastRedundantInRust
1 parent ee27cb0 commit df3a3eb

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
@@ -1779,17 +1779,12 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) {
17791779
}
17801780
}
17811781

1782-
bool Converter::IsSameRustType(clang::Expr *a, clang::Expr *b) {
1783-
auto get_converted_type_or_mapped_type = [&](clang::Expr *expr) {
1784-
if (!clang::isa<clang::ImplicitCastExpr>(expr)) {
1785-
if (const auto *rule = Mapper::GetExprRule(expr)) {
1786-
return rule->return_type.type;
1787-
}
1788-
}
1789-
return GetUnsafeTypeAsString(expr->getType());
1790-
};
1791-
return get_converted_type_or_mapped_type(a) ==
1792-
get_converted_type_or_mapped_type(b);
1782+
bool Converter::IsCastRedundantInRust(clang::Expr *expr, clang::QualType target_type) {
1783+
auto target = GetUnsafeTypeAsString(target_type);
1784+
if (const auto *rule = Mapper::GetExprRule(expr)) {
1785+
return rule->return_type.type == target;
1786+
}
1787+
return GetUnsafeTypeAsString(expr->getType()) == target;
17931788
}
17941789

17951790
bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
@@ -1891,7 +1886,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18911886
break;
18921887
}
18931888
// Skip cast if source and target map to the same Rust type.
1894-
if (IsSameRustType(sub_expr, expr)) {
1889+
if (IsCastRedundantInRust(sub_expr, type)) {
18951890
Convert(sub_expr);
18961891
break;
18971892
}

cpp2rust/converter/converter.h

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

707707
TempMaterializationCtx CollectPrvalueToLRefArgs(clang::CallExpr *expr);
708708

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

711711
private:
712712
void materializeTemplateSpecialization(clang::CXXRecordDecl *decl);

0 commit comments

Comments
 (0)