]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
gccrs: Make coercion sites autoderef cycle optional
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 27 Feb 2023 14:16:29 +0000 (14:16 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 28 Feb 2023 20:38:35 +0000 (20:38 +0000)
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::check): update to new interface
* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): likewise
(TypeCoercionRules::TryCoerce): likewise
(TypeCoercionRules::TypeCoercionRules): likewise
* typecheck/rust-coercion.h: likewise
* typecheck/rust-type-util.cc (coercion_site): likewise

gcc/rust/typecheck/rust-casts.cc
gcc/rust/typecheck/rust-coercion.cc
gcc/rust/typecheck/rust-coercion.h
gcc/rust/typecheck/rust-type-util.cc

index 987542e59c47b10624ca3ae41c4fad6df2e92404..0ecb50f7d1d7a607a70a14b9808dc29358680a07 100644 (file)
@@ -39,7 +39,8 @@ TypeCastRules::check ()
 {
   // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/cast.rs#L565-L582
   auto possible_coercion
-    = TypeCoercionRules::TryCoerce (from.get_ty (), to.get_ty (), locus);
+    = TypeCoercionRules::TryCoerce (from.get_ty (), to.get_ty (), locus,
+                                   true /*allow-autoderef*/);
   if (!possible_coercion.is_error ())
     return possible_coercion;
 
index fdc8bdd7acb2214db2579906ce0352fb63e97de4..7a3f51aa419e3d49f2dc1067f513408ec099ddae 100644 (file)
@@ -25,25 +25,26 @@ namespace Resolver {
 
 TypeCoercionRules::CoercionResult
 TypeCoercionRules::Coerce (TyTy::BaseType *receiver, TyTy::BaseType *expected,
-                          Location locus)
+                          Location locus, bool allow_autoderef)
 {
-  TypeCoercionRules resolver (expected, locus, true);
+  TypeCoercionRules resolver (expected, locus, true, allow_autoderef);
   bool ok = resolver.do_coercion (receiver);
   return ok ? resolver.try_result : CoercionResult::get_error ();
 }
 
 TypeCoercionRules::CoercionResult
 TypeCoercionRules::TryCoerce (TyTy::BaseType *receiver,
-                             TyTy::BaseType *expected, Location locus)
+                             TyTy::BaseType *expected, Location locus,
+                             bool allow_autoderef)
 {
-  TypeCoercionRules resolver (expected, locus, false);
+  TypeCoercionRules resolver (expected, locus, false, allow_autoderef);
   bool ok = resolver.do_coercion (receiver);
   return ok ? resolver.try_result : CoercionResult::get_error ();
 }
 
 TypeCoercionRules::TypeCoercionRules (TyTy::BaseType *expected, Location locus,
-                                     bool emit_errors)
-  : AutoderefCycle (false), mappings (Analysis::Mappings::get ()),
+                                     bool emit_errors, bool allow_autoderef)
+  : AutoderefCycle (!allow_autoderef), mappings (Analysis::Mappings::get ()),
     context (TypeCheckContext::get ()), expected (expected), locus (locus),
     try_result (CoercionResult::get_error ()), emit_errors (emit_errors)
 {}
index d0fc0f97079e4e57a86a64454b721bf0f1d63271..69442e5a260d09a1b12e207aa6b7d8fd5c40eef1 100644 (file)
@@ -42,10 +42,12 @@ public:
   };
 
   static CoercionResult Coerce (TyTy::BaseType *receiver,
-                               TyTy::BaseType *expected, Location locus);
+                               TyTy::BaseType *expected, Location locus,
+                               bool allow_autoderef);
 
   static CoercionResult TryCoerce (TyTy::BaseType *receiver,
-                                  TyTy::BaseType *expected, Location locus);
+                                  TyTy::BaseType *expected, Location locus,
+                                  bool allow_autoderef);
 
   CoercionResult coerce_unsafe_ptr (TyTy::BaseType *receiver,
                                    TyTy::PointerType *expected,
@@ -66,8 +68,8 @@ public:
   void object_unsafe_error (Location expr_locus, Location lhs, Location rhs);
 
 protected:
-  TypeCoercionRules (TyTy::BaseType *expected, Location locus,
-                    bool emit_errors);
+  TypeCoercionRules (TyTy::BaseType *expected, Location locus, bool emit_errors,
+                    bool allow_autoderef);
 
   bool select (const TyTy::BaseType &autoderefed) override;
 
index ff7c805c9436c4200115f6123fbe88ecacd2e04a..da9a724aca814beabe7e58f7439f063d15340c88 100644 (file)
@@ -186,7 +186,8 @@ coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
     return expr;
 
   // can we autoderef it?
-  auto result = TypeCoercionRules::Coerce (expr, expected, locus);
+  auto result = TypeCoercionRules::Coerce (expr, expected, locus,
+                                          true /*allow-autodref*/);
 
   // the result needs to be unified
   TyTy::BaseType *receiver = expr;