Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port #[fundamental] to the new attribute system
  • Loading branch information
GrigorenkoPV committed Jul 8, 2025
commit 507ebced1693e4671db3f059caf24d7a4a9c6d28
3 changes: 3 additions & 0 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ pub enum AttributeKind {
/// Represents `#[ffi_pure]`.
FfiPure(Span),

/// Represents `#[fundamental]`.
Fundamental,

/// Represents `#[ignore]`
Ignore {
span: Span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl AttributeKind {
ExportStable => No,
FfiConst(..) => No,
FfiPure(..) => No,
Fundamental { .. } => Yes,
Ignore { .. } => No,
Inline(..) => No,
LinkName { .. } => Yes,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for MarkerParser {
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Marker;
}

pub(crate) struct FundamentalParser;
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
const PATH: &[Symbol] = &[sym::fundamental];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::Fundamental;
}
5 changes: 3 additions & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use crate::attributes::stability::{
use crate::attributes::test_attrs::IgnoreParser;
use crate::attributes::traits::{
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
UnsafeSpecializationMarkerParser,
FundamentalParser, MarkerParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
TypeConstParser, UnsafeSpecializationMarkerParser,
};
use crate::attributes::transparency::TransparencyParser;
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
Expand Down Expand Up @@ -161,6 +161,7 @@ attribute_parsers!(
Single<WithoutArgs<ExportStableParser>>,
Single<WithoutArgs<FfiConstParser>>,
Single<WithoutArgs<FfiPureParser>>,
Single<WithoutArgs<FundamentalParser>>,
Single<WithoutArgs<LoopMatchParser>>,
Single<WithoutArgs<MarkerParser>>,
Single<WithoutArgs<MayDangleParser>>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
let is_marker = !is_alias && find_attr!(attrs, AttributeKind::Marker(_));

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

let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(
attrs,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use rustc_index::{IndexSlice, IndexVec};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::DataTypeKind;
use rustc_span::sym;
use rustc_type_ir::solve::AdtDestructorKind;
use tracing::{debug, info, trace};

Expand Down Expand Up @@ -296,7 +295,7 @@ impl AdtDefData {
flags |= AdtFlags::HAS_CTOR;
}

if tcx.has_attr(did, sym::fundamental) {
if find_attr!(tcx.get_all_attrs(did), AttributeKind::Fundamental) {
flags |= AdtFlags::IS_FUNDAMENTAL;
}
if tcx.is_lang_item(did, LangItem::PhantomData) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ pub fn check_builtin_meta_item(
| sym::rustc_specialization_trait
| sym::rustc_unsafe_specialization_marker
| sym::marker
| sym::fundamental
| sym::type_const
| sym::repr
| sym::align
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&Attribute::Parsed(AttributeKind::Marker(attr_span)) => {
self.check_marker(hir_id, attr_span, span, target)
}
Attribute::Parsed(AttributeKind::Fundamental) => {
// FIXME: add validation
}
Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => {
self.check_confusables(*first_span, target);
}
Expand Down Expand Up @@ -374,7 +377,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::prelude_import
| sym::panic_handler
| sym::allow_internal_unsafe
| sym::fundamental
| sym::lang
| sym::needs_allocator
| sym::default_lib_allocator
Expand Down
15 changes: 9 additions & 6 deletions tests/ui/attributes/malformed-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ error: malformed `cfi_encoding` attribute input
LL | #[cfi_encoding]
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[cfi_encoding = "encoding"]`

error: malformed `fundamental` attribute input
--> $DIR/malformed-attrs.rs:157:1
|
LL | #[fundamental()]
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]`

error: malformed `link_ordinal` attribute input
--> $DIR/malformed-attrs.rs:167:5
|
Expand Down Expand Up @@ -525,6 +519,15 @@ LL | #[marker = 3]
| | didn't expect any arguments here
| help: must be of the form: `#[marker]`

error[E0565]: malformed `fundamental` attribute input
--> $DIR/malformed-attrs.rs:157:1
|
LL | #[fundamental()]
| ^^^^^^^^^^^^^--^
| | |
| | didn't expect any arguments here
| help: must be of the form: `#[fundamental]`

error[E0565]: malformed `ffi_pure` attribute input
--> $DIR/malformed-attrs.rs:165:5
|
Expand Down