Port #[rustc_allocator_zeroed] to attr parser

This commit is contained in:
Edvin Bryntesson 2026-01-18 19:47:09 +01:00
parent 9a7614da04
commit 21c9bd7692
No known key found for this signature in database
6 changed files with 21 additions and 5 deletions

View file

@ -10,6 +10,16 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorParser {
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator;
}
pub(crate) struct RustcAllocatorZeroedParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorZeroedParser {
const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed;
}
pub(crate) struct RustcDeallocatorParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser {

View file

@ -65,7 +65,8 @@ use crate::attributes::proc_macro_attrs::{
use crate::attributes::prototype::CustomMirParser;
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
use crate::attributes::rustc_allocator::{
RustcAllocatorParser, RustcDeallocatorParser, RustcReallocatorParser,
RustcAllocatorParser, RustcAllocatorZeroedParser, RustcDeallocatorParser,
RustcReallocatorParser,
};
use crate::attributes::rustc_dump::{
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
@ -277,6 +278,7 @@ attribute_parsers!(
Single<WithoutArgs<ProcMacroParser>>,
Single<WithoutArgs<PubTransparentParser>>,
Single<WithoutArgs<RustcAllocatorParser>>,
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
Single<WithoutArgs<RustcDeallocatorParser>>,
Single<WithoutArgs<RustcDumpDefParents>>,

View file

@ -344,6 +344,9 @@ fn process_builtin_attrs(
AttributeKind::RustcReallocator => {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR
}
AttributeKind::RustcAllocatorZeroed => {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
}
_ => {}
}
}
@ -354,9 +357,6 @@ fn process_builtin_attrs(
match name {
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
sym::rustc_allocator_zeroed => {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
}
sym::patchable_function_entry => {
codegen_fn_attrs.patchable_function_entry =
parse_patchable_function_entry(tcx, attr);

View file

@ -909,6 +909,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_allocator]`
RustcAllocator,
/// Represents `#[rustc_allocator_zeroed]`
RustcAllocatorZeroed,
/// Represents `#[rustc_builtin_macro]`.
RustcBuiltinMacro { builtin_name: Option<Symbol>, helper_attrs: ThinVec<Symbol>, span: Span },

View file

@ -98,6 +98,7 @@ impl AttributeKind {
RecursionLimit { .. } => No,
Repr { .. } => No,
RustcAllocator => No,
RustcAllocatorZeroed => No,
RustcBuiltinMacro { .. } => Yes,
RustcCoherenceIsCore(..) => No,
RustcDeallocator => No,

View file

@ -317,6 +317,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::RustcDumpVtable(..)
| AttributeKind::NeedsAllocator
| AttributeKind::RustcAllocator
| AttributeKind::RustcAllocatorZeroed
| AttributeKind::RustcDeallocator
| AttributeKind::RustcReallocator
) => { /* do nothing */ }
@ -364,7 +365,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::rustc_reservation_impl
| sym::rustc_doc_primitive
| sym::rustc_conversion_suggestion
| sym::rustc_allocator_zeroed
| sym::rustc_allocator_zeroed_variant
| sym::rustc_deprecated_safe_2024
| sym::rustc_test_marker