public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Support placeholders becoming slices
@ 2022-06-08 12:20 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:20 UTC (permalink / raw)
To: gcc-cvs
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
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:20 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:20 [gcc/devel/rust/master] Support placeholders becoming slices 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).