Skip to content

Commit 3854e16

Browse files
committed
proc_macro_harness: adjust the span we use for const fn calls
1 parent a0215d8 commit 3854e16

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,23 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
313313
match m {
314314
ProcMacro::Derive(cd) => {
315315
cx.resolver.declare_proc_macro(cd.id);
316-
cx.expr_call(span, proc_macro_ty_method_path(cx, custom_derive), thin_vec![
317-
cx.expr_str(span, cd.trait_name),
318-
cx.expr_array_ref(
319-
span,
320-
cd.attrs.iter().map(|&s| cx.expr_str(span, s)).collect::<ThinVec<_>>(),
321-
),
322-
local_path(cx, cd.function_name),
323-
])
316+
// The call needs to use `harness_span` so that the const stability checker
317+
// accepts it.
318+
cx.expr_call(
319+
harness_span,
320+
proc_macro_ty_method_path(cx, custom_derive),
321+
thin_vec![
322+
cx.expr_str(span, cd.trait_name),
323+
cx.expr_array_ref(
324+
span,
325+
cd.attrs
326+
.iter()
327+
.map(|&s| cx.expr_str(span, s))
328+
.collect::<ThinVec<_>>(),
329+
),
330+
local_path(cx, cd.function_name),
331+
],
332+
)
324333
}
325334
ProcMacro::Attr(ca) | ProcMacro::Bang(ca) => {
326335
cx.resolver.declare_proc_macro(ca.id);
@@ -330,7 +339,9 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
330339
ProcMacro::Derive(_) => unreachable!(),
331340
};
332341

333-
cx.expr_call(span, proc_macro_ty_method_path(cx, ident), thin_vec![
342+
// The call needs to use `harness_span` so that the const stability checker
343+
// accepts it.
344+
cx.expr_call(harness_span, proc_macro_ty_method_path(cx, ident), thin_vec![
334345
cx.expr_str(span, ca.function_name.name),
335346
local_path(cx, ca.function_name),
336347
])

0 commit comments

Comments
 (0)