Skip to content

Commit de0268b

Browse files
committed
librustc: Fix translation of cross-crate inline or generic methods with explicit self. rs=blocking-snapshot
1 parent 917ee7e commit de0268b

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ fn trans_fn(ccx: @crate_ctxt,
16441644
let do_time = ccx.sess.trans_stats();
16451645
let start = if do_time { time::get_time() }
16461646
else { {sec: 0i64, nsec: 0i32} };
1647+
debug!("trans_fn(ty_self=%?)", ty_self);
16471648
let _icx = ccx.insn_ctxt("trans_fn");
16481649
ccx.stats.n_fns += 1;
16491650
trans_closure(ccx, path, decl, body, llfndecl, ty_self,

src/librustc/middle/trans/inline.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use common::*;
22
use syntax::ast;
33
use syntax::ast_util::local_def;
44
use syntax::ast_map::{path, path_mod, path_name};
5-
use base::{trans_item, get_item_val, self_arg, trans_fn,
6-
impl_self, get_insn_ctxt};
5+
use base::{trans_item, get_item_val, self_arg, trans_fn, impl_owned_self,
6+
impl_self, get_insn_ctxt};
77

88
// `translate` will be true if this function is allowed to translate the
99
// item and false otherwise. Currently, this parameter is set to false when
@@ -66,15 +66,29 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id,
6666
csearch::found(ast::ii_method(impl_did, mth)) => {
6767
ccx.stats.n_inlines += 1;
6868
ccx.external.insert(fn_id, Some(mth.id));
69-
let {bounds: impl_bnds, region_param: _, ty: impl_ty} =
69+
let {bounds: impl_bnds, region_param: _, ty: _} =
7070
ty::lookup_item_type(ccx.tcx, impl_did);
7171
if translate && (*impl_bnds).len() + mth.tps.len() == 0u {
7272
let llfn = get_item_val(ccx, mth.id);
7373
let path = vec::append(
7474
ty::item_path(ccx.tcx, impl_did),
7575
~[path_name(mth.ident)]);
76-
trans_fn(ccx, path, mth.decl, mth.body,
77-
llfn, impl_self(impl_ty), None, mth.id,
76+
let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id);
77+
debug!("calling inline trans_fn with self_ty %s",
78+
ty_to_str(ccx.tcx, self_ty));
79+
let self_kind;
80+
match mth.self_ty.node {
81+
ast::sty_value => self_kind = impl_owned_self(self_ty),
82+
_ => self_kind = impl_self(self_ty),
83+
}
84+
trans_fn(ccx,
85+
path,
86+
mth.decl,
87+
mth.body,
88+
llfn,
89+
self_kind,
90+
None,
91+
mth.id,
7892
Some(impl_did));
7993
}
8094
local_def(mth.id)

src/librustc/middle/trans/meth.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ fn trans_method(ccx: @crate_ctxt,
9898
ty::subst_tps(ccx.tcx, *tys, None, self_ty)
9999
}
100100
};
101+
debug!("calling trans_fn with base_self_ty %s, self_ty %s",
102+
match base_self_ty {
103+
None => ~"(none)",
104+
Some(x) => ty_to_str(ccx.tcx, x),
105+
},
106+
ty_to_str(ccx.tcx, self_ty));
101107
match method.self_ty.node {
102108
ast::sty_value => {
103109
impl_owned_self(self_ty)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub trait Foo {
2+
#[inline(always)]
3+
fn f(&self);
4+
}
5+
6+
pub struct Bar {
7+
x: ~str
8+
}
9+
10+
impl Bar : Foo {
11+
#[inline(always)]
12+
fn f(&self) {
13+
io::println((*self).x);
14+
}
15+
}
16+
17+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// xfail-fast
2+
// aux-build:explicit_self_xcrate.rs
3+
4+
extern mod explicit_self_xcrate;
5+
use explicit_self_xcrate::{Foo, Bar};
6+
7+
fn main() {
8+
let x = Bar { x: ~"hello" };
9+
x.f();
10+
}
11+

0 commit comments

Comments
 (0)