Update regular tests for always-on check-cfg

This commit is contained in:
Urgau 2024-04-17 11:18:14 +02:00
parent 60a5026885
commit 388a17f23f
8 changed files with 49 additions and 41 deletions

View File

@ -2609,7 +2609,10 @@ fn cfg_test() {
)
.file(
"build.rs",
r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#,
r#"fn main() {
println!("cargo::rustc-cfg=foo");
println!("cargo::rustc-check-cfg=cfg(foo)");
}"#,
)
.file(
"src/lib.rs",
@ -2714,6 +2717,9 @@ fn cfg_override_test() {
authors = []
build = "build.rs"
links = "a"
[lints.rust]
unexpected_cfgs = "allow" # bc of override, stable/nightly, tests
"#,
)
.file("build.rs", "")
@ -5590,9 +5596,10 @@ fn build_script_rerun_when_target_rustflags_change() {
use std::env;
fn main() {
println!("cargo::rustc-check-cfg=cfg(enable)");
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
println!("cargo::rustc-cfg=enable")
println!("cargo::rustc-cfg=enable");
}
}
}

View File

@ -1,4 +1,4 @@
<svg width="1230px" height="722px" xmlns="http://www.w3.org/2000/svg">
<svg width="1230px" height="704px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -39,63 +39,61 @@
</tspan>
<tspan x="10px" y="190px"><tspan> </tspan><tspan class="fg-cyan bold">-Z cargo-lints </tspan><tspan> Enable the `[lints.cargo]` table</tspan>
</tspan>
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-cyan bold">-Z check-cfg </tspan><tspan> Enable compile-time checking of `cfg` names/values/features</tspan>
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-cyan bold">-Z codegen-backend </tspan><tspan> Enable the `codegen-backend` option in profiles in .cargo/config.toml file</tspan>
</tspan>
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-cyan bold">-Z codegen-backend </tspan><tspan> Enable the `codegen-backend` option in profiles in .cargo/config.toml file</tspan>
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-cyan bold">-Z config-include </tspan><tspan> Enable the `include` key in config files</tspan>
</tspan>
<tspan x="10px" y="244px"><tspan> </tspan><tspan class="fg-cyan bold">-Z config-include </tspan><tspan> Enable the `include` key in config files</tspan>
<tspan x="10px" y="244px"><tspan> </tspan><tspan class="fg-cyan bold">-Z direct-minimal-versions</tspan><tspan> Resolve minimal dependency versions instead of maximum (direct dependencies only)</tspan>
</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">-Z direct-minimal-versions</tspan><tspan> Resolve minimal dependency versions instead of maximum (direct dependencies only)</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">-Z doctest-xcompile </tspan><tspan> Compile and run doctests for non-host target using runner config</tspan>
</tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">-Z doctest-xcompile </tspan><tspan> Compile and run doctests for non-host target using runner config</tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">-Z dual-proc-macros </tspan><tspan> Build proc-macros for both the host and the target</tspan>
</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">-Z dual-proc-macros </tspan><tspan> Build proc-macros for both the host and the target</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gc </tspan><tspan> Track cache usage and "garbage collect" unused files</tspan>
</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gc </tspan><tspan> Track cache usage and "garbage collect" unused files</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-Z git </tspan><tspan> Enable support for shallow git fetch operations</tspan>
</tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-Z git </tspan><tspan> Enable support for shallow git fetch operations</tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gitoxide </tspan><tspan> Use gitoxide for the given git interactions, or all of them if no argument is given</tspan>
</tspan>
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gitoxide </tspan><tspan> Use gitoxide for the given git interactions, or all of them if no argument is given</tspan>
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">-Z host-config </tspan><tspan> Enable the `[host]` section in the .cargo/config.toml file</tspan>
</tspan>
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">-Z host-config </tspan><tspan> Enable the `[host]` section in the .cargo/config.toml file</tspan>
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">-Z minimal-versions </tspan><tspan> Resolve minimal dependency versions instead of maximum</tspan>
</tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">-Z minimal-versions </tspan><tspan> Resolve minimal dependency versions instead of maximum</tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">-Z msrv-policy </tspan><tspan> Enable rust-version aware policy within cargo</tspan>
</tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-Z msrv-policy </tspan><tspan> Enable rust-version aware policy within cargo</tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-Z mtime-on-use </tspan><tspan> Configure Cargo to update the mtime of used files</tspan>
</tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">-Z mtime-on-use </tspan><tspan> Configure Cargo to update the mtime of used files</tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">-Z no-index-update </tspan><tspan> Do not update the registry index even if the cache is outdated</tspan>
</tspan>
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">-Z no-index-update </tspan><tspan> Do not update the registry index even if the cache is outdated</tspan>
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">-Z panic-abort-tests </tspan><tspan> Enable support to run tests with -Cpanic=abort</tspan>
</tspan>
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">-Z panic-abort-tests </tspan><tspan> Enable support to run tests with -Cpanic=abort</tspan>
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">-Z profile-rustflags </tspan><tspan> Enable the `rustflags` option in profiles in .cargo/config.toml file</tspan>
</tspan>
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">-Z profile-rustflags </tspan><tspan> Enable the `rustflags` option in profiles in .cargo/config.toml file</tspan>
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">-Z public-dependency </tspan><tspan> Respect a dependency's `public` field in Cargo.toml to control public/private dependencies</tspan>
</tspan>
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">-Z public-dependency </tspan><tspan> Respect a dependency's `public` field in Cargo.toml to control public/private dependencies</tspan>
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">-Z publish-timeout </tspan><tspan> Enable the `publish.timeout` key in .cargo/config.toml file</tspan>
</tspan>
<tspan x="10px" y="514px"><tspan> </tspan><tspan class="fg-cyan bold">-Z publish-timeout </tspan><tspan> Enable the `publish.timeout` key in .cargo/config.toml file</tspan>
<tspan x="10px" y="514px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-map </tspan><tspan> Allow passing external documentation mappings to rustdoc</tspan>
</tspan>
<tspan x="10px" y="532px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-map </tspan><tspan> Allow passing external documentation mappings to rustdoc</tspan>
<tspan x="10px" y="532px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-scrape-examples</tspan><tspan> Allows Rustdoc to scrape code examples from reverse-dependencies</tspan>
</tspan>
<tspan x="10px" y="550px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-scrape-examples</tspan><tspan> Allows Rustdoc to scrape code examples from reverse-dependencies</tspan>
<tspan x="10px" y="550px"><tspan> </tspan><tspan class="fg-cyan bold">-Z script </tspan><tspan> Enable support for single-file, `.rs` packages</tspan>
</tspan>
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">-Z script </tspan><tspan> Enable support for single-file, `.rs` packages</tspan>
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">-Z target-applies-to-host </tspan><tspan> Enable the `target-applies-to-host` key in the .cargo/config.toml file</tspan>
</tspan>
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">-Z target-applies-to-host </tspan><tspan> Enable the `target-applies-to-host` key in the .cargo/config.toml file</tspan>
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">-Z trim-paths </tspan><tspan> Enable the `trim-paths` option in profiles</tspan>
</tspan>
<tspan x="10px" y="604px"><tspan> </tspan><tspan class="fg-cyan bold">-Z trim-paths </tspan><tspan> Enable the `trim-paths` option in profiles</tspan>
<tspan x="10px" y="604px"><tspan> </tspan><tspan class="fg-cyan bold">-Z unstable-options </tspan><tspan> Allow the usage of unstable options</tspan>
</tspan>
<tspan x="10px" y="622px"><tspan> </tspan><tspan class="fg-cyan bold">-Z unstable-options </tspan><tspan> Allow the usage of unstable options</tspan>
<tspan x="10px" y="622px">
</tspan>
<tspan x="10px" y="640px">
<tspan x="10px" y="640px"><tspan>Run with `</tspan><tspan class="fg-cyan bold">cargo -Z</tspan><tspan> </tspan><tspan class="fg-cyan">[FLAG] [COMMAND]</tspan><tspan>`</tspan>
</tspan>
<tspan x="10px" y="658px"><tspan>Run with `</tspan><tspan class="fg-cyan bold">cargo -Z</tspan><tspan> </tspan><tspan class="fg-cyan">[FLAG] [COMMAND]</tspan><tspan>`</tspan>
<tspan x="10px" y="658px">
</tspan>
<tspan x="10px" y="676px">
<tspan x="10px" y="676px"><tspan>See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information about these flags.</tspan>
</tspan>
<tspan x="10px" y="694px"><tspan>See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information about these flags.</tspan>
</tspan>
<tspan x="10px" y="712px">
<tspan x="10px" y="694px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -377,6 +377,7 @@ fn no_implicit_feature() {
r#"
fn main() {
if cfg!(feature = "regex") { println!("regex"); }
#[allow(unexpected_cfgs)]
if cfg!(feature = "lazy_static") { println!("lazy_static"); }
}
"#,

View File

@ -189,9 +189,9 @@ fn virtual_with_specific() {
.file(
"a/src/lib.rs",
r#"
#[cfg(not_feature = "f1")]
#[cfg(not(feature = "f1"))]
compile_error!{"f1 is missing"}
#[cfg(not_feature = "f2")]
#[cfg(not(feature = "f2"))]
compile_error!{"f2 is missing"}
"#,
)
@ -211,9 +211,9 @@ fn virtual_with_specific() {
.file(
"b/src/lib.rs",
r#"
#[cfg(not_feature = "f2")]
#[cfg(not(feature = "f2"))]
compile_error!{"f2 is missing"}
#[cfg(not_feature = "f3")]
#[cfg(not(feature = "f3"))]
compile_error!{"f3 is missing"}
"#,
)

View File

@ -32,7 +32,7 @@ fn profile_overrides() {
[RUNNING] `rustc --crate-name test --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=1[..]\
-C debug-assertions=on \
-C debug-assertions=on[..] \
-C metadata=[..] \
-C rpath \
--out-dir [..] \
@ -141,7 +141,7 @@ fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
--emit=[..]link \
-C opt-level={level}[..]\
-C debuginfo=2 [..]\
-C debug-assertions=on \
-C debug-assertions=on[..] \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`

View File

@ -41,7 +41,7 @@ fn lib() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C debug-assertions=off \
-C debug-assertions=off[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
@ -69,7 +69,7 @@ fn build_main_and_allow_unstable_options() {
-L dependency=[CWD]/target/debug/deps`
[RUNNING] `rustc --crate-name {name} --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C debug-assertions \
-C debug-assertions[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps \

View File

@ -1530,6 +1530,7 @@ fn two_matching_in_config() {
.file(
"src/main.rs",
r#"
#![allow(unexpected_cfgs)]
fn main() {
if cfg!(foo = "a") {
println!("a");

View File

@ -9,6 +9,7 @@ use std::fmt::Write;
// Helper to create lib.rs files that check features.
fn require(enabled_features: &[&str], disabled_features: &[&str]) -> String {
let mut s = String::new();
writeln!(s, "#![allow(unexpected_cfgs)]").unwrap();
for feature in enabled_features {
writeln!(s, "#[cfg(not(feature=\"{feature}\"))] compile_error!(\"expected feature {feature} to be enabled\");",
feature=feature).unwrap();