Skip to content

Commit 8448711

Browse files
committed
Add classes and class fields to the tcache
They were being added lazily, which prevented class types from being used as an argument to a variant.
1 parent bdef907 commit 8448711

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/rustc/middle/typeck/collect.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ fn check_methods_against_iface(ccx: @crate_ctxt,
115115

116116
fn convert_class_item(ccx: @crate_ctxt,
117117
rp: ast::region_param,
118+
bounds: @[ty::param_bounds],
118119
v: ast_util::ivar) {
119120
/* we want to do something here, b/c within the
120121
scope of the class, it's ok to refer to fields &
@@ -123,6 +124,8 @@ fn convert_class_item(ccx: @crate_ctxt,
123124
class. outside the class, it's done with expr_field */
124125
let tt = ccx.to_ty(type_rscope(rp), v.ty);
125126
write_ty_to_tcx(ccx.tcx, v.id, tt);
127+
/* add the field to the tcache */
128+
ccx.tcx.tcache.insert(local_def(v.id), {bounds: bounds, rp: rp, ty: tt});
126129
}
127130

128131
fn convert_methods(ccx: @crate_ctxt,
@@ -228,6 +231,8 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
228231
// Write the class type
229232
let tpt = ty_of_item(ccx, it);
230233
write_ty_to_tcx(tcx, it.id, tpt.ty);
234+
tcx.tcache.insert(local_def(it.id), {bounds: tpt.bounds,
235+
rp: rp, ty: tpt.ty});
231236
// Write the ctor type
232237
let t_ctor =
233238
ty::mk_fn(
@@ -264,7 +269,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
264269
// Write the type of each of the members
265270
let (fields, methods) = split_class_items(members);
266271
for fields.each {|f|
267-
convert_class_item(ccx, rp, f);
272+
convert_class_item(ccx, rp, tpt.bounds, f);
268273
}
269274
// The selfty is just the class type
270275
let {bounds:_, substs} = mk_substs(ccx, tps, rp);

0 commit comments

Comments
 (0)