File tree 7 files changed +71
-4
lines changed
7 files changed +71
-4
lines changed Original file line number Diff line number Diff line change @@ -668,6 +668,8 @@ class SliceType : public TypeNoBounds
668
668
void accept_vis (HIRFullVisitor &vis) override ;
669
669
void accept_vis (HIRTypeVisitor &vis) override ;
670
670
671
+ std::unique_ptr<Type> &get_element_type () { return elem_type; }
672
+
671
673
protected:
672
674
/* Use covariance to implement clone function as returning this object rather
673
675
* than base */
Original file line number Diff line number Diff line change @@ -600,5 +600,15 @@ TypeCheckType::visit (HIR::ArrayType &type)
600
600
TyTy::TyVar (base->get_ref ()));
601
601
}
602
602
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
+
603
613
} // namespace Resolver
604
614
} // namespace Rust
Original file line number Diff line number Diff line change @@ -120,6 +120,8 @@ class TypeCheckType : public TypeCheckBase
120
120
121
121
void visit (HIR::ArrayType &type) override ;
122
122
123
+ void visit (HIR::SliceType &type) override ;
124
+
123
125
void visit (HIR::ReferenceType &type) override
124
126
{
125
127
TyTy::BaseType *base
@@ -347,8 +349,8 @@ class ResolveWhereClauseItem : public TypeCheckBase
347
349
binding->inherit_bounds (specified_bounds);
348
350
349
351
// When we apply these bounds we must lookup which type this binding
350
- // resolves to, as this is the type which will be used during resolution of
351
- // the block.
352
+ // resolves to, as this is the type which will be used during resolution
353
+ // of the block.
352
354
NodeId ast_node_id = binding_type_path->get_mappings ().get_nodeid ();
353
355
354
356
// then lookup the reference_node_id
Original file line number Diff line number Diff line change @@ -221,11 +221,19 @@ class SubstMapperInternal : public TyTy::TyVisitor
221
221
resolved = type.handle_substitions (mappings);
222
222
}
223
223
224
+ void visit (TyTy::ArrayType &type) override
225
+ {
226
+ resolved = type.handle_substitions (mappings);
227
+ }
228
+
229
+ void visit (TyTy::SliceType &type) override
230
+ {
231
+ resolved = type.handle_substitions (mappings);
232
+ }
233
+
224
234
// nothing to do for these
225
235
void visit (TyTy::InferType &) override { gcc_unreachable (); }
226
236
void visit (TyTy::FnPtr &) override { gcc_unreachable (); }
227
- void visit (TyTy::ArrayType &) override { gcc_unreachable (); }
228
- void visit (TyTy::SliceType &) override { gcc_unreachable (); }
229
237
void visit (TyTy::BoolType &) override { gcc_unreachable (); }
230
238
void visit (TyTy::IntType &) override { gcc_unreachable (); }
231
239
void visit (TyTy::UintType &) override { gcc_unreachable (); }
Original file line number Diff line number Diff line change @@ -1508,6 +1508,22 @@ ArrayType::clone () const
1508
1508
element_type, get_combined_refs ());
1509
1509
}
1510
1510
1511
+ ArrayType *
1512
+ ArrayType::handle_substitions (SubstitutionArgumentMappings mappings)
1513
+ {
1514
+ auto mappings_table = Analysis::Mappings::get ();
1515
+
1516
+ ArrayType *ref = static_cast <ArrayType *> (clone ());
1517
+ ref->set_ty_ref (mappings_table->get_next_hir_id ());
1518
+
1519
+ // might be &T or &ADT so this needs to be recursive
1520
+ auto base = ref->get_element_type ();
1521
+ BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
1522
+ ref->element_type = TyVar (concrete->get_ty_ref ());
1523
+
1524
+ return ref;
1525
+ }
1526
+
1511
1527
void
1512
1528
SliceType::accept_vis (TyVisitor &vis)
1513
1529
{
@@ -1581,6 +1597,22 @@ SliceType::clone () const
1581
1597
get_combined_refs ());
1582
1598
}
1583
1599
1600
+ SliceType *
1601
+ SliceType::handle_substitions (SubstitutionArgumentMappings mappings)
1602
+ {
1603
+ auto mappings_table = Analysis::Mappings::get ();
1604
+
1605
+ SliceType *ref = static_cast <SliceType *> (clone ());
1606
+ ref->set_ty_ref (mappings_table->get_next_hir_id ());
1607
+
1608
+ // might be &T or &ADT so this needs to be recursive
1609
+ auto base = ref->get_element_type ();
1610
+ BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
1611
+ ref->element_type = TyVar (concrete->get_ty_ref ());
1612
+
1613
+ return ref;
1614
+ }
1615
+
1584
1616
void
1585
1617
BoolType::accept_vis (TyVisitor &vis)
1586
1618
{
Original file line number Diff line number Diff line change @@ -1665,6 +1665,8 @@ class ArrayType : public BaseType
1665
1665
1666
1666
HIR::Expr &get_capacity_expr () const { return capacity_expr; }
1667
1667
1668
+ ArrayType *handle_substitions (SubstitutionArgumentMappings mappings);
1669
+
1668
1670
private:
1669
1671
TyVar element_type;
1670
1672
HIR::Expr &capacity_expr;
@@ -1710,6 +1712,8 @@ class SliceType : public BaseType
1710
1712
return get_element_type ()->is_concrete ();
1711
1713
}
1712
1714
1715
+ SliceType *handle_substitions (SubstitutionArgumentMappings mappings);
1716
+
1713
1717
private:
1714
1718
TyVar element_type;
1715
1719
};
Original file line number Diff line number Diff line change @@ -68,6 +68,9 @@ class RustLangItem
68
68
RANGE_INCLUSIVE,
69
69
RANGE_TO_INCLUSIVE,
70
70
71
+ // https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
72
+ CONST_PTR,
73
+
71
74
UNKNOWN,
72
75
};
73
76
@@ -201,6 +204,10 @@ class RustLangItem
201
204
{
202
205
return ItemType::RANGE_TO_INCLUSIVE;
203
206
}
207
+ else if (item.compare (" const_ptr" ) == 0 )
208
+ {
209
+ return ItemType::CONST_PTR;
210
+ }
204
211
205
212
return ItemType::UNKNOWN;
206
213
}
@@ -273,6 +280,8 @@ class RustLangItem
273
280
return " RangeInclusive" ;
274
281
case RANGE_TO_INCLUSIVE:
275
282
return " RangeToInclusive" ;
283
+ case CONST_PTR:
284
+ return " const_ptr" ;
276
285
277
286
case UNKNOWN:
278
287
return " <UNKNOWN>" ;
You can’t perform that action at this time.
0 commit comments