Skip to content

Commit f769905

Browse files
authored
Rollup merge of #152728 - Ozzy1423:default-lib, r=JonathanBrouwer
Port #![default_lib_allocator] to the new attribute parser Tracking issue: #131229 r? @JonathanBrouwer
2 parents dd27f85 + 8081e86 commit f769905

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNoImplicitBoundsParser {
292292
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
293293
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitBounds;
294294
}
295+
296+
pub(crate) struct DefaultLibAllocatorParser;
297+
298+
impl<S: Stage> NoArgsAttributeParser<S> for DefaultLibAllocatorParser {
299+
const PATH: &[Symbol] = &[sym::default_lib_allocator];
300+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
301+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
302+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::DefaultLibAllocator;
303+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ attribute_parsers!(
235235
Single<WithoutArgs<ConstContinueParser>>,
236236
Single<WithoutArgs<ConstStabilityIndirectParser>>,
237237
Single<WithoutArgs<CoroutineParser>>,
238+
Single<WithoutArgs<DefaultLibAllocatorParser>>,
238239
Single<WithoutArgs<DenyExplicitImplParser>>,
239240
Single<WithoutArgs<DynIncompatibleTraitParser>>,
240241
Single<WithoutArgs<EiiForeignItemParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ pub enum AttributeKind {
897897
/// Represents `#[debugger_visualizer]`.
898898
DebuggerVisualizer(ThinVec<DebugVisualizer>),
899899

900+
/// Represents `#![default_lib_allocator]`
901+
DefaultLibAllocator,
902+
900903
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
901904
Deprecation { deprecation: Deprecation, span: Span },
902905

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl AttributeKind {
3535
CrateType(_) => No,
3636
CustomMir(_, _, _) => Yes,
3737
DebuggerVisualizer(..) => No,
38+
DefaultLibAllocator => No,
3839
Deprecation { .. } => Yes,
3940
DoNotRecommend { .. } => Yes,
4041
Doc(_) => Yes,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
734734
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
735735
has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
736736
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
737-
has_default_lib_allocator: ast::attr::contains_name(
738-
attrs,
739-
sym::default_lib_allocator,
740-
),
737+
has_default_lib_allocator: find_attr!(attrs, AttributeKind::DefaultLibAllocator),
741738
externally_implementable_items,
742739
proc_macro_data,
743740
debugger_visualizers,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
246246
| AttributeKind::CrateName { .. }
247247
| AttributeKind::CrateType(..)
248248
| AttributeKind::DebuggerVisualizer(..)
249+
| AttributeKind::DefaultLibAllocator
249250
// `#[doc]` is actually a lot more than just doc comments, so is checked below
250251
| AttributeKind::DocComment {..}
251252
| AttributeKind::EiiDeclaration { .. }
@@ -399,7 +400,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
399400
| sym::deny
400401
| sym::forbid
401402
// internal
402-
| sym::default_lib_allocator
403403
| sym::rustc_inherit_overflow_checks
404404
| sym::rustc_on_unimplemented
405405
| sym::rustc_doc_primitive

0 commit comments

Comments
 (0)