Skip to content

Commit 7e4dca6

Browse files
committed
fix: correct annotation type when generating inner function
1 parent 6dd7e1e commit 7e4dca6

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎compiler/rustc_builtin_macros/src/offload.rs‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_ast::ast;
22
use rustc_ast::token::{Delimiter, IdentKind, Token, TokenKind};
33
use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
4+
use rustc_ast::{DUMMY_NODE_ID, ast};
45
use rustc_expand::base::{Annotatable, ExtCtxt};
56
use rustc_session::config::Offload;
67
use rustc_span::{DUMMY_SP, Ident, Span, sym};
@@ -179,14 +180,24 @@ pub(crate) fn expand_kernel(
179180
let new_id = ecx.sess.psess.attr_id_generator.mk_attr_id();
180181
let inline_never = outer_normal_attr(&inline_never_attr, new_id, span);
181182

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+
}
190201
};
191202

192203
if compile_for_device(ecx) { vec![device_item] } else { vec![host_item] }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ check-pass
2+
#![feature(gpu_offload)]
3+
4+
fn kernel() {
5+
#[core::offload::offload_kernel]
6+
fn inner_kernel() {}
7+
}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)