diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f38b9c5834de..663dfbb4d13a 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 });