Skip to content

Commit

Permalink
chore: use [lints] to address unexpected_cfgs lint (#7124)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Jan 25, 2025
1 parent fb7dec0 commit 7f09959
Show file tree
Hide file tree
Showing 42 changed files with 46 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ freebsd_instance:
image_family: freebsd-14-1
env:
RUST_STABLE: stable
RUST_NIGHTLY: nightly-2024-05-05
RUST_NIGHTLY: nightly-2025-01-25
RUSTFLAGS: -D warnings

# Test FreeBSD in a full VM on cirrus-ci.com. Test the i686 target too, in the
Expand Down
21 changes: 2 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ env:
RUSTUP_WINDOWS_PATH_ADD_BIN: 1
# Change to specific Rust release to pin
rust_stable: stable
rust_nightly: nightly-2024-05-05
rust_nightly: nightly-2025-01-25
# Pin a specific miri version
rust_miri_nightly: nightly-2024-10-21
rust_miri_nightly: nightly-2025-01-25
rust_clippy: '1.77'
# When updating this, also update:
# - README.md
Expand Down Expand Up @@ -1086,23 +1086,6 @@ jobs:
run: cargo check-external-types --all-features
working-directory: tokio

check-unexpected-lints-cfgs:
name: check unexpected lints and cfgs
needs: basics
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ env.rust_nightly }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.rust_nightly }}
- name: don't allow warnings
run: sed -i '/#!\[allow(unknown_lints, unexpected_cfgs)\]/d' */src/lib.rs */tests/*.rs
- name: check for unknown lints and cfgs
run: cargo check --all-features --tests
env:
RUSTFLAGS: -Dwarnings --check-cfg=cfg(loom,tokio_unstable,tokio_taskdump,fuzzing,mio_unsupported_force_poll_poll,tokio_internal_mt_counters,fs,tokio_no_parking_lot,tokio_no_tuning_tests) -Funexpected_cfgs -Funknown_lints

check-fuzzing:
name: check-fuzzing
needs: basics
Expand Down
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ members = [

[workspace.metadata.spellcheck]
config = "spellcheck.toml"

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(fuzzing)',
'cfg(loom)',
'cfg(mio_unsupported_force_poll_poll)',
'cfg(tokio_internal_mt_counters)',
'cfg(tokio_no_parking_lot)',
'cfg(tokio_no_tuning_tests)',
'cfg(tokio_taskdump)',
'cfg(tokio_unstable)',
] }
3 changes: 3 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ harness = false
name = "time_timeout"
path = "time_timeout.rs"
harness = false

[lints]
workspace = true
3 changes: 3 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ path = "named-pipe-multi-client.rs"
[[example]]
name = "dump"
path = "dump.rs"

[lints]
workspace = true
2 changes: 0 additions & 2 deletions examples/dump.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]

//! This example demonstrates tokio's experimental task dumping functionality.
//! This application deadlocks. Input CTRL+C to display traces of each task, or
//! input CTRL+C twice within 1 second to quit.
Expand Down
3 changes: 3 additions & 0 deletions stress-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ tokio = { version = "1.0.0", path = "../tokio/", features = ["full"] }

[dev-dependencies]
rand = "0.8"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions tests-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ tokio = { version = "1.0.0", path = "../tokio", optional = true }

[dev-dependencies]
trybuild = "1.0"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ tokio-test = { version = "0.4", path = "../tokio-test", optional = true }
doc-comment = "0.3.1"
futures = { version = "0.3.0", features = ["async-await"] }
bytes = "1.0.0"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions tokio-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }

[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true
5 changes: 0 additions & 5 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![allow(clippy::needless_doctest_main)]
#![warn(
missing_debug_implementations,
Expand Down Expand Up @@ -211,7 +210,6 @@ use proc_macro::TokenStream;
/// This option is only compatible with the `current_thread` runtime.
///
/// ```no_run
/// # #![allow(unknown_lints, unexpected_cfgs)]
/// #[cfg(tokio_unstable)]
/// #[tokio::main(flavor = "current_thread", unhandled_panic = "shutdown_runtime")]
/// async fn main() {
Expand All @@ -226,7 +224,6 @@ use proc_macro::TokenStream;
/// Equivalent code not using `#[tokio::main]`
///
/// ```no_run
/// # #![allow(unknown_lints, unexpected_cfgs)]
/// #[cfg(tokio_unstable)]
/// fn main() {
/// tokio::runtime::Builder::new_current_thread()
Expand Down Expand Up @@ -480,7 +477,6 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// This option is only compatible with the `current_thread` runtime.
///
/// ```no_run
/// # #![allow(unknown_lints, unexpected_cfgs)]
/// #[cfg(tokio_unstable)]
/// #[tokio::test(flavor = "current_thread", unhandled_panic = "shutdown_runtime")]
/// async fn my_test() {
Expand All @@ -495,7 +491,6 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// Equivalent code not using `#[tokio::test]`
///
/// ```no_run
/// # #![allow(unknown_lints, unexpected_cfgs)]
/// #[cfg(tokio_unstable)]
/// #[test]
/// fn my_test() {
Expand Down
3 changes: 3 additions & 0 deletions tokio-stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ rustdoc-args = ["--cfg", "docsrs"]
# This should allow `docsrs` to be read across projects, so that `tokio-stream`
# can pick up stubbed types exported by `tokio`.
rustc-args = ["--cfg", "docsrs"]

[lints]
workspace = true
1 change: 0 additions & 1 deletion tokio-stream/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![allow(
clippy::cognitive_complexity,
clippy::large_enum_variant,
Expand Down
3 changes: 3 additions & 0 deletions tokio-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ futures-util = "0.3.0"

[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true
1 change: 0 additions & 1 deletion tokio-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(
missing_debug_implementations,
missing_docs,
Expand Down
3 changes: 3 additions & 0 deletions tokio-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ rustc-args = ["--cfg", "docsrs", "--cfg", "tokio_unstable"]

[package.metadata.playground]
features = ["full"]

[lints]
workspace = true
1 change: 0 additions & 1 deletion tokio-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![allow(clippy::needless_doctest_main)]
#![warn(
missing_debug_implementations,
Expand Down
1 change: 0 additions & 1 deletion tokio-util/tests/task_join_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "rt", tokio_unstable))]

Expand Down
3 changes: 3 additions & 0 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,6 @@ allowed_external_types = [
"bytes::buf::buf_mut::BufMut",
"tokio_macros::*",
]

[lints]
workspace = true
1 change: 0 additions & 1 deletion tokio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![allow(
clippy::cognitive_complexity,
clippy::large_enum_variant,
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/blocking/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub(crate) struct Task {

#[derive(PartialEq, Eq)]
pub(crate) enum Mandatory {
#[cfg_attr(not(fs), allow(dead_code))]
#[cfg_attr(not(feature = "fs"), allow(dead_code))]
Mandatory,
NonMandatory,
}
Expand Down
2 changes: 0 additions & 2 deletions tokio/tests/_require_full.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]

#[cfg(not(any(feature = "full", target_family = "wasm")))]
compile_error!("run main Tokio tests with `--features full`");

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/dump.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![cfg(all(
tokio_unstable,
tokio_taskdump,
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/macros_select.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![cfg(feature = "macros")]
#![allow(clippy::disallowed_names)]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/macros_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading

use tokio::test;
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(not(miri))] // Possible bug on Miri.
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![allow(clippy::needless_range_loop)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_handle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_local.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", tokio_unstable))]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(target_os = "wasi"), target_has_atomic = "64"))]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_threaded.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
// Too slow on miri.
#![cfg(all(feature = "full", not(target_os = "wasi"), not(miri)))]
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_threaded_alt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(target_os = "wasi")))]
#![cfg(tokio_unstable)]
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/rt_unstable_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(
feature = "full",
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![cfg(all(tokio_unstable, feature = "tracing"))]

use std::rc::Rc;
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_hooks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", tokio_unstable, target_has_atomic = "64"))]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_join_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_local_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/task_yield_now.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![cfg(all(feature = "full", not(target_os = "wasi"), tokio_unstable))]

use tokio::task;
Expand Down
1 change: 0 additions & 1 deletion tokio/tests/tracing_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! These tests ensure that the instrumentation for tokio
//! synchronization primitives is correct.
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/tracing_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! These tests ensure that the instrumentation for task spawning and task
//! lifecycles is correct.
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]

Expand Down
1 change: 0 additions & 1 deletion tokio/tests/tracing_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! These tests ensure that the instrumentation for tokio
//! synchronization primitives is correct.
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]

Expand Down

0 comments on commit 7f09959

Please sign in to comment.