tokio icon indicating copy to clipboard operation
tokio copied to clipboard

Use `[lints.rust.unexpected_cfgs.check-cfg]` instead of hacky check-cfg workaround

Open Urgau opened this issue 1 year ago • 2 comments
trafficstars

With the release of rust-lang/cargo#13913 (in nightly-2024-05-19), there is no longer any need for the kind of workarounds employed in #6538. Cargo has 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(foo)'] }

Note that the diagnostic output of the lint has been updated to suggest the [lints] approach first. You can use it to guide you through the --check-cfg arguments that may need to be added.

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

Originally posted by @Urgau in https://github.com/tokio-rs/tokio/issues/6538#issuecomment-2128036174

Urgau avatar May 24 '24 07:05 Urgau

Will this work on our MSRV of Rust 1.63?

Darksonn avatar May 24 '24 20:05 Darksonn

There is no reason it wouldn't. The feature is only active with Rust 1.80. And while [lints.rust.unexpected_cfgs.check-cfg] produces a unused warning for Rust 1.78 and below, it is only present in local development, thanks to a --cap-lints-like system in Cargo.

Urgau avatar May 24 '24 20:05 Urgau

This is not blocked on MSRV.

On older versions, Cargo just outputting a warning that is not promoted to an error as well as the rust-version field.

warning: /home/runner/work/tokio/tokio/Cargo.toml: unused manifest key: workspace.lints.rust.unexpected_cfgs.check-cfg

taiki-e avatar Jan 25 '25 12:01 taiki-e