Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb8b741
Port `#[export_stable]` to the new attribute system
GrigorenkoPV Jun 16, 2025
99a9fe1
Port `#[ffi_const]` to the new attribute system
GrigorenkoPV Jun 23, 2025
5d7771e
Port `#[ffi_pure]` to the new attribute system
GrigorenkoPV Jun 23, 2025
4f0b0b0
Port `#[rustc_std_internal_symbol]` to the new attribute system
GrigorenkoPV Jul 4, 2025
429deed
Port #[rustc_dummy]
mejrs Jul 7, 2025
7ec8c89
Update intro blurb in `wasm32-wasip1` docs
alexcrichton Jul 7, 2025
6254afa
Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrde…
Periodic1911 Jul 7, 2025
e2891c0
configure.py: Write last key in each section
lambdageek Jul 7, 2025
b6d2130
Add docstring
lambdageek Jul 7, 2025
62951c2
fix: Remove newline from multiple crate versions note
Muscraft Jul 8, 2025
a58a423
Add target maintainer information for mips64-unknown-linux-muslabi64
Gelbpunkt Jul 8, 2025
7170412
Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.
obi1kenobi Jul 7, 2025
3ba8e33
Rewrite for clarity
lambdageek Jul 8, 2025
35d7856
Rollup merge of #143402 - GrigorenkoPV:attributes/link_attrs, r=jdons…
matthiaskrgr Jul 8, 2025
fd12db7
Rollup merge of #143555 - obi1kenobi:pg/target-feature-not-unsafe-rus…
matthiaskrgr Jul 8, 2025
083c0d8
Rollup merge of #143593 - mejrs:dummy, r=jdonszelmann
matthiaskrgr Jul 8, 2025
cb288e3
Rollup merge of #143600 - alexcrichton:wasm32-wasip1-doc-reword, r=ji…
matthiaskrgr Jul 8, 2025
9b51f63
Rollup merge of #143603 - Periodic1911:clarify_keepfistlast, r=compil…
matthiaskrgr Jul 8, 2025
448ca15
Rollup merge of #143606 - lambdageek:configure-write-last-key, r=Kobzol
matthiaskrgr Jul 8, 2025
38117b1
Rollup merge of #143620 - Muscraft:remove-newline, r=compiler-errors
matthiaskrgr Jul 8, 2025
cd41710
Rollup merge of #143622 - Gelbpunkt:mips64-unknown-linux-muslabi64-ta…
matthiaskrgr Jul 8, 2025
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 #[ffi_const] to the new attribute system
  • Loading branch information
GrigorenkoPV committed Jul 7, 2025
commit 99a9fe1b22edd82697a315e67392bfb35690152d
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 @@ -251,6 +251,9 @@ pub enum AttributeKind {
/// Represents `#[export_stable]`.
ExportStable,

/// Represents `#[ffi_const]`.
FfiConst(Span),

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

pub(crate) struct FfiConstParser;
impl<S: Stage> NoArgsAttributeParser<S> for FfiConstParser {
const PATH: &[Symbol] = &[sym::ffi_const];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiConst;
}
5 changes: 4 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use crate::attributes::codegen_attrs::{
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::deprecation::DeprecationParser;
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
use crate::attributes::link_attrs::{ExportStableParser, LinkNameParser, LinkSectionParser};
use crate::attributes::link_attrs::{
ExportStableParser, FfiConstParser, LinkNameParser, LinkSectionParser,
};
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
use crate::attributes::must_use::MustUseParser;
Expand Down Expand Up @@ -146,6 +148,7 @@ attribute_parsers!(
Single<WithoutArgs<ConstContinueParser>>,
Single<WithoutArgs<ConstStabilityIndirectParser>>,
Single<WithoutArgs<ExportStableParser>>,
Single<WithoutArgs<FfiConstParser>>,
Single<WithoutArgs<LoopMatchParser>>,
Single<WithoutArgs<MayDangleParser>>,
Single<WithoutArgs<NoImplicitPreludeParser>>,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
},
AttributeKind::FfiConst(_) => {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
}
_ => {}
}
}
Expand All @@ -214,7 +217,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
match name {
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
sym::ffi_const => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST,
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,
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 @@ -272,6 +272,7 @@ pub fn check_builtin_meta_item(
name,
sym::inline
| sym::export_stable
| sym::ffi_const
| sym::may_dangle
| sym::rustc_as_ptr
| sym::rustc_pub_transparent
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Attribute::Parsed(AttributeKind::ExportStable) => {
// handled in `check_export`
}
&Attribute::Parsed(AttributeKind::FfiConst(attr_span)) => {
self.check_ffi_const(attr_span, target)
}
Attribute::Parsed(
AttributeKind::BodyStability { .. }
| AttributeKind::ConstStabilityIndirect
Expand Down Expand Up @@ -304,7 +307,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_has_incoherent_inherent_impls(attr, span, target)
}
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target),
[sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target),
[sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target),
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
Expand Down Expand Up @@ -1509,7 +1511,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.dcx().emit_err(errors::FfiPureInvalidTarget { attr_span });
return;
}
if attrs.iter().any(|a| a.has_name(sym::ffi_const)) {
if find_attr!(attrs, AttributeKind::FfiConst(_)) {
// `#[ffi_const]` functions cannot be `#[ffi_pure]`
self.dcx().emit_err(errors::BothFfiConstAndPure { attr_span });
}
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 @@ -146,12 +146,6 @@ error: malformed `link_ordinal` attribute input
LL | #[link_ordinal]
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[link_ordinal(ordinal)]`

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

error: malformed `linkage` attribute input
--> $DIR/malformed-attrs.rs:173:5
|
Expand Down Expand Up @@ -540,6 +534,15 @@ LL | #[rustc_layout_scalar_valid_range_end]
| expected this to be a list
| help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]`

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

error[E0565]: malformed `non_exhaustive` attribute input
--> $DIR/malformed-attrs.rs:197:1
|
Expand Down