public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Assigning members to structures is a coercion site Date: Wed, 8 Jun 2022 12:45:30 +0000 (GMT) [thread overview] Message-ID: <20220608124530.12DE93895FE2@sourceware.org> (raw) 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 } + } +}
reply other threads:[~2022-06-08 12:45 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608124530.12DE93895FE2@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).