Skip to content

Commit 34e0dfd

Browse files
committed
Port #[fundamental] to the new attribute system
1 parent 46c5460 commit 34e0dfd

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,15 @@ pub enum AttributeKind {
243243
/// Represents `#[export_stable]`.
244244
ExportStable,
245245

246-
/// Represents `#[ffi_const]`,
246+
/// Represents `#[ffi_const]`.
247247
FfiConst(Span),
248248

249-
/// Represents `#[ffi_pure]`,
249+
/// Represents `#[ffi_pure]`.
250250
FfiPure(Span),
251251

252+
/// Represents `#[fundamental]`.
253+
Fundamental,
254+
252255
/// Represents `#[inline]` and `#[rustc_force_inline]`.
253256
Inline(InlineAttr, Span),
254257

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,13 @@ impl<S: Stage> NoArgsAttributeParser<S> for MarkerParser {
134134
AttributeKind::Marker(span)
135135
}
136136
}
137+
138+
pub(crate) struct FundamentalParser;
139+
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
140+
const PATH: &[Symbol] = &[sym::fundamental];
141+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
142+
143+
fn create(_: Span) -> AttributeKind {
144+
AttributeKind::Fundamental
145+
}
146+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use crate::attributes::stability::{
2929
};
3030
use crate::attributes::traits::{
3131
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
32-
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
33-
UnsafeSpecializationMarkerParser,
32+
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
33+
TypeConstParser, UnsafeSpecializationMarkerParser,
3434
};
3535
use crate::attributes::transparency::TransparencyParser;
3636
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -133,6 +133,7 @@ attribute_parsers!(
133133
Single<WithoutArgs<ExportStableParser>>,
134134
Single<WithoutArgs<FfiConstParser>>,
135135
Single<WithoutArgs<FfiPureParser>>,
136+
Single<WithoutArgs<FundamentalParser>>,
136137
Single<WithoutArgs<MarkerParser>>,
137138
Single<WithoutArgs<MayDangleParser>>,
138139
Single<WithoutArgs<NoMangleParser>>,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
11511151
let is_marker = !is_alias && find_attr!(attrs, AttributeKind::Marker(_));
11521152

11531153
let rustc_coinductive = find_attr!(attrs, AttributeKind::Coinductive(_));
1154-
let is_fundamental = attrs.iter().any(|attr| attr.has_name(sym::fundamental));
1154+
let is_fundamental = find_attr!(attrs, AttributeKind::Fundamental);
11551155

11561156
let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(
11571157
attrs,

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ops::Range;
44
use std::str;
55

66
use rustc_abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
7+
use rustc_attr_data_structures::{AttributeKind, find_attr};
78
use rustc_data_structures::fingerprint::Fingerprint;
89
use rustc_data_structures::fx::FxHashMap;
910
use rustc_data_structures::intern::Interned;
@@ -293,7 +294,7 @@ impl AdtDefData {
293294
flags |= AdtFlags::HAS_CTOR;
294295
}
295296

296-
if tcx.has_attr(did, sym::fundamental) {
297+
if find_attr!(tcx.get_all_attrs(did), AttributeKind::Fundamental) {
297298
flags |= AdtFlags::IS_FUNDAMENTAL;
298299
}
299300
if tcx.is_lang_item(did, LangItem::PhantomData) {

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ fn emit_malformed_attribute(
303303
| sym::rustc_specialization_trait
304304
| sym::rustc_unsafe_specialization_marker
305305
| sym::marker
306+
| sym::fundamental
306307
| sym::type_const
307308
| sym::rustc_pass_by_value
308309
| sym::repr

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
140140
&Attribute::Parsed(AttributeKind::Marker(attr_span)) => {
141141
self.check_marker(hir_id, attr_span, span, target)
142142
}
143+
Attribute::Parsed(AttributeKind::Fundamental) => {
144+
// FIXME: add validation
145+
}
143146
Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => {
144147
self.check_confusables(*first_span, target);
145148
}
@@ -348,7 +351,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
348351
| sym::prelude_import
349352
| sym::panic_handler
350353
| sym::allow_internal_unsafe
351-
| sym::fundamental
352354
| sym::lang
353355
| sym::needs_allocator
354356
| sym::default_lib_allocator

0 commit comments

Comments
 (0)