]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: respect the unify rules commit flag
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 25 Aug 2025 12:30:22 +0000 (13:30 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:55 +0000 (20:58 +0100)
We use the types compatable interface for unify here and so if
we dont respect the commit flag the interface can have unintended
side effects with infer type hints throwing things off down the line.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): dont commit
(UnifyRules::expect_adt): likewise
(UnifyRules::expect_bool): likewise
(UnifyRules::expect_char): likewise
(UnifyRules::expect_int): likewise
(UnifyRules::expect_uint): likewise
(UnifyRules::expect_float): likewise
(UnifyRules::expect_isize): likewise
(UnifyRules::expect_usize): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-unify.cc

index 852451aeef4c1a3d527a90eaf3af44324bc873ac..5c1e5b732cdd16ba4ba18a2c94d93986880fa910 100644 (file)
@@ -385,7 +385,8 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype,
                            == TyTy::InferType::InferTypeKind::INTEGRAL);
        if (is_valid)
          {
-           ltype->apply_primitive_type_hint (*rtype);
+           if (commit_flag)
+             ltype->apply_primitive_type_hint (*rtype);
            return rtype;
          }
       }
@@ -399,7 +400,8 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype,
                            == TyTy::InferType::InferTypeKind::FLOAT);
        if (is_valid)
          {
-           ltype->apply_primitive_type_hint (*rtype);
+           if (commit_flag)
+             ltype->apply_primitive_type_hint (*rtype);
            return rtype;
          }
       }
@@ -523,7 +525,7 @@ UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype)
              }
          }
 
-       return type.clone ();
+       return ltype;
       }
       break;
 
@@ -1269,7 +1271,8 @@ UnifyRules::expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype)
          = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1319,7 +1322,8 @@ UnifyRules::expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype)
          = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1370,7 +1374,8 @@ UnifyRules::expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype)
            || r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1428,7 +1433,8 @@ UnifyRules::expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype)
            || r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1486,7 +1492,8 @@ UnifyRules::expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype)
            || r->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1543,7 +1550,8 @@ UnifyRules::expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype)
          = r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }
@@ -1593,7 +1601,8 @@ UnifyRules::expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype)
          = r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT;
        if (is_valid)
          {
-           r->apply_primitive_type_hint (*ltype);
+           if (commit_flag)
+             r->apply_primitive_type_hint (*ltype);
            return ltype->clone ();
          }
       }