1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -19,18 +19,18 @@ use syntax::ast;
19
19
use syntax:: ast_util:: { local_def, PostExpansionMethod } ;
20
20
use syntax:: ast_util;
21
21
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 > {
24
24
let _icx = push_ctxt ( "maybe_instantiate_inline" ) ;
25
25
match ccx. external ( ) . borrow ( ) . find ( & fn_id) {
26
26
Some ( & Some ( node_id) ) => {
27
27
// Already inline
28
28
debug ! ( "maybe_instantiate_inline({}): already inline as node id {}" ,
29
29
ty:: item_path_str( ccx. tcx( ) , fn_id) , node_id) ;
30
- return local_def ( node_id) ;
30
+ return Some ( local_def ( node_id) ) ;
31
31
}
32
32
Some ( & None ) => {
33
- return fn_id ; // Not inlinable
33
+ return None ; // Not inlinable
34
34
}
35
35
None => {
36
36
// Not seen yet
@@ -41,10 +41,11 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
41
41
csearch:: maybe_get_item_ast (
42
42
ccx. tcx ( ) , fn_id,
43
43
|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 {
45
46
csearch:: not_found => {
46
47
ccx. external ( ) . borrow_mut ( ) . insert ( fn_id, None ) ;
47
- fn_id
48
+ return None ;
48
49
}
49
50
csearch:: found( ast:: IIItem ( item) ) => {
50
51
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)
182
183
}
183
184
}
184
185
} ;
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)
185
201
}
0 commit comments