mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 17:22:19 +00:00
Reject static EII defaults on Apple targets
This commit is contained in:
@@ -1134,6 +1134,15 @@ pub(crate) struct EiiStaticMultipleImplementations {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`#[{$name}]` cannot be used on statics with a value on Apple targets")]
|
||||
#[note("see issue #157649 <https://github.com/rust-lang/rust/issues/157649> for more information")]
|
||||
pub(crate) struct EiiStaticDefaultApple {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`#[{$name}]` requires the name as an explicit argument when used on a static")]
|
||||
pub(crate) struct EiiStaticArgumentRequired {
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::diagnostics::{
|
||||
EiiAttributeNotSupported, EiiExternTargetExpectedList, EiiExternTargetExpectedMacro,
|
||||
EiiExternTargetExpectedUnsafe, EiiMacroExpectedMaxOneArgument, EiiOnlyOnce,
|
||||
EiiSharedMacroInStatementPosition, EiiSharedMacroTarget, EiiStaticArgumentRequired,
|
||||
EiiStaticMultipleImplementations, EiiStaticMutable,
|
||||
EiiStaticDefaultApple, EiiStaticMultipleImplementations, EiiStaticMutable,
|
||||
};
|
||||
|
||||
/// ```rust
|
||||
@@ -86,6 +86,17 @@ fn eii_(
|
||||
let (item_span, foreign_item_name) = match kind {
|
||||
ItemKind::Fn(func) => (func.sig.span, func.ident),
|
||||
ItemKind::Static(stat) => {
|
||||
// See https://github.com/rust-lang/rust/issues/157649
|
||||
if let Some(expr) = &stat.expr
|
||||
&& ecx.sess.target.is_like_darwin
|
||||
{
|
||||
ecx.dcx().emit_err(EiiStaticDefaultApple {
|
||||
span: expr.span,
|
||||
name: path_to_string(&meta_item.path),
|
||||
});
|
||||
return vec![];
|
||||
}
|
||||
|
||||
// Statics must have an explicit name for the eii
|
||||
if meta_item.is_word() {
|
||||
ecx.dcx().emit_err(EiiStaticArgumentRequired {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//@ no-prefer-dynamic
|
||||
#![crate_type = "rlib"]
|
||||
#![feature(extern_item_impls)]
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//@ no-prefer-dynamic
|
||||
//@ aux-build: decl_with_default.rs
|
||||
#![crate_type = "rlib"]
|
||||
#![feature(extern_item_impls)]
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
//@ ignore-backends: gcc
|
||||
// FIXME: linking on windows (specifically mingw) not yet supported, see tracking issue #125418
|
||||
//@ ignore-windows
|
||||
// FIXME(#157649): static EII defaults currently fail to link on Apple targets.
|
||||
//@ ignore-apple
|
||||
// Tests static EIIs with default implementations.
|
||||
|
||||
#![feature(extern_item_impls)]
|
||||
|
||||
8
tests/ui/eii/static/default_apple.rs
Normal file
8
tests/ui/eii/static/default_apple.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
//@ only-apple
|
||||
//@ ignore-backends: gcc
|
||||
|
||||
#![feature(extern_item_impls)]
|
||||
#![crate_type = "lib"]
|
||||
#[eii(eii1)]
|
||||
pub static DECL1: u64 = 5;
|
||||
//~^ ERROR `#[eii]` cannot be used on statics with a value on Apple targets
|
||||
10
tests/ui/eii/static/default_apple.stderr
Normal file
10
tests/ui/eii/static/default_apple.stderr
Normal file
@@ -0,0 +1,10 @@
|
||||
error: `#[eii]` cannot be used on statics with a value on Apple targets
|
||||
--> $DIR/default_apple.rs:7:25
|
||||
|
|
||||
LL | pub static DECL1: u64 = 5;
|
||||
| ^
|
||||
|
|
||||
= note: see issue #157649 <https://github.com/rust-lang/rust/issues/157649> for more information
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
//@ ignore-backends: gcc
|
||||
// FIXME: linking on windows (specifically mingw) not yet supported, see tracking issue #125418
|
||||
//@ ignore-windows
|
||||
// FIXME(#157649): static EII defaults currently fail to link on Apple targets.
|
||||
//@ ignore-apple
|
||||
// Tests that a static EII default can be used from another crate.
|
||||
|
||||
extern crate decl_with_default;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
//@ ignore-backends: gcc
|
||||
// FIXME: linking on windows (specifically mingw) not yet supported, see tracking issue #125418
|
||||
//@ ignore-windows
|
||||
// FIXME(#157649): static EII defaults currently fail to link on Apple targets.
|
||||
//@ ignore-apple
|
||||
// Tests that an explicit static EII implementation overrides a cross-crate default.
|
||||
|
||||
extern crate decl_with_default;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
//@ ignore-backends: gcc
|
||||
// FIXME: linking on windows (specifically mingw) not yet supported, see tracking issue #125418
|
||||
//@ ignore-windows
|
||||
// FIXME(#157649): static EII defaults currently fail to link on Apple targets.
|
||||
//@ ignore-apple
|
||||
// Tests that an explicit static EII implementation overrides a local default.
|
||||
|
||||
#![feature(extern_item_impls)]
|
||||
|
||||
Reference in New Issue
Block a user