Skip to content

Commit 5175f38

Browse files
committed
Port #[fundamental] to the new attribute system
1 parent 48958e5 commit 5175f38

File tree

9 files changed

+29
-12
lines changed

9 files changed

+29
-12
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ pub enum AttributeKind {
262262
span: Span,
263263
},
264264

265+
/// Represents `#[fundamental]`.
266+
Fundamental,
267+
265268
/// Represents `#[inline]` and `#[rustc_force_inline]`.
266269
Inline(InlineAttr, Span),
267270

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl AttributeKind {
3030
DoNotImplementViaObject(..) => No,
3131
DocComment { .. } => Yes,
3232
ExportName { .. } => Yes,
33+
Fundamental { .. } => Yes,
3334
Inline(..) => No,
3435
LinkName { .. } => Yes,
3536
LinkSection { .. } => No,

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for MarkerParser {
110110
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
111111
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Marker;
112112
}
113+
114+
pub(crate) struct FundamentalParser;
115+
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
116+
const PATH: &[Symbol] = &[sym::fundamental];
117+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
118+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::Fundamental;
119+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use crate::attributes::stability::{
3939
};
4040
use crate::attributes::traits::{
4141
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
42-
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
43-
UnsafeSpecializationMarkerParser,
42+
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
43+
TypeConstParser, UnsafeSpecializationMarkerParser,
4444
};
4545
use crate::attributes::transparency::TransparencyParser;
4646
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -149,6 +149,7 @@ attribute_parsers!(
149149
Single<WithoutArgs<ConstTraitParser>>,
150150
Single<WithoutArgs<DenyExplicitImplParser>>,
151151
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
152+
Single<WithoutArgs<FundamentalParser>>,
152153
Single<WithoutArgs<LoopMatchParser>>,
153154
Single<WithoutArgs<MarkerParser>>,
154155
Single<WithoutArgs<MayDangleParser>>,

compiler/rustc_hir_analysis/src/collect.rs

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

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

874874
let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(
875875
attrs,

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_index::{IndexSlice, IndexVec};
1717
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1818
use rustc_query_system::ich::StableHashingContext;
1919
use rustc_session::DataTypeKind;
20-
use rustc_span::sym;
2120
use rustc_type_ir::solve::AdtDestructorKind;
2221
use tracing::{debug, info, trace};
2322

@@ -296,7 +295,7 @@ impl AdtDefData {
296295
flags |= AdtFlags::HAS_CTOR;
297296
}
298297

299-
if tcx.has_attr(did, sym::fundamental) {
298+
if find_attr!(tcx.get_all_attrs(did), AttributeKind::Fundamental) {
300299
flags |= AdtFlags::IS_FUNDAMENTAL;
301300
}
302301
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
@@ -301,6 +301,7 @@ fn emit_malformed_attribute(
301301
| sym::rustc_specialization_trait
302302
| sym::rustc_unsafe_specialization_marker
303303
| sym::marker
304+
| sym::fundamental
304305
| sym::type_const
305306
| sym::repr
306307
| sym::align

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
142142
&Attribute::Parsed(AttributeKind::Marker(attr_span)) => {
143143
self.check_marker(hir_id, attr_span, span, target)
144144
}
145+
Attribute::Parsed(AttributeKind::Fundamental) => {
146+
// FIXME: add validation
147+
}
145148
Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => {
146149
self.check_confusables(*first_span, target);
147150
}
@@ -361,7 +364,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
361364
| sym::prelude_import
362365
| sym::panic_handler
363366
| sym::allow_internal_unsafe
364-
| sym::fundamental
365367
| sym::lang
366368
| sym::needs_allocator
367369
| sym::default_lib_allocator

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ error: malformed `cfi_encoding` attribute input
122122
LL | #[cfi_encoding]
123123
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[cfi_encoding = "encoding"]`
124124

125-
error: malformed `fundamental` attribute input
126-
--> $DIR/malformed-attrs.rs:156:1
127-
|
128-
LL | #[fundamental()]
129-
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]`
130-
131125
error: malformed `ffi_pure` attribute input
132126
--> $DIR/malformed-attrs.rs:164:5
133127
|
@@ -543,6 +537,15 @@ LL | #[marker = 3]
543537
| | didn't expect any arguments here
544538
| help: must be of the form: `#[marker]`
545539

540+
error[E0565]: malformed `fundamental` attribute input
541+
--> $DIR/malformed-attrs.rs:156:1
542+
|
543+
LL | #[fundamental()]
544+
| ^^^^^^^^^^^^^--^
545+
| | |
546+
| | didn't expect any arguments here
547+
| help: must be of the form: `#[fundamental]`
548+
546549
error[E0565]: malformed `non_exhaustive` attribute input
547550
--> $DIR/malformed-attrs.rs:196:1
548551
|

0 commit comments

Comments
 (0)