Skip to content

Commit 54f31c2

Browse files
committed
---
yaml --- r: 24459 b: refs/heads/master c: b80b068 h: refs/heads/master i: 24457: c3e2372 24455: 4b745a4 v: v3
1 parent 2794eb1 commit 54f31c2

File tree

9 files changed

+62
-16
lines changed

9 files changed

+62
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 02c33f8d316cca760b380e5d9fc4762629a9f968
2+
refs/heads/master: b80b0688d5ccc276e1dd3b6dfeeaea5e6f2782de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/astencode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ impl method_origin: tr {
493493
typeck::method_trait(did, m, vstore) => {
494494
typeck::method_trait(did.tr(xcx), m, vstore)
495495
}
496+
typeck::method_self(did, m) => {
497+
typeck::method_self(did.tr(xcx), m)
498+
}
496499
}
497500
}
498501
}

trunk/src/rustc/middle/privacy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use syntax::ast::{item_trait, local_crate, node_id, pat_struct, private};
88
use syntax::ast::{provided, required};
99
use syntax::ast_map::{node_item, node_method};
1010
use ty::ty_class;
11-
use typeck::{method_map, method_origin, method_param, method_static};
12-
use typeck::{method_trait};
11+
use typeck::{method_map, method_origin, method_param, method_self};
12+
use typeck::{method_static, method_trait};
1313

1414
use core::util::ignore;
1515
use dvec::DVec;
@@ -81,7 +81,8 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
8181
}
8282
}
8383
method_param({trait_id: trait_id, method_num: method_num, _}) |
84-
method_trait(trait_id, method_num, _) => {
84+
method_trait(trait_id, method_num, _) |
85+
method_self(trait_id, method_num) => {
8586
if trait_id.crate == local_crate {
8687
match tcx.items.find(trait_id.node) {
8788
Some(node_item(item, _)) => {

trunk/src/rustc/middle/trans/base.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18471847
}
18481848
}
18491849
}
1850-
ast::item_impl(tps, trait_refs, _, ms) => {
1850+
ast::item_impl(tps, trait_refs, self_ast_ty, ms) => {
18511851
meth::trans_impl(ccx, *path, item.ident, ms, tps, None);
18521852

18531853
// Translate any methods that have provided implementations.
@@ -1860,13 +1860,22 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18601860
loop;
18611861
}
18621862

1863+
// Get the self type.
1864+
let self_ty;
1865+
match ccx.tcx.ast_ty_to_ty_cache.get(self_ast_ty) {
1866+
ty::atttce_resolved(self_type) => self_ty = self_type,
1867+
ty::atttce_unresolved => {
1868+
ccx.tcx.sess.impossible_case(item.span,
1869+
~"didn't cache self ast ty");
1870+
}
1871+
}
1872+
18631873
match ccx.tcx.items.get(trait_id.node) {
18641874
ast_map::node_item(trait_item, _) => {
18651875
match trait_item.node {
18661876
ast::item_trait(tps, _, trait_methods) => {
1867-
// XXX: ty_self is wrong here. Get the real type.
18681877
trans_trait(ccx, tps, trait_methods, path,
1869-
item.ident, ty::mk_self(ccx.tcx));
1878+
item.ident, self_ty);
18701879
}
18711880
_ => {
18721881
ccx.tcx.sess.impossible_case(item.span,

trunk/src/rustc/middle/trans/meth.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
154154
typeck::method_trait(_, off, vstore) => {
155155
trans_trait_callee(bcx, callee_id, off, self, vstore)
156156
}
157+
typeck::method_self(_, off) => {
158+
bcx.tcx().sess.span_bug(self.span, ~"self method call");
159+
}
157160
}
158161
}
159162

trunk/src/rustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn mark_for_expr(cx: ctx, e: @expr) {
247247
typeck::method_param({param_num: param, _}) => {
248248
cx.uses[param] |= use_tydesc;
249249
}
250-
typeck::method_trait(*) => (),
250+
typeck::method_trait(*) | typeck::method_self(*) => (),
251251
}
252252
}
253253
}

trunk/src/rustc/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2826,7 +2826,8 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
28262826
}
28272827
typeck::method_param({trait_id:trt_id,
28282828
method_num:n_mth, _}) |
2829-
typeck::method_trait(trt_id, n_mth, _) => {
2829+
typeck::method_trait(trt_id, n_mth, _) |
2830+
typeck::method_self(trt_id, n_mth) => {
28302831
// ...trait methods bounds, in contrast, include only the
28312832
// method bounds, so we must preprend the tps from the
28322833
// trait itself. This ought to be harmonized.

trunk/src/rustc/middle/typeck.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export deserialize_method_map_entry;
7373
export vtable_map;
7474
export vtable_res;
7575
export vtable_origin;
76-
export method_static, method_param, method_trait;
76+
export method_static, method_param, method_trait, method_self;
7777
export vtable_static, vtable_param, vtable_trait;
7878
export provided_methods_map;
7979

@@ -87,6 +87,9 @@ enum method_origin {
8787

8888
// method invoked on a trait instance
8989
method_trait(ast::def_id, uint, ty::vstore),
90+
91+
// method invoked on "self" inside a default method
92+
method_self(ast::def_id, uint),
9093
}
9194

9295
// details for a method invoked with a receiver whose type is a type parameter

trunk/src/rustc/middle/typeck/check/method.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@ impl LookupContext {
232232
let self_did = self.fcx.self_impl_def_id.expect(
233233
~"unexpected `none` for self_impl_def_id");
234234
let substs = {self_r: None, self_ty: None, tps: ~[]};
235-
self.push_inherent_candidates_from_trait(
236-
self_ty, self_did, &substs,
237-
ty::vstore_slice(ty::re_static)); // XXX: Wrong!
235+
self.push_inherent_candidates_from_self(
236+
self_ty, self_did, &substs);
238237
}
239238
ty_enum(did, _) | ty_class(did, _) => {
240239
self.push_inherent_impl_candidates_for_type(did);
@@ -397,6 +396,33 @@ impl LookupContext {
397396
});
398397
}
399398

399+
fn push_inherent_candidates_from_self(&self,
400+
self_ty: ty::t,
401+
did: def_id,
402+
substs: &ty::substs) {
403+
let tcx = self.tcx();
404+
let methods = ty::trait_methods(tcx, did); // XXX: Inherited methods.
405+
let index;
406+
match vec::position(*methods, |m| m.ident == self.m_name) {
407+
Some(i) => index = i,
408+
None => return
409+
}
410+
let method = &methods[index];
411+
412+
let rcvr_substs = { self_ty: Some(self_ty), ..*substs };
413+
let (rcvr_ty, rcvr_substs) =
414+
self.create_rcvr_ty_and_substs_for_method(
415+
method.self_ty, self_ty, move rcvr_substs);
416+
417+
self.inherent_candidates.push(Candidate {
418+
rcvr_ty: rcvr_ty,
419+
rcvr_substs: move rcvr_substs,
420+
num_method_tps: method.tps.len(),
421+
self_mode: get_mode_from_self_type(method.self_ty),
422+
origin: method_self(did, index)
423+
});
424+
}
425+
400426
fn push_inherent_impl_candidates_for_type(did: def_id)
401427
{
402428
let opt_impl_infos =
@@ -737,7 +763,7 @@ impl LookupContext {
737763
* vtable and hence cannot be monomorphized. */
738764

739765
match candidate.origin {
740-
method_static(*) | method_param(*) => {
766+
method_static(*) | method_param(*) | method_self(*) => {
741767
return; // not a call to a trait instance
742768
}
743769
method_trait(*) => {}
@@ -772,7 +798,7 @@ impl LookupContext {
772798
method_param(ref mp) => {
773799
type_of_trait_method(self.tcx(), mp.trait_id, mp.method_num)
774800
}
775-
method_trait(did, idx, _) => {
801+
method_trait(did, idx, _) | method_self(did, idx) => {
776802
type_of_trait_method(self.tcx(), did, idx)
777803
}
778804
};
@@ -793,7 +819,7 @@ impl LookupContext {
793819
method_param(mp) => {
794820
self.report_param_candidate(idx, mp.trait_id)
795821
}
796-
method_trait(trait_did, _, _) => {
822+
method_trait(trait_did, _, _) | method_self(trait_did, _) => {
797823
self.report_param_candidate(idx, trait_did)
798824
}
799825
}

0 commit comments

Comments
 (0)