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

Closed
azriel91 opened this issue May 7, 2024 · 4 comments
Closed
Labels
C-documentation Category: related to documentation. C-question Category: A question

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

@taiki-e taiki-e added C-documentation Category: related to documentation. and removed C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream) labels Jul 18, 2024
taiki-e added a commit that referenced this issue Jul 18, 2024
@matan-starkware
Copy link

This linter update seems to work for me at the package level, but not at the workspace level. Meaning if I put the line you had in every package's Cargo.toml it takes effect, but if I put it in the workspace's Cargo.toml it seems to make no difference:

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

Is there any way to have this configured at the workspace level?

@taiki-e
Copy link
Owner

taiki-e commented Aug 1, 2024

See cargo docs: https://doc.rust-lang.org/cargo/reference/workspaces.html#the-lints-table

# [PROJECT_DIR]/Cargo.toml
[workspace]
members = ["crates/*"]

[workspace.lints.rust]
unsafe_code = "forbid"
# [PROJECT_DIR]/crates/bar/Cargo.toml
[package]
name = "bar"
version = "0.1.0"

[lints]
workspace = true

You have to add the last one (lints.workspace = true).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-documentation Category: related to documentation. C-question Category: A question
Projects
None yet
Development

No branches or pull requests

4 participants