Skip to content

Commit 4f3cc01

Browse files
committed
Fix cross-crate inlining of static functions
1 parent 5bf9e6f commit 4f3cc01

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/librustc/middle/trans/inline.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use syntax::ast;
1313
use syntax::ast_util::local_def;
1414
use syntax::ast_map::{path, path_mod, path_name};
1515
use base::{trans_item, get_item_val, self_arg, trans_fn, impl_owned_self,
16-
impl_self, get_insn_ctxt};
16+
impl_self, no_self, get_insn_ctxt};
1717

1818
// `translate` will be true if this function is allowed to translate the
1919
// item and false otherwise. Currently, this parameter is set to false when
@@ -83,14 +83,18 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id,
8383
let path = vec::append(
8484
ty::item_path(ccx.tcx, impl_did),
8585
~[path_name(mth.ident)]);
86-
let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id);
87-
debug!("calling inline trans_fn with self_ty %s",
88-
ty_to_str(ccx.tcx, self_ty));
89-
let self_kind;
90-
match mth.self_ty.node {
91-
ast::sty_value => self_kind = impl_owned_self(self_ty),
92-
_ => self_kind = impl_self(self_ty),
93-
}
86+
let self_kind = match mth.self_ty.node {
87+
ast::sty_static => no_self,
88+
_ => {
89+
let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id);
90+
debug!("calling inline trans_fn with self_ty %s",
91+
ty_to_str(ccx.tcx, self_ty));
92+
match mth.self_ty.node {
93+
ast::sty_value => impl_owned_self(self_ty),
94+
_ => impl_self(self_ty),
95+
}
96+
}
97+
};
9498
trans_fn(ccx,
9599
path,
96100
mth.decl,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
pub mod num {
3+
pub trait Num2 {
4+
static pure fn from_int2(n: int) -> self;
5+
}
6+
}
7+
8+
pub mod float {
9+
impl float: num::Num2 {
10+
#[inline]
11+
static pure fn from_int2(n: int) -> float { return n as float; }
12+
}
13+
}
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// aux-build:static_fn_inline_xc_aux.rs
2+
3+
extern mod mycore(name ="static_fn_inline_xc_aux");
4+
5+
use mycore::num;
6+
7+
fn main() {
8+
let _1:float = num::from_int2(1i);
9+
}

0 commit comments

Comments
 (0)