Skip to content

Commit a620a22

Browse files
committed
Add missing type-checking for slice types
1 parent 77a4950 commit a620a22

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

gcc/rust/hir/tree/rust-hir-type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ class SliceType : public TypeNoBounds
668668
void accept_vis (HIRFullVisitor &vis) override;
669669
void accept_vis (HIRTypeVisitor &vis) override;
670670

671+
std::unique_ptr<Type> &get_element_type () { return elem_type; }
672+
671673
protected:
672674
/* Use covariance to implement clone function as returning this object rather
673675
* than base */

gcc/rust/typecheck/rust-hir-type-check-type.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,5 +600,15 @@ TypeCheckType::visit (HIR::ArrayType &type)
600600
TyTy::TyVar (base->get_ref ()));
601601
}
602602

603+
void
604+
TypeCheckType::visit (HIR::SliceType &type)
605+
{
606+
TyTy::BaseType *base
607+
= TypeCheckType::Resolve (type.get_element_type ().get ());
608+
translated
609+
= new TyTy::SliceType (type.get_mappings ().get_hirid (), type.get_locus (),
610+
TyTy::TyVar (base->get_ref ()));
611+
}
612+
603613
} // namespace Resolver
604614
} // namespace Rust

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class TypeCheckType : public TypeCheckBase
120120

121121
void visit (HIR::ArrayType &type) override;
122122

123+
void visit (HIR::SliceType &type) override;
124+
123125
void visit (HIR::ReferenceType &type) override
124126
{
125127
TyTy::BaseType *base
@@ -338,8 +340,8 @@ class ResolveWhereClauseItem : public TypeCheckBase
338340
binding->inherit_bounds (specified_bounds);
339341

340342
// When we apply these bounds we must lookup which type this binding
341-
// resolves to, as this is the type which will be used during resolution of
342-
// the block.
343+
// resolves to, as this is the type which will be used during resolution
344+
// of the block.
343345
NodeId ast_node_id = binding_type_path->get_mappings ().get_nodeid ();
344346

345347
// then lookup the reference_node_id

0 commit comments

Comments
 (0)