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.
This commit is contained in:
parent
05b7cc8370
commit
6e04e678dc
@ -150,9 +150,9 @@ fn check_attributes(
|
||||
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 @@ fn check_has_incoherent_inherent_impls(
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ fn check_ffi_pure(&self, hir_id: HirId, attr_span: Span, attrs: &[Attribute]) ->
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ fn check_ffi_const(&self, hir_id: HirId, attr_span: Span) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
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 });
|
||||
|
Loading…
Reference in New Issue
Block a user