Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace unexpected-cfg lint configuration does not apply to integration test. #13944

Closed
ChrisDenton opened this issue May 21, 2024 · 3 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@ChrisDenton
Copy link
Member

ChrisDenton commented May 21, 2024

Problem

When using the workspace lints table to set rust.unexpected-cfg, integration tests appear to ignore the configuration.

Steps

Workspace Cargo.toml:

[workspace]
resolver = "2"
members = ["unexpected"]

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(biscuits)'] }

Add a workspace crate called "unexpected" with an unexpected/tests/test.rs file:

#![cfg(biscuits)]

Running cargo +nightly test will warn about the unexpected cfg even though it's set.

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.80.0-nightly (0de7f2ec6 2024-05-17)
release: 1.80.0-nightly
commit-hash: 0de7f2ec6c39d68022e6b97a39559d2f4dbf3930
commit-date: 2024-05-17
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.22631 (Windows 11 Professional) [64-bit]
@ChrisDenton ChrisDenton added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 21, 2024
@epage
Copy link
Contributor

epage commented May 21, 2024

Hmm, I'm not able to reproduce this with cargo 1.80.0-nightly (0de7f2e 2024-05-17)

I went a step further and have #![cfg(biscuits)] in unexpected/src/main.rs in a mod regular and in a #[cfg(test)] mod test.

Without the lint config, I get

$ cargo check --all-targets
warning: unexpected `cfg` condition name: `biscuits`
 --> unexpected/tests/test.rs:1:8
  |
1 | #![cfg(biscuits)]
  |        ^^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_c
hecks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `saniti
zer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feat
ure`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_p
ointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(biscuits)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(biscuits)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about chec
king conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `biscuits`
 --> unexpected/src/main.rs:2:12
  |
2 |     #![cfg(biscuits)]
  |            ^^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_c
hecks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `saniti
zer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feat
ure`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_p
ointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(biscuits)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(biscuits)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about chec
king conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `biscuits`
 --> unexpected/src/main.rs:7:12
  |
7 |     #![cfg(biscuits)]
  |            ^^^^^^^^
  |
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(biscuits)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(biscuits)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about chec
king conditional configuration

warning: `unexpected` (test "test") generated 1 warning
warning: `unexpected` (bin "unexpected") generated 1 warning
warning: `unexpected` (bin "unexpected" test) generated 2 warnings (1 duplicate)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s

with the lint config I get

$ cargo +nightly check  --all-targets
    Checking unexpected v0.1.0 (/home/epage/src/personal/dump/cargo-13944/unexpected)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s

Running cargo +nightly test doesn't change the result.

@epage
Copy link
Contributor

epage commented May 21, 2024

Note that the issue at one point mentions rust.unexpected-cfg, (outside of the reproduction steps though). We don't support rust.unexpected-cfg,, only rust.unexpected_cfg,. See #13943.

@ChrisDenton
Copy link
Member Author

Ah, it seems I was missing the workspace = true when minimizing tests cases. Following my own steps fresh (rather than copy/pasting) it works thanks to cargo new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants