File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1769,6 +1769,19 @@ 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 (!llvm::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);
1783+ }
1784+
17721785bool Converter::VisitImplicitCastExpr (clang::ImplicitCastExpr *expr) {
17731786 auto *sub_expr = expr->getSubExpr ();
17741787 auto type = expr->getType ();
@@ -1866,8 +1879,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18661879 break ;
18671880 }
18681881 // Skip cast if source and target map to the same Rust type.
1869- if (GetUnsafeTypeAsString (sub_expr->getType ()) ==
1870- GetUnsafeTypeAsString (type)) {
1882+ if (IsSameRustType (sub_expr, expr)) {
18711883 Convert (sub_expr);
18721884 break ;
18731885 }
Original file line number Diff line number Diff line change @@ -685,6 +685,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
685685
686686 TempMaterializationCtx CollectPrvalueToLRefArgs (clang::CallExpr *expr);
687687
688+ bool IsSameRustType (clang::Expr *a, clang::Expr *b);
689+
688690private:
689691 void materializeTemplateSpecialization (clang::CXXRecordDecl *decl);
690692
You can’t perform that action at this time.
0 commit comments