8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ #![ allow( unused_imports, unused_variables, dead_code) ]
12
+
11
13
use rustc:: middle:: allocator:: AllocatorKind ;
12
14
use rustc_errors;
13
15
use rustc_target:: spec:: abi:: Abi ;
@@ -35,13 +37,15 @@ pub fn modify(
35
37
sess : & ParseSess ,
36
38
resolver : & mut Resolver ,
37
39
krate : Crate ,
40
+ crate_name : String ,
38
41
handler : & rustc_errors:: Handler ,
39
42
) -> ast:: Crate {
40
43
ExpandAllocatorDirectives {
41
44
handler,
42
45
sess,
43
46
resolver,
44
47
found : false ,
48
+ crate_name : Some ( crate_name) ,
45
49
} . fold_crate ( krate)
46
50
}
47
51
@@ -50,6 +54,7 @@ struct ExpandAllocatorDirectives<'a> {
50
54
handler : & ' a rustc_errors:: Handler ,
51
55
sess : & ' a ParseSess ,
52
56
resolver : & ' a mut Resolver ,
57
+ crate_name : Option < String > ,
53
58
}
54
59
55
60
impl < ' a > Folder for ExpandAllocatorDirectives < ' a > {
@@ -78,26 +83,34 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
78
83
}
79
84
self . found = true ;
80
85
86
+ // Create a fresh Mark for the new macro expansion we are about to do
81
87
let mark = Mark :: fresh ( Mark :: root ( ) ) ;
82
88
mark. set_expn_info ( ExpnInfo {
83
- call_site : DUMMY_SP ,
89
+ call_site : item . span ,
84
90
callee : NameAndSpan {
85
91
format : MacroAttribute ( Symbol :: intern ( name) ) ,
86
92
span : None ,
87
93
allow_internal_unstable : true ,
88
94
allow_internal_unsafe : false ,
89
95
} ,
90
96
} ) ;
97
+
98
+ // Tie the span to the macro expansion info we just created
91
99
let span = item. span . with_ctxt ( SyntaxContext :: empty ( ) . apply_mark ( mark) ) ;
92
- let ecfg = ExpansionConfig :: default ( name. to_string ( ) ) ;
100
+
101
+ // Create an expansion config
102
+ let ecfg = ExpansionConfig :: default ( self . crate_name . take ( ) . unwrap ( ) ) ;
103
+
104
+ // Generate a bunch of new items using the AllocFnFactory
93
105
let mut f = AllocFnFactory {
94
106
span,
95
107
kind : AllocatorKind :: Global ,
96
108
global : item. ident ,
97
109
core : Ident :: from_str ( "core" ) ,
98
110
cx : ExtCtxt :: new ( self . sess , ecfg, self . resolver ) ,
99
111
} ;
100
- let super_path = f. cx . path ( f. span , vec ! [ Ident :: from_str( "super" ) , f. global] ) ;
112
+ //let super_path = f.cx.path(f.span, vec![Ident::from_str("super"), f.global]);
113
+ let super_path = f. cx . path ( f. span , vec ! [ f. global] ) ;
101
114
let mut items = vec ! [
102
115
f. cx. item_extern_crate( f. span, f. core) ,
103
116
f. cx. item_use_simple(
0 commit comments