@@ -26,14 +26,14 @@ pub fn expand(
2626
2727 // Allow using `#[global_allocator]` on an item statement
2828 // FIXME - if we get deref patterns, use them to reduce duplication here
29- let ( item, is_stmt) = match & item {
29+ let ( item, is_stmt, ty_span ) = match & item {
3030 Annotatable :: Item ( item) => match item. kind {
31- ItemKind :: Static ( ..) => ( item, false ) ,
31+ ItemKind :: Static ( ref ty , ..) => ( item, false , ecx . with_def_site_ctxt ( ty . span ) ) ,
3232 _ => return not_static ( ) ,
3333 } ,
3434 Annotatable :: Stmt ( stmt) => match & stmt. kind {
3535 StmtKind :: Item ( item_) => match item_. kind {
36- ItemKind :: Static ( ..) => ( item_, true ) ,
36+ ItemKind :: Static ( ref ty , ..) => ( item_, true , ecx . with_def_site_ctxt ( ty . span ) ) ,
3737 _ => return not_static ( ) ,
3838 } ,
3939 _ => return not_static ( ) ,
@@ -43,13 +43,14 @@ pub fn expand(
4343
4444 // Generate a bunch of new items using the AllocFnFactory
4545 let span = ecx. with_def_site_ctxt ( item. span ) ;
46- let f = AllocFnFactory { span, kind : AllocatorKind :: Global , global : item. ident , cx : ecx } ;
46+ let f =
47+ AllocFnFactory { span, ty_span, kind : AllocatorKind :: Global , global : item. ident , cx : ecx } ;
4748
4849 // Generate item statements for the allocator methods.
4950 let stmts = ALLOCATOR_METHODS . iter ( ) . map ( |method| f. allocator_fn ( method) ) . collect ( ) ;
5051
5152 // Generate anonymous constant serving as container for the allocator methods.
52- let const_ty = ecx. ty ( span , TyKind :: Tup ( Vec :: new ( ) ) ) ;
53+ let const_ty = ecx. ty ( ty_span , TyKind :: Tup ( Vec :: new ( ) ) ) ;
5354 let const_body = ecx. expr_block ( ecx. block ( span, stmts) ) ;
5455 let const_item = ecx. item_const ( span, Ident :: new ( kw:: Underscore , span) , const_ty, const_body) ;
5556 let const_item = if is_stmt {
@@ -64,6 +65,7 @@ pub fn expand(
6465
6566struct AllocFnFactory < ' a , ' b > {
6667 span : Span ,
68+ ty_span : Span ,
6769 kind : AllocatorKind ,
6870 global : Ident ,
6971 cx : & ' b ExtCtxt < ' a > ,
@@ -97,18 +99,18 @@ impl AllocFnFactory<'_, '_> {
9799 self . attrs ( ) ,
98100 kind,
99101 ) ;
100- self . cx . stmt_item ( self . span , item)
102+ self . cx . stmt_item ( self . ty_span , item)
101103 }
102104
103105 fn call_allocator ( & self , method : Symbol , mut args : Vec < P < Expr > > ) -> P < Expr > {
104106 let method = self . cx . std_path ( & [ sym:: alloc, sym:: GlobalAlloc , method] ) ;
105- let method = self . cx . expr_path ( self . cx . path ( self . span , method) ) ;
106- let allocator = self . cx . path_ident ( self . span , self . global ) ;
107+ let method = self . cx . expr_path ( self . cx . path ( self . ty_span , method) ) ;
108+ let allocator = self . cx . path_ident ( self . ty_span , self . global ) ;
107109 let allocator = self . cx . expr_path ( allocator) ;
108- let allocator = self . cx . expr_addr_of ( self . span , allocator) ;
110+ let allocator = self . cx . expr_addr_of ( self . ty_span , allocator) ;
109111 args. insert ( 0 , allocator) ;
110112
111- self . cx . expr_call ( self . span , method, args)
113+ self . cx . expr_call ( self . ty_span , method, args)
112114 }
113115
114116 fn attrs ( & self ) -> Vec < Attribute > {
0 commit comments