We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
#[rustc_allocator_zeroed_variant]
1 parent 21c9bd7 commit 9a931e8Copy full SHA for 9a931e8
6 files changed
compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs
@@ -20,6 +20,25 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorZeroedParser {
20
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed;
21
}
22
23
+pub(crate) struct RustcAllocatorZeroedVariantParser;
24
+
25
+impl<S: Stage> SingleAttributeParser<S> for RustcAllocatorZeroedVariantParser {
26
+ const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed_variant];
27
+ const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
28
+ const ALLOWED_TARGETS: AllowedTargets =
29
+ AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
30
+ const TEMPLATE: AttributeTemplate = template!(NameValueStr: "function");
31
+ const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
32
+ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
33
+ let Some(name) = args.name_value().and_then(NameValueParser::value_as_str) else {
34
+ cx.expected_name_value(cx.attr_span, None);
35
+ return None;
36
+ };
37
38
+ Some(AttributeKind::RustcAllocatorZeroedVariant { name })
39
+ }
40
+}
41
42
pub(crate) struct RustcDeallocatorParser;
43
44
impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser {
compiler/rustc_attr_parsing/src/context.rs
@@ -65,8 +65,8 @@ use crate::attributes::proc_macro_attrs::{
65
use crate::attributes::prototype::CustomMirParser;
66
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
67
use crate::attributes::rustc_allocator::{
68
- RustcAllocatorParser, RustcAllocatorZeroedParser, RustcDeallocatorParser,
69
- RustcReallocatorParser,
+ RustcAllocatorParser, RustcAllocatorZeroedParser, RustcAllocatorZeroedVariantParser,
+ RustcDeallocatorParser, RustcReallocatorParser,
70
};
71
use crate::attributes::rustc_dump::{
72
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
@@ -227,6 +227,7 @@ attribute_parsers!(
227
Single<PatternComplexityLimitParser>,
228
Single<ProcMacroDeriveParser>,
229
Single<RecursionLimitParser>,
230
+ Single<RustcAllocatorZeroedVariantParser>,
231
Single<RustcBuiltinMacroParser>,
232
Single<RustcForceInlineParser>,
233
Single<RustcLayoutScalarValidRangeEndParser>,
compiler/rustc_codegen_llvm/src/attributes.rs
@@ -1,6 +1,7 @@
1
//! Set and unset common attributes on LLVM values.
2
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr, RtsanSetting};
3
use rustc_hir::def_id::DefId;
4
+use rustc_hir::find_attr;
5
use rustc_middle::middle::codegen_fn_attrs::{
6
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
7
@@ -470,9 +471,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
470
471
{
472
to_add.push(create_alloc_family_attr(cx.llcx));
473
if let Some(instance) = instance
- && let Some(zv) =
474
- tcx.get_attr(instance.def_id(), rustc_span::sym::rustc_allocator_zeroed_variant)
475
- && let Some(name) = zv.value_str()
+ && let Some(name) = find_attr!(tcx.get_all_attrs(instance.def_id()), rustc_hir::attrs::AttributeKind::RustcAllocatorZeroedVariant {name} => name)
476
477
to_add.push(llvm::CreateAttrStringValue(
478
cx.llcx,
compiler/rustc_hir/src/attrs/data_structures.rs
@@ -912,6 +912,9 @@ pub enum AttributeKind {
912
/// Represents `#[rustc_allocator_zeroed]`
913
RustcAllocatorZeroed,
914
915
+ /// Represents `#[rustc_allocator_zeroed_variant]`
916
+ RustcAllocatorZeroedVariant { name: Symbol },
917
918
/// Represents `#[rustc_builtin_macro]`.
919
RustcBuiltinMacro { builtin_name: Option<Symbol>, helper_attrs: ThinVec<Symbol>, span: Span },
920
compiler/rustc_hir/src/attrs/encode_cross_crate.rs
@@ -99,6 +99,7 @@ impl AttributeKind {
99
Repr { .. } => No,
100
RustcAllocator => No,
101
RustcAllocatorZeroed => No,
102
+ RustcAllocatorZeroedVariant { .. } => Yes,
103
RustcBuiltinMacro { .. } => Yes,
104
RustcCoherenceIsCore(..) => No,
105
RustcDeallocator => No,
compiler/rustc_passes/src/check_attr.rs
@@ -318,6 +318,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
318
| AttributeKind::NeedsAllocator
319
| AttributeKind::RustcAllocator
320
| AttributeKind::RustcAllocatorZeroed
321
+ | AttributeKind::RustcAllocatorZeroedVariant { .. }
322
| AttributeKind::RustcDeallocator
323
| AttributeKind::RustcReallocator
324
) => { /* do nothing */ }
@@ -365,7 +366,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
365
366
| sym::rustc_reservation_impl
367
| sym::rustc_doc_primitive
368
| sym::rustc_conversion_suggestion
- | sym::rustc_allocator_zeroed_variant
369
| sym::rustc_deprecated_safe_2024
370
| sym::rustc_test_marker
371
| sym::rustc_abi
0 commit comments