Skip to content

Commit 507ebce

Browse files
committed
Port #[fundamental] to the new attribute system
1 parent 12f6487 commit 507ebce

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
@@ -272,6 +272,9 @@ pub enum AttributeKind {
272272
/// Represents `#[ffi_pure]`.
273273
FfiPure(Span),
274274

275+
/// Represents `#[fundamental]`.
276+
Fundamental,
277+
275278
/// Represents `#[ignore]`
276279
Ignore {
277280
span: Span,

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl AttributeKind {
3434
ExportStable => No,
3535
FfiConst(..) => No,
3636
FfiPure(..) => No,
37+
Fundamental { .. } => Yes,
3738
Ignore { .. } => No,
3839
Inline(..) => No,
3940
LinkName { .. } => Yes,

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
@@ -45,8 +45,8 @@ use crate::attributes::stability::{
4545
use crate::attributes::test_attrs::IgnoreParser;
4646
use crate::attributes::traits::{
4747
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
48-
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
49-
UnsafeSpecializationMarkerParser,
48+
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
49+
TypeConstParser, UnsafeSpecializationMarkerParser,
5050
};
5151
use crate::attributes::transparency::TransparencyParser;
5252
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -161,6 +161,7 @@ attribute_parsers!(
161161
Single<WithoutArgs<ExportStableParser>>,
162162
Single<WithoutArgs<FfiConstParser>>,
163163
Single<WithoutArgs<FfiPureParser>>,
164+
Single<WithoutArgs<FundamentalParser>>,
164165
Single<WithoutArgs<LoopMatchParser>>,
165166
Single<WithoutArgs<MarkerParser>>,
166167
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
@@ -290,6 +290,7 @@ pub fn check_builtin_meta_item(
290290
| sym::rustc_specialization_trait
291291
| sym::rustc_unsafe_specialization_marker
292292
| sym::marker
293+
| sym::fundamental
293294
| sym::type_const
294295
| sym::repr
295296
| 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
}
@@ -374,7 +377,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
374377
| sym::prelude_import
375378
| sym::panic_handler
376379
| sym::allow_internal_unsafe
377-
| sym::fundamental
378380
| sym::lang
379381
| sym::needs_allocator
380382
| sym::default_lib_allocator

tests/ui/attributes/malformed-attrs.stderr

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

119-
error: malformed `fundamental` attribute input
120-
--> $DIR/malformed-attrs.rs:157:1
121-
|
122-
LL | #[fundamental()]
123-
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]`
124-
125119
error: malformed `link_ordinal` attribute input
126120
--> $DIR/malformed-attrs.rs:167:5
127121
|
@@ -525,6 +519,15 @@ LL | #[marker = 3]
525519
| | didn't expect any arguments here
526520
| help: must be of the form: `#[marker]`
527521

522+
error[E0565]: malformed `fundamental` attribute input
523+
--> $DIR/malformed-attrs.rs:157:1
524+
|
525+
LL | #[fundamental()]
526+
| ^^^^^^^^^^^^^--^
527+
| | |
528+
| | didn't expect any arguments here
529+
| help: must be of the form: `#[fundamental]`
530+
528531
error[E0565]: malformed `ffi_pure` attribute input
529532
--> $DIR/malformed-attrs.rs:165:5
530533
|

0 commit comments

Comments
 (0)