Skip to content

Commit 57f6f1e

Browse files
committed
Port #[fundamental] to the new attribute system
1 parent a71fc8e commit 57f6f1e

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
@@ -38,8 +38,8 @@ use crate::attributes::stability::{
3838
};
3939
use crate::attributes::traits::{
4040
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
41-
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
42-
UnsafeSpecializationMarkerParser,
41+
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
42+
TypeConstParser, UnsafeSpecializationMarkerParser,
4343
};
4444
use crate::attributes::transparency::TransparencyParser;
4545
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -148,6 +148,7 @@ attribute_parsers!(
148148
Single<WithoutArgs<ConstTraitParser>>,
149149
Single<WithoutArgs<DenyExplicitImplParser>>,
150150
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
151+
Single<WithoutArgs<FundamentalParser>>,
151152
Single<WithoutArgs<LoopMatchParser>>,
152153
Single<WithoutArgs<MarkerParser>>,
153154
Single<WithoutArgs<MayDangleParser>>,

compiler/rustc_hir_analysis/src/collect.rs

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

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

878878
let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(
879879
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
@@ -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
}
@@ -359,7 +362,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
359362
| sym::prelude_import
360363
| sym::panic_handler
361364
| sym::allow_internal_unsafe
362-
| sym::fundamental
363365
| sym::lang
364366
| sym::needs_allocator
365367
| 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
|
@@ -549,6 +543,15 @@ LL | #[marker = 3]
549543
| | didn't expect any arguments here
550544
| help: must be of the form: `#[marker]`
551545

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

0 commit comments

Comments
 (0)