@@ -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 (!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);
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 }
@@ -3109,7 +3121,7 @@ std::string Converter::GetUnsafeTypeAsString(clang::QualType qual_type) const {
31093121 std::string type_as_string;
31103122 Converter converter (type_as_string, ctx_);
31113123 converter.Convert (qual_type);
3112- return type_as_string;
3124+ return std::string ( Trim ( type_as_string)) ;
31133125}
31143126
31153127void Converter::ConvertVarInit (clang::QualType qual_type, clang::Expr *expr) {
@@ -3545,7 +3557,8 @@ void Converter::ConvertDeref(clang::Expr *expr) {
35453557
35463558void Converter::ConvertArrow (clang::Expr *expr) { ConvertDeref (expr); }
35473559
3548- void Converter::ConvertCast (clang::QualType qual_type) {
3560+ void Converter::ConvertCast (clang::QualType qual_type, int line) {
3561+ log () << " [ConvertCast] Called from line " << line << " \n " ;
35493562 StrCat (keyword::kAs , GetUnsafeTypeAsString (qual_type));
35503563}
35513564
0 commit comments