From cdb132d333c9f8d20f6f4daef0bd72a67ce83f5b Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sat, 14 May 2022 20:59:52 +0200 Subject: [PATCH] Revert "chore: disable warnings in old CI (#4691)" This reverts commit b24df49a9d26057b44a869c6effce494ec10dd35 so we can merge the CHANGELOG changes in #4691 into master. --- .circleci/config.yml | 25 ------- .cirrus.yml | 4 +- .github/workflows/ci.yml | 14 ++-- .github/workflows/loom.yml | 3 +- Cargo.toml | 1 + tests-build/Cargo.toml | 16 +++++ tests-build/README.md | 2 + tests-build/src/lib.rs | 2 + .../tests/fail/macros_core_no_default.rs | 6 ++ .../tests/fail/macros_core_no_default.stderr | 7 ++ tests-build/tests/fail/macros_dead_code.rs | 8 +++ .../tests/fail/macros_dead_code.stderr | 11 +++ .../tests/fail/macros_invalid_input.rs | 40 +++++++++++ .../tests/fail/macros_invalid_input.stderr | 71 +++++++++++++++++++ .../tests/fail/macros_type_mismatch.rs | 26 +++++++ .../tests/fail/macros_type_mismatch.stderr | 45 ++++++++++++ tests-build/tests/macros.rs | 27 +++++++ tests-build/tests/macros_clippy.rs | 7 ++ .../tests/pass/forward_args_and_output.rs | 13 ++++ tests-build/tests/pass/macros_main_loop.rs | 14 ++++ tests-build/tests/pass/macros_main_return.rs | 6 ++ tokio/src/time/driver/sleep.rs | 12 ++-- 22 files changed, 323 insertions(+), 37 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 tests-build/Cargo.toml create mode 100644 tests-build/README.md create mode 100644 tests-build/src/lib.rs create mode 100644 tests-build/tests/fail/macros_core_no_default.rs create mode 100644 tests-build/tests/fail/macros_core_no_default.stderr create mode 100644 tests-build/tests/fail/macros_dead_code.rs create mode 100644 tests-build/tests/fail/macros_dead_code.stderr create mode 100644 tests-build/tests/fail/macros_invalid_input.rs create mode 100644 tests-build/tests/fail/macros_invalid_input.stderr create mode 100644 tests-build/tests/fail/macros_type_mismatch.rs create mode 100644 tests-build/tests/fail/macros_type_mismatch.stderr create mode 100644 tests-build/tests/macros.rs create mode 100644 tests-build/tests/macros_clippy.rs create mode 100644 tests-build/tests/pass/forward_args_and_output.rs create mode 100644 tests-build/tests/pass/macros_main_loop.rs create mode 100644 tests-build/tests/pass/macros_main_return.rs diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 97670e93784..00000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 2.1 -jobs: - test-arm: - machine: - image: ubuntu-2004:202101-01 - resource_class: arm.medium - environment: - # Change to pin rust versino - RUST_STABLE: stable - steps: - - checkout - - run: - name: Install Rust - command: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh - chmod +x rustup.sh - ./rustup.sh -y --default-toolchain $RUST_STABLE - source "$HOME"/.cargo/env - # Only run Tokio tests - - run: cargo test --all-features -p tokio - -workflows: - ci: - jobs: - - test-arm diff --git a/.cirrus.yml b/.cirrus.yml index 390f7883fef..4bef869c24f 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,5 +1,7 @@ freebsd_instance: image: freebsd-12-2-release-amd64 +env: + RUSTFLAGS: -D warnings # Test FreeBSD in a full VM on cirrus-ci.com. Test the i686 target too, in the # same VM. The binary will be built in 32-bit mode, but will execute on a @@ -23,7 +25,7 @@ task: name: FreeBSD docs env: RUSTFLAGS: --cfg docsrs - RUSTDOCFLAGS: --cfg docsrs + RUSTDOCFLAGS: --cfg docsrs -Dwarnings setup_script: - pkg install -y bash curl - curl https://sh.rustup.rs -sSf --output rustup.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 862dab192b6..05f6e87f330 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: name: CI env: + RUSTFLAGS: -Dwarnings RUST_BACKTRACE: 1 nightly: nightly-2021-10-25 minrust: 1.45.2 @@ -64,6 +65,11 @@ jobs: run: cargo hack test --each-feature working-directory: tests-integration + # Run macro build tests + - name: test tests-build --each-feature + run: cargo hack test --each-feature + working-directory: tests-build + # Build benchmarks. Run of benchmarks is done by bench.yml workflow. - name: build benches run: cargo build --benches @@ -123,7 +129,7 @@ jobs: run: cargo test --all-features working-directory: tokio env: - RUSTFLAGS: --cfg tokio_unstable + RUSTFLAGS: --cfg tokio_unstable -Dwarnings miri: name: miri @@ -207,7 +213,7 @@ jobs: - name: check --each-feature --unstable run: cargo hack check --all --each-feature -Z avoid-dev-deps env: - RUSTFLAGS: --cfg tokio_unstable + RUSTFLAGS: --cfg tokio_unstable -Dwarnings minrust: name: minrust @@ -292,7 +298,7 @@ jobs: run: cargo doc --lib --no-deps --all-features --document-private-items env: RUSTFLAGS: --cfg docsrs - RUSTDOCFLAGS: --cfg docsrs + RUSTDOCFLAGS: --cfg docsrs -Dwarnings loom-compile: name: build loom tests @@ -306,7 +312,7 @@ jobs: run: cargo test --no-run --lib --features full working-directory: tokio env: - RUSTFLAGS: --cfg loom --cfg tokio_unstable + RUSTFLAGS: --cfg loom --cfg tokio_unstable -Dwarnings check-readme: name: Check README diff --git a/.github/workflows/loom.yml b/.github/workflows/loom.yml index 088828a1b51..fde9f1114e1 100644 --- a/.github/workflows/loom.yml +++ b/.github/workflows/loom.yml @@ -8,6 +8,7 @@ on: name: Loom env: + RUSTFLAGS: -Dwarnings RUST_BACKTRACE: 1 jobs: @@ -34,6 +35,6 @@ jobs: run: cargo test --lib --release --features full -- --nocapture $SCOPE working-directory: tokio env: - RUSTFLAGS: --cfg loom --cfg tokio_unstable + RUSTFLAGS: --cfg loom --cfg tokio_unstable -Dwarnings LOOM_MAX_PREEMPTIONS: 2 SCOPE: ${{ matrix.scope }} diff --git a/Cargo.toml b/Cargo.toml index 0ed9192a249..bc01f186281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ members = [ "benches", "examples", "stress-test", + "tests-build", "tests-integration", ] diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml new file mode 100644 index 00000000000..299af0cf417 --- /dev/null +++ b/tests-build/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "tests-build" +version = "0.1.0" +authors = ["Tokio Contributors "] +edition = "2018" +publish = false + +[features] +full = ["tokio/full"] +rt = ["tokio/rt", "tokio/macros"] + +[dependencies] +tokio = { path = "../tokio", optional = true } + +[dev-dependencies] +trybuild = "1.0" diff --git a/tests-build/README.md b/tests-build/README.md new file mode 100644 index 00000000000..f491e2bc377 --- /dev/null +++ b/tests-build/README.md @@ -0,0 +1,2 @@ +Tests the various combination of feature flags. This is broken out to a separate +crate to work around limitations with cargo features. diff --git a/tests-build/src/lib.rs b/tests-build/src/lib.rs new file mode 100644 index 00000000000..7b019cc7c26 --- /dev/null +++ b/tests-build/src/lib.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "tokio")] +pub use tokio; diff --git a/tests-build/tests/fail/macros_core_no_default.rs b/tests-build/tests/fail/macros_core_no_default.rs new file mode 100644 index 00000000000..23f8847df7d --- /dev/null +++ b/tests-build/tests/fail/macros_core_no_default.rs @@ -0,0 +1,6 @@ +use tests_build::tokio; + +#[tokio::main] +async fn my_fn() {} + +fn main() {} diff --git a/tests-build/tests/fail/macros_core_no_default.stderr b/tests-build/tests/fail/macros_core_no_default.stderr new file mode 100644 index 00000000000..676acc8dbe3 --- /dev/null +++ b/tests-build/tests/fail/macros_core_no_default.stderr @@ -0,0 +1,7 @@ +error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled. + --> $DIR/macros_core_no_default.rs:3:1 + | +3 | #[tokio::main] + | ^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `tokio::main` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests-build/tests/fail/macros_dead_code.rs b/tests-build/tests/fail/macros_dead_code.rs new file mode 100644 index 00000000000..f2ada6f835d --- /dev/null +++ b/tests-build/tests/fail/macros_dead_code.rs @@ -0,0 +1,8 @@ +#![deny(dead_code)] + +use tests_build::tokio; + +#[tokio::main] +async fn f() {} + +fn main() {} diff --git a/tests-build/tests/fail/macros_dead_code.stderr b/tests-build/tests/fail/macros_dead_code.stderr new file mode 100644 index 00000000000..816c294bd31 --- /dev/null +++ b/tests-build/tests/fail/macros_dead_code.stderr @@ -0,0 +1,11 @@ +error: function is never used: `f` + --> $DIR/macros_dead_code.rs:6:10 + | +6 | async fn f() {} + | ^ + | +note: the lint level is defined here + --> $DIR/macros_dead_code.rs:1:9 + | +1 | #![deny(dead_code)] + | ^^^^^^^^^ diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs new file mode 100644 index 00000000000..eb04eca76b6 --- /dev/null +++ b/tests-build/tests/fail/macros_invalid_input.rs @@ -0,0 +1,40 @@ +use tests_build::tokio; + +#[tokio::main] +fn main_is_not_async() {} + +#[tokio::main(foo)] +async fn main_attr_has_unknown_args() {} + +#[tokio::main(threadpool::bar)] +async fn main_attr_has_path_args() {} + +#[tokio::test] +fn test_is_not_async() {} + +#[tokio::test(foo)] +async fn test_attr_has_args() {} + +#[tokio::test(foo = 123)] +async fn test_unexpected_attr() {} + +#[tokio::test(flavor = 123)] +async fn test_flavor_not_string() {} + +#[tokio::test(flavor = "foo")] +async fn test_unknown_flavor() {} + +#[tokio::test(flavor = "multi_thread", start_paused = false)] +async fn test_multi_thread_with_start_paused() {} + +#[tokio::test(flavor = "multi_thread", worker_threads = "foo")] +async fn test_worker_threads_not_int() {} + +#[tokio::test(flavor = "current_thread", worker_threads = 4)] +async fn test_worker_threads_and_current_thread() {} + +#[tokio::test] +#[test] +async fn test_has_second_test_attr() {} + +fn main() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr new file mode 100644 index 00000000000..11337a94fe5 --- /dev/null +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -0,0 +1,71 @@ +error: the `async` keyword is missing from the function declaration + --> $DIR/macros_invalid_input.rs:4:1 + | +4 | fn main_is_not_async() {} + | ^^ + +error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused` + --> $DIR/macros_invalid_input.rs:6:15 + | +6 | #[tokio::main(foo)] + | ^^^ + +error: Must have specified ident + --> $DIR/macros_invalid_input.rs:9:15 + | +9 | #[tokio::main(threadpool::bar)] + | ^^^^^^^^^^^^^^^ + +error: the `async` keyword is missing from the function declaration + --> $DIR/macros_invalid_input.rs:13:1 + | +13 | fn test_is_not_async() {} + | ^^ + +error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused` + --> $DIR/macros_invalid_input.rs:15:15 + | +15 | #[tokio::test(foo)] + | ^^^ + +error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused` + --> $DIR/macros_invalid_input.rs:18:15 + | +18 | #[tokio::test(foo = 123)] + | ^^^^^^^^^ + +error: Failed to parse value of `flavor` as string. + --> $DIR/macros_invalid_input.rs:21:24 + | +21 | #[tokio::test(flavor = 123)] + | ^^^ + +error: No such runtime flavor `foo`. The runtime flavors are `current_thread` and `multi_thread`. + --> $DIR/macros_invalid_input.rs:24:24 + | +24 | #[tokio::test(flavor = "foo")] + | ^^^^^ + +error: The `start_paused` option requires the `current_thread` runtime flavor. Use `#[tokio::test(flavor = "current_thread")]` + --> $DIR/macros_invalid_input.rs:27:55 + | +27 | #[tokio::test(flavor = "multi_thread", start_paused = false)] + | ^^^^^ + +error: Failed to parse value of `worker_threads` as integer. + --> $DIR/macros_invalid_input.rs:30:57 + | +30 | #[tokio::test(flavor = "multi_thread", worker_threads = "foo")] + | ^^^^^ + +error: The `worker_threads` option requires the `multi_thread` runtime flavor. Use `#[tokio::test(flavor = "multi_thread")]` + --> $DIR/macros_invalid_input.rs:33:59 + | +33 | #[tokio::test(flavor = "current_thread", worker_threads = 4)] + | ^ + +error: second test attribute is supplied + --> $DIR/macros_invalid_input.rs:37:1 + | +37 | #[test] + | ^^^^^^^ diff --git a/tests-build/tests/fail/macros_type_mismatch.rs b/tests-build/tests/fail/macros_type_mismatch.rs new file mode 100644 index 00000000000..0a5b9c4c727 --- /dev/null +++ b/tests-build/tests/fail/macros_type_mismatch.rs @@ -0,0 +1,26 @@ +use tests_build::tokio; + +#[tokio::main] +async fn missing_semicolon_or_return_type() { + Ok(()) +} + +#[tokio::main] +async fn missing_return_type() { + return Ok(()); +} + +#[tokio::main] +async fn extra_semicolon() -> Result<(), ()> { + /* TODO(taiki-e): help message still wrong + help: try using a variant of the expected enum + | + 23 | Ok(Ok(());) + | + 23 | Err(Ok(());) + | + */ + Ok(()); +} + +fn main() {} diff --git a/tests-build/tests/fail/macros_type_mismatch.stderr b/tests-build/tests/fail/macros_type_mismatch.stderr new file mode 100644 index 00000000000..a8fa99bc63b --- /dev/null +++ b/tests-build/tests/fail/macros_type_mismatch.stderr @@ -0,0 +1,45 @@ +error[E0308]: mismatched types + --> $DIR/macros_type_mismatch.rs:5:5 + | +5 | Ok(()) + | ^^^^^^ expected `()`, found enum `Result` + | + = note: expected unit type `()` + found enum `Result<(), _>` +help: consider using a semicolon here + | +5 | Ok(()); + | + +help: try adding a return type + | +4 | async fn missing_semicolon_or_return_type() -> Result<(), _> { + | ++++++++++++++++ + +error[E0308]: mismatched types + --> $DIR/macros_type_mismatch.rs:10:5 + | +9 | async fn missing_return_type() { + | - help: try adding a return type: `-> Result<(), _>` +10 | return Ok(()); + | ^^^^^^^^^^^^^^ expected `()`, found enum `Result` + | + = note: expected unit type `()` + found enum `Result<(), _>` + +error[E0308]: mismatched types + --> $DIR/macros_type_mismatch.rs:23:5 + | +14 | async fn extra_semicolon() -> Result<(), ()> { + | -------------- expected `Result<(), ()>` because of return type +... +23 | Ok(()); + | ^^^^^^^ expected enum `Result`, found `()` + | + = note: expected enum `Result<(), ()>` + found unit type `()` +help: try using a variant of the expected enum + | +23 | Ok(Ok(());) + | +23 | Err(Ok(());) + | diff --git a/tests-build/tests/macros.rs b/tests-build/tests/macros.rs new file mode 100644 index 00000000000..0a180dfb74f --- /dev/null +++ b/tests-build/tests/macros.rs @@ -0,0 +1,27 @@ +#[test] +fn compile_fail_full() { + let t = trybuild::TestCases::new(); + + #[cfg(feature = "full")] + t.pass("tests/pass/forward_args_and_output.rs"); + + #[cfg(feature = "full")] + t.pass("tests/pass/macros_main_return.rs"); + + #[cfg(feature = "full")] + t.pass("tests/pass/macros_main_loop.rs"); + + #[cfg(feature = "full")] + t.compile_fail("tests/fail/macros_invalid_input.rs"); + + #[cfg(feature = "full")] + t.compile_fail("tests/fail/macros_dead_code.rs"); + + #[cfg(feature = "full")] + t.compile_fail("tests/fail/macros_type_mismatch.rs"); + + #[cfg(all(feature = "rt", not(feature = "full")))] + t.compile_fail("tests/fail/macros_core_no_default.rs"); + + drop(t); +} diff --git a/tests-build/tests/macros_clippy.rs b/tests-build/tests/macros_clippy.rs new file mode 100644 index 00000000000..0f3f4bb0b8b --- /dev/null +++ b/tests-build/tests/macros_clippy.rs @@ -0,0 +1,7 @@ +#[cfg(feature = "full")] +#[tokio::test] +async fn test_with_semicolon_without_return_type() { + #![deny(clippy::semicolon_if_nothing_returned)] + + dbg!(0); +} diff --git a/tests-build/tests/pass/forward_args_and_output.rs b/tests-build/tests/pass/forward_args_and_output.rs new file mode 100644 index 00000000000..e6ef1f88c1e --- /dev/null +++ b/tests-build/tests/pass/forward_args_and_output.rs @@ -0,0 +1,13 @@ +use tests_build::tokio; + +fn main() {} + +// arguments and output type is forwarded so other macros can access them + +#[tokio::test] +async fn test_fn_has_args(_x: u8) {} + +#[tokio::test] +async fn test_has_output() -> Result<(), Box> { + Ok(()) +} diff --git a/tests-build/tests/pass/macros_main_loop.rs b/tests-build/tests/pass/macros_main_loop.rs new file mode 100644 index 00000000000..d7d51982c36 --- /dev/null +++ b/tests-build/tests/pass/macros_main_loop.rs @@ -0,0 +1,14 @@ +use tests_build::tokio; + +#[tokio::main] +async fn main() -> Result<(), ()> { + loop { + if !never() { + return Ok(()); + } + } +} + +fn never() -> bool { + std::time::Instant::now() > std::time::Instant::now() +} diff --git a/tests-build/tests/pass/macros_main_return.rs b/tests-build/tests/pass/macros_main_return.rs new file mode 100644 index 00000000000..d4d34ec26d3 --- /dev/null +++ b/tests-build/tests/pass/macros_main_return.rs @@ -0,0 +1,6 @@ +use tests_build::tokio; + +#[tokio::main] +async fn main() -> Result<(), ()> { + return Ok(()); +} diff --git a/tokio/src/time/driver/sleep.rs b/tokio/src/time/driver/sleep.rs index c0571ca2ab9..43ff694ffc6 100644 --- a/tokio/src/time/driver/sleep.rs +++ b/tokio/src/time/driver/sleep.rs @@ -324,8 +324,8 @@ impl Sleep { } fn reset_inner(self: Pin<&mut Self>, deadline: Instant) { - let mut me = self.project(); - me.entry.as_mut().reset(deadline); + let me = self.project(); + me.entry.reset(deadline); (*me.inner).deadline = deadline; #[cfg(all(tokio_unstable, feature = "tracing"))] @@ -349,12 +349,12 @@ impl Sleep { cfg_not_trace! { fn poll_elapsed(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { - let mut me = self.project(); + let me = self.project(); // Keep track of task budget let coop = ready!(crate::coop::poll_proceed(cx)); - me.entry.as_mut().poll_elapsed(cx).map(move |r| { + me.entry.poll_elapsed(cx).map(move |r| { coop.made_progress(); r }) @@ -363,7 +363,7 @@ impl Sleep { cfg_trace! { fn poll_elapsed(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { - let mut me = self.project(); + let me = self.project(); // Keep track of task budget let coop = ready!(trace_poll_op!( "poll_elapsed", @@ -371,7 +371,7 @@ impl Sleep { me.inner.resource_span.id(), )); - let result = me.entry.as_mut().poll_elapsed(cx).map(move |r| { + let result = me.entry.poll_elapsed(cx).map(move |r| { coop.made_progress(); r });