Skip to content

Commit 82154ad

Browse files
committed
Port #[fundamental] to the new attribute system
1 parent c657f72 commit 82154ad

File tree

9 files changed

+30
-11
lines changed

9 files changed

+30
-11
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
@@ -37,8 +37,8 @@ use crate::attributes::stability::{
3737
};
3838
use crate::attributes::traits::{
3939
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
40-
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
41-
UnsafeSpecializationMarkerParser,
40+
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
41+
TypeConstParser, UnsafeSpecializationMarkerParser,
4242
};
4343
use crate::attributes::transparency::TransparencyParser;
4444
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -147,6 +147,7 @@ attribute_parsers!(
147147
Single<WithoutArgs<ConstTraitParser>>,
148148
Single<WithoutArgs<DenyExplicitImplParser>>,
149149
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
150+
Single<WithoutArgs<FundamentalParser>>,
150151
Single<WithoutArgs<LoopMatchParser>>,
151152
Single<WithoutArgs<MarkerParser>>,
152153
Single<WithoutArgs<MayDangleParser>>,

compiler/rustc_hir_analysis/src/collect.rs

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

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

877877
let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(
878878
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
@@ -300,6 +300,7 @@ fn emit_malformed_attribute(
300300
| sym::rustc_specialization_trait
301301
| sym::rustc_unsafe_specialization_marker
302302
| sym::marker
303+
| sym::fundamental
303304
| sym::type_const
304305
| sym::repr
305306
| 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
}
@@ -352,7 +355,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
352355
| sym::prelude_import
353356
| sym::panic_handler
354357
| sym::allow_internal_unsafe
355-
| sym::fundamental
356358
| sym::lang
357359
| sym::needs_allocator
358360
| sym::default_lib_allocator

tests/ui/attributes/malformed-attrs.stderr

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

131-
error: malformed `fundamental` attribute input
132-
--> $DIR/malformed-attrs.rs:156:1
133-
|
134-
LL | #[fundamental()]
135-
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]`
136-
137131
error: malformed `ffi_pure` attribute input
138132
--> $DIR/malformed-attrs.rs:164:5
139133
|
@@ -546,6 +540,15 @@ LL | #[marker = 3]
546540
| | didn't expect any arguments here
547541
| help: must be of the form: `#[marker]`
548542

543+
error[E0565]: malformed `fundamental` attribute input
544+
--> $DIR/malformed-attrs.rs:156:1
545+
|
546+
LL | #[fundamental()]
547+
| ^^^^^^^^^^^^^--^
548+
| | |
549+
| | didn't expect any arguments here
550+
| help: must be of the form: `#[fundamental]`
551+
549552
error[E0565]: malformed `type_const` attribute input
550553
--> $DIR/malformed-attrs.rs:142:5
551554
|

0 commit comments

Comments
 (0)