Skip to content

Support placeholders becoming slices #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class TypeCheckExpr : public TypeCheckBase
// 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 (),
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-implitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,6 @@ class TypeCheckImplItemWithTrait : public TypeCheckImplItem

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);
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/typecheck/rust-tyty-cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,8 @@ class PlaceholderCmp : public BaseCmp

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;
Expand Down
14 changes: 14 additions & 0 deletions gcc/rust/typecheck/rust-tyty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions gcc/testsuite/rust/compile/issue-1034.rs
Original file line number Diff line number Diff line change
@@ -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
}
}