Skip to content

Commit 1e8e509

Browse files
committed
---
yaml --- r: 29930 b: refs/heads/incoming c: a14485b h: refs/heads/master v: v3
1 parent db9ee6c commit 1e8e509

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 1300be58d7cb77d230d5269ad4346a069648e5fc
9+
refs/heads/incoming: a14485b7fd1a8a268a456ee1b47d79b10ccac875
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/rustc/middle/kind.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,8 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
226226
_ => {
227227
// Type substitions should only occur on paths and
228228
// method calls, so this needs to be a method call.
229-
match cx.method_map.get(e.id).origin {
230-
typeck::method_static(did) => {
231-
// n.b.: When we encode class/impl methods, the bounds
232-
// that we encode include both the class/impl bounds
233-
// and then the method bounds themselves...
234-
ty::lookup_item_type(cx.tcx, did).bounds
235-
}
236-
typeck::method_param({trait_id:trt_id,
237-
method_num:n_mth, _}) |
238-
typeck::method_trait(trt_id, n_mth) => {
239-
// ...trait methods bounds, in contrast, include only the
240-
// method bounds, so we must preprend the tps from the
241-
// trait itself. This ought to be harmonized.
242-
let trt_bounds =
243-
ty::lookup_item_type(cx.tcx, trt_id).bounds;
244-
let mth = ty::trait_methods(cx.tcx, trt_id)[n_mth];
245-
@(vec::append(*trt_bounds, *mth.tps))
246-
}
247-
}
229+
ty::method_call_bounds(cx.tcx, cx.method_map, e.id).expect(
230+
~"non path/method call expr has type substs??")
248231
}
249232
};
250233
if vec::len(ts) != vec::len(*bounds) {

branches/incoming/src/rustc/middle/ty.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export eval_repeat_count;
178178
export fn_proto, proto_bare, proto_vstore;
179179
export ast_proto_to_proto;
180180
export is_blockish;
181+
export method_call_bounds;
181182

182183
// Data types
183184

@@ -2414,6 +2415,32 @@ fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool {
24142415
return node_id_has_type_params(cx, expr.id);
24152416
}
24162417
2418+
fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
2419+
id: ast::node_id)
2420+
-> option<@~[param_bounds]> {
2421+
do method_map.find(id).map |method| {
2422+
match method.origin {
2423+
typeck::method_static(did) => {
2424+
// n.b.: When we encode class/impl methods, the bounds
2425+
// that we encode include both the class/impl bounds
2426+
// and then the method bounds themselves...
2427+
ty::lookup_item_type(tcx, did).bounds
2428+
}
2429+
typeck::method_param({trait_id:trt_id,
2430+
method_num:n_mth, _}) |
2431+
typeck::method_trait(trt_id, n_mth) => {
2432+
// ...trait methods bounds, in contrast, include only the
2433+
// method bounds, so we must preprend the tps from the
2434+
// trait itself. This ought to be harmonized.
2435+
let trt_bounds =
2436+
ty::lookup_item_type(tcx, trt_id).bounds;
2437+
let mth = ty::trait_methods(tcx, trt_id)[n_mth];
2438+
@(vec::append(*trt_bounds, *mth.tps))
2439+
}
2440+
}
2441+
}
2442+
}
2443+
24172444
fn expr_is_lval(method_map: typeck::method_map, e: @ast::expr) -> bool {
24182445
match e.node {
24192446
ast::expr_path(_) | ast::expr_unary(ast::deref, _) => true,

branches/incoming/src/rustc/middle/typeck/check/vtable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,8 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
252252
ast::expr_index(*) => {
253253
debug!("(vtable - resolving expr) resolving field/binary/unary/\
254254
assign/index expr");
255-
match cx.method_map.find(ex.id) {
256-
some({origin: method_static(did), _}) => {
257-
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
255+
match ty::method_call_bounds(cx.tcx, cx.method_map, ex.id) {
256+
some(bounds) => {
258257
if has_trait_bounds(*bounds) {
259258
let callee_id = match ex.node {
260259
ast::expr_field(_, _, _) => ex.id,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait TraitA {
2+
fn method_a() -> int;
3+
}
4+
5+
trait TraitB {
6+
fn gimme_an_a<A: TraitA>(a: A) -> int;
7+
}
8+
9+
impl int: TraitB {
10+
fn gimme_an_a<A: TraitA>(a: A) -> int {
11+
a.method_a() + self
12+
}
13+
}
14+
15+
fn call_it<B: TraitB>(b: B) -> int {
16+
let y = 4u;
17+
b.gimme_an_a(y) //~ ERROR failed to find an implementation of trait @TraitA for uint
18+
}
19+
20+
fn main() {
21+
let x = 3i;
22+
assert call_it(x) == 22;
23+
}

0 commit comments

Comments
 (0)