Skip to content

Commit a71c904

Browse files
committed
---
yaml --- r: 142806 b: refs/heads/try2 c: 1bbb434 h: refs/heads/master v: v3
1 parent 29e876a commit a71c904

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 2b89b437fb38a4388d8f868f13d1200a22157e8a
8+
refs/heads/try2: 1bbb4348806dab6d9b4c280d4cfd324645969eca
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/monomorphize.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
111111
let tpt = ty::lookup_item_type(ccx.tcx, fn_id);
112112
let llitem_ty = tpt.ty;
113113

114+
// We need to do special handling of the substitutions if we are
115+
// calling a static provided method. This is sort of unfortunate.
116+
let mut is_static_provided = None;
117+
114118
let map_node = session::expect(
115119
ccx.sess,
116120
ccx.tcx.items.find_copy(&fn_id.node),
@@ -129,6 +133,12 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
129133
return (get_item_val(ccx, fn_id.node), true);
130134
}
131135
ast_map::node_trait_method(@ast::provided(m), _, pt) => {
136+
// If this is a static provided method, indicate that
137+
// and stash the number of params on the method.
138+
if m.explicit_self.node == ast::sty_static {
139+
is_static_provided = Some(m.generics.ty_params.len());
140+
}
141+
132142
(pt, m.ident, m.span)
133143
}
134144
ast_map::node_trait_method(@ast::required(_), _, _) => {
@@ -153,8 +163,36 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
153163
ast_map::node_struct_ctor(_, i, pt) => (pt, i.ident, i.span)
154164
};
155165

156-
let mono_ty = ty::subst_tps(ccx.tcx, psubsts.tys,
157-
psubsts.self_ty, llitem_ty);
166+
debug!("monomorphic_fn about to subst into %s", llitem_ty.repr(ccx.tcx));
167+
let mono_ty = match is_static_provided {
168+
None => ty::subst_tps(ccx.tcx, psubsts.tys,
169+
psubsts.self_ty, llitem_ty),
170+
Some(num_method_ty_params) => {
171+
// Static default methods are a little unfortunate, in
172+
// that the "internal" and "external" type of them differ.
173+
// Internally, the method body can refer to Self, but the
174+
// externally visable type of the method has a type param
175+
// inserted in between the trait type params and the
176+
// method type params. The substs that we are given are
177+
// the proper substs *internally* to the method body, so
178+
// we have to use those when compiling it.
179+
//
180+
// In order to get the proper substitution to use on the
181+
// type of the method, we pull apart the substitution and
182+
// stick a substitution for the self type in.
183+
// This is a bit unfortunate.
184+
185+
let idx = psubsts.tys.len() - num_method_ty_params;
186+
let substs =
187+
(psubsts.tys.slice(0, idx) +
188+
&[psubsts.self_ty.get()] +
189+
psubsts.tys.tailn(idx));
190+
debug!("static default: changed substitution to %s",
191+
substs.repr(ccx.tcx));
192+
193+
ty::subst_tps(ccx.tcx, substs, None, llitem_ty)
194+
}
195+
};
158196
let llfty = type_of_fn_from_ty(ccx, mono_ty);
159197

160198
ccx.stats.n_monos += 1;

0 commit comments

Comments
 (0)