Skip to content

Commit b7baee8

Browse files
bors[bot]philberty
andauthored
Merge #1037
1037: Support placeholders becoming slices r=philberty a=philberty 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. This will be added down the line when we support unsized method resolution. Fixes #1034 Addresses #849 Co-authored-by: Philip Herron <[email protected]>
2 parents e48bce4 + f6c86fc commit b7baee8

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

gcc/rust/typecheck/rust-hir-type-check-expr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ class TypeCheckExpr : public TypeCheckBase
258258
// Get the adjusted self
259259
Adjuster adj (receiver_tyty);
260260
TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments);
261-
adjusted_self->debug ();
262261

263262
// store the adjustments for code-generation to know what to do
264263
context->insert_autoderef_mappings (expr.get_mappings ().get_hirid (),

gcc/rust/typecheck/rust-hir-type-check-implitem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,6 @@ class TypeCheckImplItemWithTrait : public TypeCheckImplItem
440440

441441
void visit (HIR::TypeAlias &type) override
442442
{
443-
// resolved_trait_item = trait_reference.lookup_trait_item (
444-
// type.get_new_type_name (), TraitItemReference::TraitItemType::TYPE);
445443
trait_reference.lookup_trait_item_by_type (
446444
type.get_new_type_name (), TraitItemReference::TraitItemType::TYPE,
447445
&resolved_trait_item);

gcc/rust/typecheck/rust-tyty-cmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,8 @@ class PlaceholderCmp : public BaseCmp
14441444

14451445
void visit (const NeverType &) override { ok = true; }
14461446

1447+
void visit (const SliceType &) override { ok = true; }
1448+
14471449
void visit (const PlaceholderType &type) override
14481450
{
14491451
ok = base->get_symbol ().compare (type.get_symbol ()) == 0;

gcc/rust/typecheck/rust-tyty.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ BaseType::inherit_bounds (
201201
const BaseType *
202202
BaseType::get_root () const
203203
{
204+
// FIXME this needs to be it its own visitor class with a vector adjustments
204205
const TyTy::BaseType *root = this;
205206
if (get_kind () == TyTy::REF)
206207
{
@@ -212,6 +213,19 @@ BaseType::get_root () const
212213
const PointerType *r = static_cast<const PointerType *> (root);
213214
root = r->get_base ()->get_root ();
214215
}
216+
217+
// these are an unsize
218+
else if (get_kind () == TyTy::SLICE)
219+
{
220+
const SliceType *r = static_cast<const SliceType *> (root);
221+
root = r->get_element_type ()->get_root ();
222+
}
223+
// else if (get_kind () == TyTy::ARRAY)
224+
// {
225+
// const ArrayType *r = static_cast<const ArrayType *> (root);
226+
// root = r->get_element_type ()->get_root ();
227+
// }
228+
215229
return root;
216230
}
217231

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Foo<T> {
2+
type Output;
3+
4+
fn test(self, slice: &T) -> &Self::Output;
5+
}
6+
7+
struct Bar<T>(T);
8+
// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
9+
10+
impl<T> Foo<[T]> for Bar<usize> {
11+
type Output = [T];
12+
13+
fn test(self, slice: &[T]) -> &[T] {
14+
slice
15+
}
16+
}

0 commit comments

Comments
 (0)