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

Rust 1.80 upcoming warning: unexpected cfg condition name: coverage_nightly #370

Open
azriel91 opened this issue May 7, 2024 · 2 comments
Labels
C-question Category: A question C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream)

Comments

@azriel91
Copy link

azriel91 commented May 7, 2024

Heya, in the upcoming Rust 1.80, the following attribute will cause some cargo commands to fail (at least it causes clippy on rustc 1.80.0-nightly (7d83a4c13 2024-05-06) to fail):

#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

Details are in this Rust blog post: Automatic checking of cfgs at compile-time

Error Message

The following error message appears when running clippy:

cargo clippy --workspace --fix -- -D warnings
error: unexpected `cfg` condition name: `coverage_nightly`
 --> src/lib.rs:1:13
  |
1 | #![cfg_attr(coverage_nightly, feature(coverage_attribute))]
  |             ^^^^^^^^^^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
  = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(coverage_nightly)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
  = note: `-D unexpected-cfgs` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`

The Fix

Add a build.rs with the following:

fn main() {
    println!("cargo::rustc-check-cfg=cfg(coverage_nightly)");
}

I think that's the right fix, as it got my build to pass.

If that's the right fix, then in cargo-llvm-cov it would be handy add it to the README.md as part of set up.

@taiki-e taiki-e changed the title Rust 1.80 upcoming "breakage": unexpected cfg condition name: coverage_nightly Rust 1.80 upcoming warning: unexpected cfg condition name: coverage_nightly May 8, 2024
@taiki-e
Copy link
Owner

taiki-e commented May 8, 2024

See rust-lang/rust#124800 (coverage_nightly is listed in rust-lang/rust#124800 (comment)).
This lint will probably be allowed by default: rust-lang/rust#124841

@taiki-e taiki-e added C-question Category: A question C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream) labels May 8, 2024
mdegans added a commit to mdegans/weave that referenced this issue May 23, 2024
Hopefully the last round.
- Fix order of cuda install on Windows
- Disable coverage on Linux because of this issue:
taiki-e/cargo-llvm-cov#370
@Urgau
Copy link

Urgau commented May 23, 2024

Heads up, with the release of rust-lang/cargo#13913 (in nightly-2024-05-19), Cargo has now gain the ability to declare --check-cfg args directly inside the [lints] table with [lints.rust.unexpected_cfgs.check-cfg]1:

Cargo.toml:

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

Footnotes

  1. take effect on Rust 1.80 (current nightly), is ignored on Rust 1.79 (current beta), and produce an unused warning below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream)
Projects
None yet
Development

No branches or pull requests

3 participants