diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-03-17 10:38:58 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-03-17 11:02:58 +0000 |
commit | f6c86fc8cdea9db5259ae67a62618b13a57ea9a1 (patch) | |
tree | 799643f617b6a9a52ef1e96eadae480da843d4da /gcc | |
parent | fe13ad49b1da5285719b176bb5d00a94b9260ebf (diff) | |
download | gcc-f6c86fc8cdea9db5259ae67a62618b13a57ea9a1.zip gcc-f6c86fc8cdea9db5259ae67a62618b13a57ea9a1.tar.gz gcc-f6c86fc8cdea9db5259ae67a62618b13a57ea9a1.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-implitem.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-cmp.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 14 | ||||
-rw-r--r-- | 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 93aa868..1b14693 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 1722d16..f1b5e35 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 436bde9..6504e5a 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 c12095f..1d197f5 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 0000000..23d7700 --- /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 + } +} |