1- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
22// file at the top-level directory of this distribution and at
33// http://rust-lang.org/COPYRIGHT.
44//
@@ -19,18 +19,18 @@ use syntax::ast;
1919use syntax:: ast_util:: { local_def, PostExpansionMethod } ;
2020use syntax:: ast_util;
2121
22- pub fn maybe_instantiate_inline ( ccx : & CrateContext , fn_id : ast:: DefId )
23- -> ast:: DefId {
22+ fn instantiate_inline ( ccx : & CrateContext , fn_id : ast:: DefId )
23+ -> Option < ast:: DefId > {
2424 let _icx = push_ctxt ( "maybe_instantiate_inline" ) ;
2525 match ccx. external ( ) . borrow ( ) . find ( & fn_id) {
2626 Some ( & Some ( node_id) ) => {
2727 // Already inline
2828 debug ! ( "maybe_instantiate_inline({}): already inline as node id {}" ,
2929 ty:: item_path_str( ccx. tcx( ) , fn_id) , node_id) ;
30- return local_def ( node_id) ;
30+ return Some ( local_def ( node_id) ) ;
3131 }
3232 Some ( & None ) => {
33- return fn_id ; // Not inlinable
33+ return None ; // Not inlinable
3434 }
3535 None => {
3636 // Not seen yet
@@ -41,10 +41,11 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
4141 csearch:: maybe_get_item_ast (
4242 ccx. tcx ( ) , fn_id,
4343 |a, b, c, d| astencode:: decode_inlined_item ( a, b, c, d) ) ;
44- return match csearch_result {
44+
45+ let inline_def = match csearch_result {
4546 csearch:: not_found => {
4647 ccx. external ( ) . borrow_mut ( ) . insert ( fn_id, None ) ;
47- fn_id
48+ return None ;
4849 }
4950 csearch:: found( ast:: IIItem ( item) ) => {
5051 ccx. external ( ) . borrow_mut ( ) . insert ( fn_id, Some ( item. id ) ) ;
@@ -182,4 +183,19 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
182183 }
183184 }
184185 } ;
186+
187+ return Some ( inline_def) ;
188+ }
189+
190+ pub fn get_local_instance ( ccx : & CrateContext , fn_id : ast:: DefId )
191+ -> Option < ast:: DefId > {
192+ if fn_id. krate == ast:: LOCAL_CRATE {
193+ Some ( fn_id)
194+ } else {
195+ instantiate_inline ( ccx, fn_id)
196+ }
197+ }
198+
199+ pub fn maybe_instantiate_inline ( ccx : & CrateContext , fn_id : ast:: DefId ) -> ast:: DefId {
200+ get_local_instance ( ccx, fn_id) . unwrap_or ( fn_id)
185201}
0 commit comments