Auto merge of #93778 - matthiaskrgr:rollup-yfngdao, r=matthiaskrgr · rust-lang/rust@9a5a961 (original) (raw)
`@@ -26,14 +26,14 @@ pub fn expand(
`
26
26
``
27
27
`` // Allow using #[global_allocator]
on an item statement
``
28
28
`// 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 {
`
30
30
`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)),
`
32
32
` _ => return not_static(),
`
33
33
`},
`
34
34
`Annotatable::Stmt(stmt) => match &stmt.kind {
`
35
35
`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)),
`
37
37
` _ => return not_static(),
`
38
38
`},
`
39
39
` _ => return not_static(),
`
`@@ -43,13 +43,14 @@ pub fn expand(
`
43
43
``
44
44
`// Generate a bunch of new items using the AllocFnFactory
`
45
45
`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 };
`
47
48
``
48
49
`// Generate item statements for the allocator methods.
`
49
50
`let stmts = ALLOCATOR_METHODS.iter().map(|method| f.allocator_fn(method)).collect();
`
50
51
``
51
52
`// 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()));
`
53
54
`let const_body = ecx.expr_block(ecx.block(span, stmts));
`
54
55
`let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body);
`
55
56
`let const_item = if is_stmt {
`
`@@ -64,6 +65,7 @@ pub fn expand(
`
64
65
``
65
66
`struct AllocFnFactory<'a, 'b> {
`
66
67
`span: Span,
`
``
68
`+
ty_span: Span,
`
67
69
`kind: AllocatorKind,
`
68
70
`global: Ident,
`
69
71
`cx: &'b ExtCtxt<'a>,
`
`@@ -97,18 +99,18 @@ impl AllocFnFactory<'_, '_> {
`
97
99
`self.attrs(),
`
98
100
` kind,
`
99
101
`);
`
100
``
`-
self.cx.stmt_item(self.span, item)
`
``
102
`+
self.cx.stmt_item(self.ty_span, item)
`
101
103
`}
`
102
104
``
103
105
`fn call_allocator(&self, method: Symbol, mut args: Vec<P>) -> P {
`
104
106
`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);
`
107
109
`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);
`
109
111
` args.insert(0, allocator);
`
110
112
``
111
``
`-
self.cx.expr_call(self.span, method, args)
`
``
113
`+
self.cx.expr_call(self.ty_span, method, args)
`
112
114
`}
`
113
115
``
114
116
`fn attrs(&self) -> Vec {
`