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] Support placeholders becoming slices Date: Wed, 8 Jun 2022 12:20:26 +0000 (GMT) [thread overview] Message-ID: <20220608122026.B3B883852770@sourceware.org> (raw) https://gcc.gnu.org/g:f6c86fc8cdea9db5259ae67a62618b13a57ea9a1 commit f6c86fc8cdea9db5259ae67a62618b13a57ea9a1 Author: Philip Herron <philip.herron@embecosm.com> Date: Thu Mar 17 10:38:58 2022 +0000 Support placeholders becoming slices When we setup trait-impls the type-alias are allowed to become any type this interface was missing a visitor. We also need to support constraining type-parameters behind slices. The get_root interface is currently unsafe, it needs a flag for allowing unsized and for keeping a map of adjustments along the way. Fixes #1034 Diff: --- gcc/rust/typecheck/rust-hir-type-check-expr.h | 1 - gcc/rust/typecheck/rust-hir-type-check-implitem.h | 2 -- gcc/rust/typecheck/rust-tyty-cmp.h | 2 ++ gcc/rust/typecheck/rust-tyty.cc | 14 ++++++++++++++ gcc/testsuite/rust/compile/issue-1034.rs | 16 ++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 93aa868505c..1b14693aa8d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -258,7 +258,6 @@ public: // Get the adjusted self Adjuster adj (receiver_tyty); TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments); - adjusted_self->debug (); // store the adjustments for code-generation to know what to do context->insert_autoderef_mappings (expr.get_mappings ().get_hirid (), diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index 1722d16e4a9..f1b5e35450e 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -440,8 +440,6 @@ public: void visit (HIR::TypeAlias &type) override { - // resolved_trait_item = trait_reference.lookup_trait_item ( - // type.get_new_type_name (), TraitItemReference::TraitItemType::TYPE); trait_reference.lookup_trait_item_by_type ( type.get_new_type_name (), TraitItemReference::TraitItemType::TYPE, &resolved_trait_item); diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index 436bde9a295..6504e5aee1d 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -1444,6 +1444,8 @@ public: void visit (const NeverType &) override { ok = true; } + void visit (const SliceType &) override { ok = true; } + void visit (const PlaceholderType &type) override { ok = base->get_symbol ().compare (type.get_symbol ()) == 0; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index c12095f26eb..1d197f5a845 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -201,6 +201,7 @@ BaseType::inherit_bounds ( const BaseType * BaseType::get_root () const { + // FIXME this needs to be it its own visitor class with a vector adjustments const TyTy::BaseType *root = this; if (get_kind () == TyTy::REF) { @@ -212,6 +213,19 @@ BaseType::get_root () const const PointerType *r = static_cast<const PointerType *> (root); root = r->get_base ()->get_root (); } + + // these are an unsize + else if (get_kind () == TyTy::SLICE) + { + const SliceType *r = static_cast<const SliceType *> (root); + root = r->get_element_type ()->get_root (); + } + // else if (get_kind () == TyTy::ARRAY) + // { + // const ArrayType *r = static_cast<const ArrayType *> (root); + // root = r->get_element_type ()->get_root (); + // } + return root; } diff --git a/gcc/testsuite/rust/compile/issue-1034.rs b/gcc/testsuite/rust/compile/issue-1034.rs new file mode 100644 index 00000000000..23d77005452 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1034.rs @@ -0,0 +1,16 @@ +trait Foo<T> { + type Output; + + fn test(self, slice: &T) -> &Self::Output; +} + +struct Bar<T>(T); +// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } + +impl<T> Foo<[T]> for Bar<usize> { + type Output = [T]; + + fn test(self, slice: &[T]) -> &[T] { + slice + } +}
reply other threads:[~2022-06-08 12:20 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=20220608122026.B3B883852770@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).