Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_builtin_macros/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,8 @@ builtin_macros_unexpected_lit = expected path to a trait, found literal
.other = for example, write `#[derive(Debug)]` for `Debug`
builtin_macros_unnameable_test_items = cannot test inner items
builtin_macros_global_allocator_thread_local_conflict =
`#[global_allocator]` cannot be used with `#[thread_local]` on the same static
.note = The global allocator must be a single, program-wide instance.
.help = Remove either the `#[global_allocator]` or `#[thread_local]` attribute.
7 changes: 7 additions & 0 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ pub(crate) struct AllocMustStatics {
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_global_allocator_thread_local_conflict)]
pub(crate) struct GlobalAllocatorThreadLocalConflict {
#[primary_span]
pub(crate) span: Span,
}

pub(crate) use autodiff::*;

mod autodiff {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_builtin_macros/src/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ pub(crate) fn expand(
ecx.dcx().emit_err(errors::AllocMustStatics { span: item.span() });
return vec![orig_item];
};

if item.attrs.iter().any(|a| a.path().is_ident(sym::thread_local)) {
ecx.dcx().emit_err(errors::GlobalAllocatorThreadLocalConflict {
span: item.span,
});
return vec![orig_item];
}
// Generate a bunch of new items using the AllocFnFactory
let span = ecx.with_def_site_ctxt(item.span);
let f = AllocFnFactory { span, ty_span, global: ident, cx: ecx };
Expand Down
Loading