about summary refs log tree commit diff
diff options
context:
space:
mode:
authorinquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com>2023-01-24 02:54:00 -0800
committerinquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com>2023-01-24 03:51:01 -0800
commit6e04e678dca99db95c28a3aa7091d4fa800dfb61 (patch)
tree3da54292aa93f1936807c3e8d8708b2fbcd71080
parent05b7cc83707026de18dc49276db04a599781bbc2 (diff)
downloadrust-6e04e678dca99db95c28a3aa7091d4fa800dfb61.tar.gz
rust-6e04e678dca99db95c28a3aa7091d4fa800dfb61.zip
Make sure FFI attrs aren't used on foreign statics
Previously, we verified that FFI attrs were used on foreign items,
but this allowed them on both foreign functions and foreign statics.
This change only allows them on foreign functions.
-rw-r--r--compiler/rustc_passes/src/check_attr.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index f38b9c5834d..663dfbb4d13 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -150,9 +150,9 @@ impl CheckAttrVisitor<'_> {
                 sym::rustc_has_incoherent_inherent_impls => {
                     self.check_has_incoherent_inherent_impls(&attr, span, target)
                 }
-                sym::ffi_pure => self.check_ffi_pure(hir_id, attr.span, attrs),
-                sym::ffi_const => self.check_ffi_const(hir_id, attr.span),
-                sym::ffi_returns_twice => self.check_ffi_returns_twice(hir_id, attr.span),
+                sym::ffi_pure => self.check_ffi_pure(attr.span, attrs, target),
+                sym::ffi_const => self.check_ffi_const(attr.span, target),
+                sym::ffi_returns_twice => self.check_ffi_returns_twice(attr.span, target),
                 sym::rustc_const_unstable
                 | sym::rustc_const_stable
                 | sym::unstable
@@ -1174,8 +1174,8 @@ impl CheckAttrVisitor<'_> {
         }
     }
 
-    fn check_ffi_pure(&self, hir_id: HirId, attr_span: Span, attrs: &[Attribute]) -> bool {
-        if !self.tcx.is_foreign_item(self.tcx.hir().local_def_id(hir_id)) {
+    fn check_ffi_pure(&self, attr_span: Span, attrs: &[Attribute], target: Target) -> bool {
+        if target != Target::ForeignFn {
             self.tcx.sess.emit_err(errors::FfiPureInvalidTarget { attr_span });
             return false;
         }
@@ -1188,8 +1188,8 @@ impl CheckAttrVisitor<'_> {
         }
     }
 
-    fn check_ffi_const(&self, hir_id: HirId, attr_span: Span) -> bool {
-        if self.tcx.is_foreign_item(self.tcx.hir().local_def_id(hir_id)) {
+    fn check_ffi_const(&self, attr_span: Span, target: Target) -> bool {
+        if target == Target::ForeignFn {
             true
         } else {
             self.tcx.sess.emit_err(errors::FfiConstInvalidTarget { attr_span });
@@ -1197,8 +1197,8 @@ impl CheckAttrVisitor<'_> {
         }
     }
 
-    fn check_ffi_returns_twice(&self, hir_id: HirId, attr_span: Span) -> bool {
-        if self.tcx.is_foreign_item(self.tcx.hir().local_def_id(hir_id)) {
+    fn check_ffi_returns_twice(&self, attr_span: Span, target: Target) -> bool {
+        if target == Target::ForeignFn {
             true
         } else {
             self.tcx.sess.emit_err(errors::FfiReturnsTwiceInvalidTarget { attr_span });