@@ -1779,6 +1779,19 @@ 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);
1793+ }
1794+
17821795bool Converter::VisitImplicitCastExpr (clang::ImplicitCastExpr *expr) {
17831796 auto *sub_expr = expr->getSubExpr ();
17841797 auto type = expr->getType ();
@@ -1878,8 +1891,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18781891 break ;
18791892 }
18801893 // Skip cast if source and target map to the same Rust type.
1881- if (GetUnsafeTypeAsString (sub_expr->getType ()) ==
1882- GetUnsafeTypeAsString (type)) {
1894+ if (IsSameRustType (sub_expr, expr)) {
18831895 Convert (sub_expr);
18841896 break ;
18851897 }
@@ -3134,7 +3146,7 @@ std::string Converter::GetUnsafeTypeAsString(clang::QualType qual_type) const {
31343146 std::string type_as_string;
31353147 Converter converter (type_as_string, ctx_);
31363148 converter.Convert (qual_type);
3137- return type_as_string;
3149+ return std::string ( Trim ( type_as_string)) ;
31383150}
31393151
31403152void Converter::ConvertVarInit (clang::QualType qual_type, clang::Expr *expr) {
@@ -3572,7 +3584,8 @@ void Converter::ConvertDeref(clang::Expr *expr) {
35723584
35733585void Converter::ConvertArrow (clang::Expr *expr) { ConvertDeref (expr); }
35743586
3575- void Converter::ConvertCast (clang::QualType qual_type) {
3587+ void Converter::ConvertCast (clang::QualType qual_type, int line) {
3588+ log () << " [ConvertCast] Called from line " << line << " \n " ;
35763589 StrCat (keyword::kAs , GetUnsafeTypeAsString (qual_type));
35773590}
35783591
0 commit comments