Skip to content

Commit

Permalink
Fix type parameter handling for static default methods. Closes #8654.
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Aug 22, 2013
1 parent 451de33 commit 8a9cdda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,6 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt,
sp: span,
defn: ast::def)
-> ty_param_bounds_and_ty {

match defn {
ast::def_arg(nid, _) | ast::def_local(nid, _) | ast::def_self(nid, _) |
ast::def_binding(nid, _) => {
Expand Down Expand Up @@ -3149,7 +3148,8 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
let ty_param_count = tpt.generics.type_param_defs.len();
let ty_substs_len = pth.types.len();

debug!("ty_param_count=%? ty_substs_len=%?",
debug!("tpt=%s ty_param_count=%? ty_substs_len=%?",
tpt.repr(fcx.tcx()),
ty_param_count,
ty_substs_len);

Expand Down
10 changes: 8 additions & 2 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
let substd_type_param_defs = m.generics.type_param_defs.subst(tcx, &substs);
new_type_param_defs.push_all(*substd_type_param_defs);

debug!("static method %s type_param_defs=%s substs=%s",
debug!("static method %s type_param_defs=%s ty=%s, substs=%s",
m.def_id.repr(tcx),
new_type_param_defs.repr(tcx),
ty.repr(tcx),
substs.repr(tcx));

tcx.tcache.insert(m.def_id,
Expand Down Expand Up @@ -893,8 +894,8 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
}
ast::item_trait(ref generics, _, ref trait_methods) => {
let _trait_def = trait_def_of_item(ccx, it);
ensure_trait_methods(ccx, it.id);

// Run convert_methods on the provided methods.
let (_, provided_methods) =
split_trait_methods(*trait_methods);
let untransformed_rcvr_ty = ty::mk_self(tcx, local_def(it.id));
Expand All @@ -904,6 +905,11 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
untransformed_rcvr_ty,
&ty_generics, generics,
it.vis);

// We need to do this *after* converting methods, since
// convert_methods produces a tcache entry that is wrong for
// static trait methods. This is somewhat unfortunate.
ensure_trait_methods(ccx, it.id);
}
ast::item_struct(struct_def, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "structure");
Expand Down

0 comments on commit 8a9cdda

Please sign in to comment.