public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Assigning members to structures is a coercion site
@ 2022-06-08 12:45 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d1a2508778aafeaf19ae7e6c3e50cf9aed384854

commit d1a2508778aafeaf19ae7e6c3e50cf9aed384854
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Tue May 10 01:45:04 2022 +0100

    Assigning members to structures is a coercion site
    
    Fix missing coercion site call which allows the coecion of a reference to
    a pointer type.
    
    Fixes #1235

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-struct.cc |  8 ++++----
 gcc/testsuite/rust/compile/issue-1235.rs         | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
index dbd1c2612f9..a1cd35977ab 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
@@ -44,7 +44,7 @@ TypeCheckStructExpr::visit (HIR::StructExprStructFields &struct_expr)
 	= TypeCheckExpr::Resolve (struct_expr.struct_base->base_struct.get (),
 				  false);
       struct_def
-	= (TyTy::ADTType *) struct_path_resolved->unify (base_resolved);
+	= (TyTy::ADTType *) struct_path_resolved->coerce (base_resolved);
       if (struct_def == nullptr)
 	{
 	  rust_fatal_error (struct_expr.struct_base->base_struct->get_locus (),
@@ -222,7 +222,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
     }
 
   TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value (), false);
-  resolved_field_value_expr = field_type->get_field_type ()->unify (value);
+  resolved_field_value_expr = field_type->get_field_type ()->coerce (value);
   if (resolved_field_value_expr != nullptr)
     {
       fields_assigned.insert (field.field_name);
@@ -251,7 +251,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field)
     }
 
   TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value (), false);
-  resolved_field_value_expr = field_type->get_field_type ()->unify (value);
+  resolved_field_value_expr = field_type->get_field_type ()->coerce (value);
   if (resolved_field_value_expr != nullptr)
     {
       fields_assigned.insert (field_name);
@@ -285,7 +285,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
 			    field.get_locus ());
   TyTy::BaseType *value = TypeCheckExpr::Resolve (&expr, false);
 
-  resolved_field_value_expr = field_type->get_field_type ()->unify (value);
+  resolved_field_value_expr = field_type->get_field_type ()->coerce (value);
   if (resolved_field_value_expr != nullptr)
 
     {
diff --git a/gcc/testsuite/rust/compile/issue-1235.rs b/gcc/testsuite/rust/compile/issue-1235.rs
new file mode 100644
index 00000000000..098b337455f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1235.rs
@@ -0,0 +1,21 @@
+// { dg-additional-options "-w" }
+struct FatPtr<T> {
+    data: *const T,
+    len: usize,
+}
+
+pub union Repr<T> {
+    rust: *const [T],
+    rust_mut: *mut [T],
+    raw: FatPtr<T>,
+}
+
+impl<T> [T] {
+    pub const fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
+
+    pub const fn len(&self) -> usize {
+        unsafe { Repr { rust: self }.raw.len }
+    }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:45 [gcc/devel/rust/master] Assigning members to structures is a coercion site Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).