|
1 | 1 | use rustc_ast::ast; |
2 | 2 | use rustc_ast::token::{Delimiter, IdentKind, Token, TokenKind}; |
3 | 3 | use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree}; |
| 4 | +use rustc_ast::{DUMMY_NODE_ID, ast}; |
4 | 5 | use rustc_expand::base::{Annotatable, ExtCtxt}; |
5 | 6 | use rustc_session::config::Offload; |
6 | 7 | use rustc_span::{DUMMY_SP, Ident, Span, sym}; |
@@ -179,14 +180,24 @@ pub(crate) fn expand_kernel( |
179 | 180 | let new_id = ecx.sess.psess.attr_id_generator.mk_attr_id(); |
180 | 181 | let inline_never = outer_normal_attr(&inline_never_attr, new_id, span); |
181 | 182 |
|
182 | | - let host_item = { |
183 | | - let mut item = ecx.item( |
184 | | - span, |
185 | | - thin_vec![rustc_offload_kernel, inline_never], |
186 | | - ast::ItemKind::Fn(host_fn), |
187 | | - ); |
188 | | - item.vis = vis; |
189 | | - Annotatable::Item(item) |
| 183 | + let mut host_item_ecx = |
| 184 | + ecx.item(span, thin_vec![rustc_offload_kernel, inline_never], ast::ItemKind::Fn(host_fn)); |
| 185 | + let host_item = match &item { |
| 186 | + Annotatable::Item(_) => { |
| 187 | + host_item_ecx.vis = vis; |
| 188 | + Annotatable::Item(host_item_ecx) |
| 189 | + } |
| 190 | + Annotatable::Stmt(_) => { |
| 191 | + host_item_ecx.vis = vis; |
| 192 | + Annotatable::Stmt(Box::new(ast::Stmt { |
| 193 | + id: DUMMY_NODE_ID, |
| 194 | + kind: ast::StmtKind::Item(host_item_ecx), |
| 195 | + span, |
| 196 | + })) |
| 197 | + } |
| 198 | + _ => { |
| 199 | + unreachable!("item kind checked previously") |
| 200 | + } |
190 | 201 | }; |
191 | 202 |
|
192 | 203 | if compile_for_device(ecx) { vec![device_item] } else { vec![host_item] } |
|
0 commit comments