Skip to content

Commit 57ee34c

Browse files
committed
Actually resolve trait bounds on impls. Closes #7266.
1 parent 817f980 commit 57ee34c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
609609
for ms.iter().advance |m| {
610610
check_method(ccx, *m);
611611
}
612+
vtable::resolve_impl(ccx, it);
612613
}
613614
ast::item_trait(_, _, ref trait_methods) => {
614615
for (*trait_methods).iter().advance |trait_method| {

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ pub fn location_info_for_expr(expr: @ast::expr) -> LocationInfo {
478478
id: expr.id
479479
}
480480
}
481+
pub fn location_info_for_item(item: @ast::item) -> LocationInfo {
482+
LocationInfo {
483+
span: item.span,
484+
id: item.id
485+
}
486+
}
481487

482488
pub fn early_resolve_expr(ex: @ast::expr,
483489
fcx: @mut FnCtxt,
@@ -661,6 +667,27 @@ fn resolve_expr(ex: @ast::expr,
661667
visit::visit_expr(ex, (fcx, v));
662668
}
663669

670+
pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) {
671+
let def_id = ast_util::local_def(impl_item.id);
672+
match ty::impl_trait_ref(ccx.tcx, def_id) {
673+
None => {},
674+
Some(trait_ref) => {
675+
let infcx = infer::new_infer_ctxt(ccx.tcx);
676+
let vcx = VtableContext { ccx: ccx, infcx: infcx };
677+
let trait_def = ty::lookup_trait_def(ccx.tcx, trait_ref.def_id);
678+
679+
let vtbls = lookup_vtables(&vcx,
680+
&location_info_for_item(impl_item),
681+
*trait_def.generics.type_param_defs,
682+
&trait_ref.substs,
683+
false);
684+
685+
// FIXME(#7450): Doesn't work cross crate
686+
ccx.vtable_map.insert(impl_item.id, vtbls);
687+
}
688+
}
689+
}
690+
664691
// Detect points where a trait-bounded type parameter is
665692
// instantiated, resolve the impls for the parameters.
666693
pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::blk) {

0 commit comments

Comments
 (0)