Skip to content

Commit 5d7771e

Browse files
committed
Port #[ffi_pure] to the new attribute system
1 parent 99a9fe1 commit 5d7771e

File tree

8 files changed

+27
-9
lines changed

8 files changed

+27
-9
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ pub enum AttributeKind {
254254
/// Represents `#[ffi_const]`.
255255
FfiConst(Span),
256256

257+
/// Represents `#[ffi_pure]`.
258+
FfiPure(Span),
259+
257260
/// Represents `#[ignore]`
258261
Ignore {
259262
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
@@ -28,6 +28,7 @@ impl AttributeKind {
2828
ExportName { .. } => Yes,
2929
ExportStable => No,
3030
FfiConst(..) => No,
31+
FfiPure(..) => No,
3132
Ignore { .. } => No,
3233
Inline(..) => No,
3334
LinkName { .. } => Yes,

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for FfiConstParser {
7373
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
7474
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiConst;
7575
}
76+
77+
pub(crate) struct FfiPureParser;
78+
impl<S: Stage> NoArgsAttributeParser<S> for FfiPureParser {
79+
const PATH: &[Symbol] = &[sym::ffi_pure];
80+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
81+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiPure;
82+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2525
use crate::attributes::link_attrs::{
26-
ExportStableParser, FfiConstParser, LinkNameParser, LinkSectionParser,
26+
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkSectionParser,
2727
};
2828
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
2929
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
@@ -149,6 +149,7 @@ attribute_parsers!(
149149
Single<WithoutArgs<ConstStabilityIndirectParser>>,
150150
Single<WithoutArgs<ExportStableParser>>,
151151
Single<WithoutArgs<FfiConstParser>>,
152+
Single<WithoutArgs<FfiPureParser>>,
152153
Single<WithoutArgs<LoopMatchParser>>,
153154
Single<WithoutArgs<MayDangleParser>>,
154155
Single<WithoutArgs<NoImplicitPreludeParser>>,

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
206206
AttributeKind::FfiConst(_) => {
207207
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
208208
}
209+
AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
209210
_ => {}
210211
}
211212
}
@@ -216,7 +217,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
216217

217218
match name {
218219
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
219-
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
220220
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
221221
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
222222
sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub fn check_builtin_meta_item(
273273
sym::inline
274274
| sym::export_stable
275275
| sym::ffi_const
276+
| sym::ffi_pure
276277
| sym::may_dangle
277278
| sym::rustc_as_ptr
278279
| sym::rustc_pub_transparent

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
210210
&Attribute::Parsed(AttributeKind::FfiConst(attr_span)) => {
211211
self.check_ffi_const(attr_span, target)
212212
}
213+
&Attribute::Parsed(AttributeKind::FfiPure(attr_span)) => {
214+
self.check_ffi_pure(attr_span, attrs, target)
215+
}
213216
Attribute::Parsed(
214217
AttributeKind::BodyStability { .. }
215218
| AttributeKind::ConstStabilityIndirect
@@ -306,7 +309,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
306309
[sym::rustc_has_incoherent_inherent_impls, ..] => {
307310
self.check_has_incoherent_inherent_impls(attr, span, target)
308311
}
309-
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target),
310312
[sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target),
311313
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
312314
[sym::macro_use, ..] | [sym::macro_escape, ..] => {

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ error: malformed `fundamental` attribute input
134134
LL | #[fundamental()]
135135
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]`
136136

137-
error: malformed `ffi_pure` attribute input
138-
--> $DIR/malformed-attrs.rs:165:5
139-
|
140-
LL | #[unsafe(ffi_pure = 1)]
141-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[ffi_pure]`
142-
143137
error: malformed `link_ordinal` attribute input
144138
--> $DIR/malformed-attrs.rs:167:5
145139
|
@@ -534,6 +528,15 @@ LL | #[rustc_layout_scalar_valid_range_end]
534528
| expected this to be a list
535529
| help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]`
536530

531+
error[E0565]: malformed `ffi_pure` attribute input
532+
--> $DIR/malformed-attrs.rs:165:5
533+
|
534+
LL | #[unsafe(ffi_pure = 1)]
535+
| ^^^^^^^^^^^^^^^^^^---^^
536+
| | |
537+
| | didn't expect any arguments here
538+
| help: must be of the form: `#[ffi_pure]`
539+
537540
error[E0565]: malformed `ffi_const` attribute input
538541
--> $DIR/malformed-attrs.rs:171:5
539542
|

0 commit comments

Comments
 (0)