Skip to content

Commit ddbdb29

Browse files
committed
Port #[ffi_pure] to the new attribute system
1 parent 90bb6b1 commit ddbdb29

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
@@ -256,6 +256,9 @@ pub enum AttributeKind {
256256
/// Represents `#[ffi_const]`.
257257
FfiConst(Span),
258258

259+
/// Represents `#[ffi_pure]`.
260+
FfiPure(Span),
261+
259262
/// Represents `#[inline]` and `#[rustc_force_inline]`.
260263
Inline(InlineAttr, Span),
261264

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
Inline(..) => No,
3233
LinkName { .. } => Yes,
3334
LinkSection { .. } => No,

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};
@@ -144,6 +144,7 @@ attribute_parsers!(
144144
Single<WithoutArgs<ConstStabilityIndirectParser>>,
145145
Single<WithoutArgs<ExportStableParser>>,
146146
Single<WithoutArgs<FfiConstParser>>,
147+
Single<WithoutArgs<FfiPureParser>>,
147148
Single<WithoutArgs<LoopMatchParser>>,
148149
Single<WithoutArgs<MayDangleParser>>,
149150
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
@@ -214,6 +214,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
214214
AttributeKind::FfiConst(_) => {
215215
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
216216
}
217+
AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
217218
_ => {}
218219
}
219220
}
@@ -224,7 +225,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
224225

225226
match name {
226227
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
227-
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
228228
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
229229
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
230230
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
@@ -288,6 +288,7 @@ fn emit_malformed_attribute(
288288
sym::inline
289289
| sym::export_stable
290290
| sym::ffi_const
291+
| sym::ffi_pure
291292
| sym::may_dangle
292293
| sym::rustc_as_ptr
293294
| 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
@@ -204,6 +204,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
204204
&Attribute::Parsed(AttributeKind::FfiConst(attr_span)) => {
205205
self.check_ffi_const(attr_span, target)
206206
}
207+
&Attribute::Parsed(AttributeKind::FfiPure(attr_span)) => {
208+
self.check_ffi_pure(attr_span, attrs, target)
209+
}
207210
Attribute::Parsed(
208211
AttributeKind::BodyStability { .. }
209212
| AttributeKind::ConstStabilityIndirect
@@ -298,7 +301,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
298301
[sym::rustc_has_incoherent_inherent_impls, ..] => {
299302
self.check_has_incoherent_inherent_impls(attr, span, target)
300303
}
301-
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target),
302304
[sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target),
303305
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
304306
[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:164: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:166:5
145139
|
@@ -549,6 +543,15 @@ LL | #[rustc_layout_scalar_valid_range_end]
549543
| expected this to be a list
550544
| help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]`
551545

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

0 commit comments

Comments
 (0)