Implement cfg(target_abi) (RFC 2992)

Add an `abi` field to `TargetOptions`, defaulting to "". Support using
`cfg(target_abi = "...")` for conditional compilation on that field.

Gated by `feature(cfg_target_abi)`.

Add a test for `target_abi`, and a test for the feature gate.

Add `target_abi` to tidy as a platform-specific cfg.

This does not add an abi to any existing target.
This commit is contained in:
Josh Triplett 2021-07-06 20:54:54 -07:00
parent c0bd5a584d
commit 84d6e8aed3
9 changed files with 76 additions and 1 deletions

View file

@ -0,0 +1,10 @@
// run-pass
#![feature(cfg_target_abi)]
#[cfg(target_abi = "eabihf")]
pub fn main() {
}
#[cfg(not(target_abi = "eabihf"))]
pub fn main() {
}

View file

@ -0,0 +1,11 @@
#[cfg(target_abi = "x")] //~ ERROR `cfg(target_abi)` is experimental
#[cfg_attr(target_abi = "x", x)] //~ ERROR `cfg(target_abi)` is experimental
struct Foo(u64, u64);
#[cfg(not(any(all(target_abi = "x"))))] //~ ERROR `cfg(target_abi)` is experimental
fn foo() {}
fn main() {
cfg!(target_abi = "x");
//~^ ERROR `cfg(target_abi)` is experimental and subject to change
}

View file

@ -0,0 +1,39 @@
error[E0658]: `cfg(target_abi)` is experimental and subject to change
--> $DIR/feature-gate-cfg-target-abi.rs:2:12
|
LL | #[cfg_attr(target_abi = "x", x)]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #80970 <https://github.com/rust-lang/rust/issues/80970> for more information
= help: add `#![feature(cfg_target_abi)]` to the crate attributes to enable
error[E0658]: `cfg(target_abi)` is experimental and subject to change
--> $DIR/feature-gate-cfg-target-abi.rs:1:7
|
LL | #[cfg(target_abi = "x")]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #80970 <https://github.com/rust-lang/rust/issues/80970> for more information
= help: add `#![feature(cfg_target_abi)]` to the crate attributes to enable
error[E0658]: `cfg(target_abi)` is experimental and subject to change
--> $DIR/feature-gate-cfg-target-abi.rs:5:19
|
LL | #[cfg(not(any(all(target_abi = "x"))))]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #80970 <https://github.com/rust-lang/rust/issues/80970> for more information
= help: add `#![feature(cfg_target_abi)]` to the crate attributes to enable
error[E0658]: `cfg(target_abi)` is experimental and subject to change
--> $DIR/feature-gate-cfg-target-abi.rs:9:10
|
LL | cfg!(target_abi = "x");
| ^^^^^^^^^^^^^^^^
|
= note: see issue #80970 <https://github.com/rust-lang/rust/issues/80970> for more information
= help: add `#![feature(cfg_target_abi)]` to the crate attributes to enable
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -122,6 +122,7 @@ fn check_cfgs(
let contains_platform_specific_cfg = cfg.contains("target_os")
|| cfg.contains("target_env")
|| cfg.contains("target_abi")
|| cfg.contains("target_vendor")
|| cfg.contains("unix")
|| cfg.contains("windows");