mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Forward -Zallow-features to rustc
This commit is contained in:
parent
caca4d43a0
commit
85f7c800f8
@ -338,6 +338,19 @@ impl<'cfg> Compilation<'cfg> {
|
||||
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
|
||||
.cwd(pkg.root());
|
||||
|
||||
if is_rustc_tool {
|
||||
if let Some(allow) = &self.config.cli_unstable().allow_features {
|
||||
let mut arg = String::from("-Zallow-features=");
|
||||
for (i, a) in allow.iter().enumerate() {
|
||||
arg.push_str(a);
|
||||
if i != allow.len() - 1 {
|
||||
arg.push(',');
|
||||
}
|
||||
}
|
||||
cmd.arg(&arg);
|
||||
}
|
||||
}
|
||||
|
||||
if self.config.cli_unstable().configurable_env {
|
||||
// Apply any environment variables from the config
|
||||
for (key, value) in self.config.env_config()?.iter() {
|
||||
|
@ -79,6 +79,11 @@ where `test-dummy-unstable` is unstable, that features would also be
|
||||
disallowed by `-Zallow-features=`, and allowed with
|
||||
`-Zallow-features=test-dummy-unstable`.
|
||||
|
||||
The list of features passed to cargo's `-Zallow-features` is also passed
|
||||
to any Rust tools that cargo ends up calling (like `rustc` or
|
||||
`rustdoc`). Thus, if you run `cargo -Zallow-features=`, no unstable
|
||||
Cargo _or_ Rust features can be used.
|
||||
|
||||
### extra-link-arg
|
||||
* Original Pull Request: [#7811](https://github.com/rust-lang/cargo/pull/7811)
|
||||
|
||||
|
@ -131,8 +131,11 @@ fn allow_features() {
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
// NOTE: We need to use RUSTC_BOOTSTRAP here since we also need nightly rustc
|
||||
|
||||
p.cargo("-Zallow-features=test-dummy-unstable build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_stderr(
|
||||
"\
|
||||
[COMPILING] a [..]
|
||||
@ -143,12 +146,14 @@ fn allow_features() {
|
||||
|
||||
p.cargo("-Zallow-features=test-dummy-unstable,print-im-a-teapot -Zprint-im-a-teapot build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_stdout("im-a-teapot = true")
|
||||
.with_stderr("[FINISHED] [..]")
|
||||
.run();
|
||||
|
||||
p.cargo("-Zallow-features=test-dummy-unstable -Zprint-im-a-teapot build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
@ -159,6 +164,7 @@ error: the feature `print-im-a-teapot` is not in the list of allowed features: {
|
||||
|
||||
p.cargo("-Zallow-features= build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
@ -171,6 +177,57 @@ Caused by:
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn allow_features_to_rustc() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "a"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(test_2018_feature)]
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
// NOTE: We need to use RUSTC_BOOTSTRAP here since we also need nightly rustc
|
||||
|
||||
p.cargo("-Zallow-features= build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr_contains(
|
||||
"\
|
||||
[COMPILING] a [..]
|
||||
error[E0725]: the feature `test_2018_feature` is not in the list of allowed features
|
||||
",
|
||||
)
|
||||
.with_stderr_contains(
|
||||
"\
|
||||
error: could not compile `a`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
||||
p.cargo("-Zallow-features=test_2018_feature build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_stderr(
|
||||
"\
|
||||
[COMPILING] a [..]
|
||||
[FINISHED] [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn allow_features_in_cfg() {
|
||||
let p = project()
|
||||
@ -196,8 +253,11 @@ fn allow_features_in_cfg() {
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
// NOTE: We need to use RUSTC_BOOTSTRAP here since we also need nightly rustc
|
||||
|
||||
p.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_stderr(
|
||||
"\
|
||||
[COMPILING] a [..]
|
||||
@ -208,12 +268,14 @@ fn allow_features_in_cfg() {
|
||||
|
||||
p.cargo("-Zprint-im-a-teapot build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_stdout("im-a-teapot = true")
|
||||
.with_stderr("[FINISHED] [..]")
|
||||
.run();
|
||||
|
||||
p.cargo("-Zunstable-options build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
@ -225,6 +287,7 @@ error: the feature `unstable-options` is not in the list of allowed features: {[
|
||||
// -Zallow-features overrides .cargo/config
|
||||
p.cargo("-Zallow-features=test-dummy-unstable -Zprint-im-a-teapot build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
@ -235,6 +298,7 @@ error: the feature `print-im-a-teapot` is not in the list of allowed features: {
|
||||
|
||||
p.cargo("-Zallow-features= build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user