Skip to content

Commit 21c9bd7

Browse files
committed
Port #[rustc_allocator_zeroed] to attr parser
1 parent 9a7614d commit 21c9bd7

6 files changed

Lines changed: 21 additions & 5 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorParser {
1010
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator;
1111
}
1212

13+
pub(crate) struct RustcAllocatorZeroedParser;
14+
15+
impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorZeroedParser {
16+
const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed];
17+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
18+
const ALLOWED_TARGETS: AllowedTargets =
19+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
20+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed;
21+
}
22+
1323
pub(crate) struct RustcDeallocatorParser;
1424

1525
impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ use crate::attributes::proc_macro_attrs::{
6565
use crate::attributes::prototype::CustomMirParser;
6666
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6767
use crate::attributes::rustc_allocator::{
68-
RustcAllocatorParser, RustcDeallocatorParser, RustcReallocatorParser,
68+
RustcAllocatorParser, RustcAllocatorZeroedParser, RustcDeallocatorParser,
69+
RustcReallocatorParser,
6970
};
7071
use crate::attributes::rustc_dump::{
7172
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
@@ -277,6 +278,7 @@ attribute_parsers!(
277278
Single<WithoutArgs<ProcMacroParser>>,
278279
Single<WithoutArgs<PubTransparentParser>>,
279280
Single<WithoutArgs<RustcAllocatorParser>>,
281+
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
280282
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
281283
Single<WithoutArgs<RustcDeallocatorParser>>,
282284
Single<WithoutArgs<RustcDumpDefParents>>,

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ fn process_builtin_attrs(
344344
AttributeKind::RustcReallocator => {
345345
codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR
346346
}
347+
AttributeKind::RustcAllocatorZeroed => {
348+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
349+
}
347350
_ => {}
348351
}
349352
}
@@ -354,9 +357,6 @@ fn process_builtin_attrs(
354357

355358
match name {
356359
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
357-
sym::rustc_allocator_zeroed => {
358-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
359-
}
360360
sym::patchable_function_entry => {
361361
codegen_fn_attrs.patchable_function_entry =
362362
parse_patchable_function_entry(tcx, attr);

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ pub enum AttributeKind {
909909
/// Represents `#[rustc_allocator]`
910910
RustcAllocator,
911911

912+
/// Represents `#[rustc_allocator_zeroed]`
913+
RustcAllocatorZeroed,
914+
912915
/// Represents `#[rustc_builtin_macro]`.
913916
RustcBuiltinMacro { builtin_name: Option<Symbol>, helper_attrs: ThinVec<Symbol>, span: Span },
914917

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl AttributeKind {
9898
RecursionLimit { .. } => No,
9999
Repr { .. } => No,
100100
RustcAllocator => No,
101+
RustcAllocatorZeroed => No,
101102
RustcBuiltinMacro { .. } => Yes,
102103
RustcCoherenceIsCore(..) => No,
103104
RustcDeallocator => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
317317
| AttributeKind::RustcDumpVtable(..)
318318
| AttributeKind::NeedsAllocator
319319
| AttributeKind::RustcAllocator
320+
| AttributeKind::RustcAllocatorZeroed
320321
| AttributeKind::RustcDeallocator
321322
| AttributeKind::RustcReallocator
322323
) => { /* do nothing */ }
@@ -364,7 +365,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
364365
| sym::rustc_reservation_impl
365366
| sym::rustc_doc_primitive
366367
| sym::rustc_conversion_suggestion
367-
| sym::rustc_allocator_zeroed
368368
| sym::rustc_allocator_zeroed_variant
369369
| sym::rustc_deprecated_safe_2024
370370
| sym::rustc_test_marker

0 commit comments

Comments
 (0)