From 45a64ee1505662f48755937a50087355272c4d55 Mon Sep 17 00:00:00 2001 From: y86-dev Date: Sat, 20 Apr 2024 14:52:47 +0200 Subject: [PATCH] ci: deny warnings and add more checks --- .github/workflows/check.yml | 4 +--- .github/workflows/nostd.yml | 2 ++ .github/workflows/safety.yml | 18 ++++++++++++++---- .github/workflows/scheduled.yml | 4 +++- .github/workflows/test.yml | 8 +++++++- tests/alloc_fail.rs | 26 +++----------------------- tests/ring_buf.rs | 24 ++++++++++++++++++++---- tests/ui.rs | 6 ++++-- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ef3733f..d3c8af3 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -39,9 +39,7 @@ jobs: toolchain: ${{ matrix.toolchain }} components: clippy - name: cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + run: cargo clippy -- -D warnings doc: runs-on: ubuntu-latest name: nightly / doc diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml index b2e711c..f4d5c20 100644 --- a/.github/workflows/nostd.yml +++ b/.github/workflows/nostd.yml @@ -22,3 +22,5 @@ jobs: run: rustup target add ${{ matrix.target }} - name: cargo check run: cargo check --target ${{ matrix.target }} --no-default-features + env: + RUSTFLAGS: "-Dwarnings" diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml index 9b0f828..627a7d4 100644 --- a/.github/workflows/safety.yml +++ b/.github/workflows/safety.yml @@ -28,15 +28,24 @@ jobs: run: cargo test --lib --tests --all-features --target x86_64-unknown-linux-gnu env: ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0" - RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=address" + RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=address -Dwarnings" - name: cargo test -Zsanitizer=leak if: always() run: cargo test --all-features --target x86_64-unknown-linux-gnu env: LSAN_OPTIONS: "suppressions=lsan-suppressions.txt" - RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=leak" + RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=leak -Dwarnings" miri: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + flags: [ + "", + "-Zmiri-tree-borrows", + "-Zmiri-strict-provenance", + "-Zmiri-tree-borrows -Zmiri-strict-provenance" + ] steps: - uses: actions/checkout@v4 with: @@ -48,10 +57,11 @@ jobs: with: toolchain: ${{ env.NIGHTLY }} components: miri - - name: cargo miri test + - name: ${{ matrix.flags }} cargo miri test run: cargo miri test env: - MIRIFLAGS: "" + RUSTFLAGS: "-Dwarnings" + MIRIFLAGS: ${{ matrix.flags }} # loom: # runs-on: ubuntu-latest # steps: diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index e541996..605ab57 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -27,6 +27,8 @@ jobs: run: cargo generate-lockfile - name: cargo test --locked run: cargo test --locked --all-features --all-targets + env: + RUSTFLAGS: "-Dwarnings" # https://twitter.com/alcuadrado/status/1571291687837732873 update: runs-on: ubuntu-latest @@ -46,4 +48,4 @@ jobs: - name: cargo test run: cargo test --locked --all-features --all-targets env: - RUSTFLAGS: -D deprecated + RUSTFLAGS: -Ddeprecated -Dwarnings diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ab465f..052a48f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,9 +29,13 @@ jobs: # https://twitter.com/jonhoo/status/1571290371124260865 - name: cargo test --locked run: cargo test --locked --all-features --all-targets + env: + RUSTFLAGS: "-Dwarnings" # https://github.com/rust-lang/cargo/issues/6669 - name: cargo test --doc run: cargo test --locked --all-features --doc + env: + RUSTFLAGS: "-Dwarnings" os-check: runs-on: ${{ matrix.os }} name: ${{ matrix.os }} / nightly @@ -53,4 +57,6 @@ jobs: if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile - name: cargo test - run: cargo test --locked --all-features --all-targets + run: cargo test --locked --all-features --all-targets + env: + RUSTFLAGS: "-Dwarnings" diff --git a/tests/alloc_fail.rs b/tests/alloc_fail.rs index ecf0980..17d3c82 100644 --- a/tests/alloc_fail.rs +++ b/tests/alloc_fail.rs @@ -1,31 +1,11 @@ #![feature(allocator_api)] -use core::alloc::AllocError; -use pinned_init::*; -use std::sync::Arc; - -#[path = "./ring_buf.rs"] -mod ring_buf; -use ring_buf::*; - -#[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))] -#[test] -fn too_big_pinned() { - // should be too big with current hardware. - assert!(matches!( - Box::pin_init(RingBuffer::::new()), - Err(AllocError) - )); - // should be too big with current hardware. - assert!(matches!( - Arc::pin_init(RingBuffer::::new()), - Err(AllocError) - )); -} - #[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))] #[test] fn too_big_in_place() { + use core::alloc::AllocError; + use pinned_init::*; + use std::sync::Arc; // should be too big with current hardware. assert!(matches!( Box::init(zeroed::<[u8; 1024 * 1024 * 1024 * 1024]>()), diff --git a/tests/ring_buf.rs b/tests/ring_buf.rs index 3b655b1..9e4dc2f 100644 --- a/tests/ring_buf.rs +++ b/tests/ring_buf.rs @@ -12,10 +12,6 @@ use core::{ use pinned_init::*; use std::sync::Arc; -#[path = "../examples/mutex.rs"] -mod mutex; -use mutex::*; - #[pin_data(PinnedDrop)] pub struct RingBuffer { buffer: [MaybeUninit; SIZE], @@ -239,6 +235,7 @@ fn with_failing_inner() { assert_eq!(buf.as_mut().pop(), None); } +#[cfg_attr(miri, allow(dead_code))] #[derive(Debug)] struct BigStruct { buf: [u8; 1024 * 1024], @@ -263,6 +260,10 @@ fn big_struct() { #[cfg(not(miri))] #[test] fn with_big_struct() { + #[path = "../examples/mutex.rs"] + mod mutex; + use mutex::*; + let buf = Arc::pin_init(CMutex::new(RingBuffer::::new())).unwrap(); let mut buf = buf.lock(); for _ in 0..63 { @@ -285,3 +286,18 @@ fn with_big_struct() { assert!(matches!(buf.as_mut().pop_no_stack(), Some(_))); } } + +#[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))] +#[test] +fn too_big_pinned() { + // should be too big with current hardware. + assert!(matches!( + Box::pin_init(RingBuffer::::new()), + Err(AllocError) + )); + // should be too big with current hardware. + assert!(matches!( + Arc::pin_init(RingBuffer::::new()), + Err(AllocError) + )); +} diff --git a/tests/ui.rs b/tests/ui.rs index 87039f9..ee4f640 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -1,4 +1,5 @@ -#[cfg_attr(not(any(miri, NO_UI_TESTS)), test)] +#[cfg(not(any(miri, NO_UI_TESTS)))] +#[test] fn compile_fail() { let test_cases = trybuild::TestCases::new(); test_cases.compile_fail("tests/ui/compile-fail/pinned_drop/*.rs"); @@ -7,7 +8,8 @@ fn compile_fail() { test_cases.compile_fail("tests/ui/compile-fail/zeroable/*.rs"); } -#[cfg_attr(not(any(miri, NO_UI_TESTS)), test)] +#[cfg(not(any(miri, NO_UI_TESTS)))] +#[test] fn expand() { macrotest::expand("tests/ui/expand/*.rs"); }