Port #[ffi_const] to the new attribute system

This commit is contained in:
Pavel Grigorenko
2025-06-24 01:00:30 +03:00
parent bb8b741c32
commit 99a9fe1b22
8 changed files with 32 additions and 10 deletions

View File

@@ -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
@@ -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, ..] => {
@@ -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 });
}