tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
25.71k stars 2.35k forks source link

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

Open Urgau opened 1 month ago

Urgau commented 1 month ago

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

Darksonn commented 1 month ago

Will this work on our MSRV of Rust 1.63?

Urgau commented 1 month ago

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.