diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e33e713..6747865 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,24 +8,13 @@ jobs: steps: - uses: actions/checkout@master - - uses: actions-rs/toolchain@v1 - name: Install Rust - with: - profile: minimal - toolchain: stable - override: true - - name: Build - run: RUSTFLAGS="-D warnings" cargo build --verbose --all-targets --all-features - - name: Run tests - run: make test - - name: Build Documentation - run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps - - name: Run rustfmt - run: cargo fmt -- --check - - name: Run clippy + - name: Install rust run: | - cargo clippy --all-targets --all-features -- --deny warnings - RUSTFLAGS='--cfg loom' cargo clippy --all-targets --all-features -- --deny warnings + rustup install nightly + rustup component add --toolchain nightly miri + rustup show + - name: Run tests + run: make ci - name: Deploy Docs uses: peaceiris/actions-gh-pages@v3 with: diff --git a/Cargo.toml b/Cargo.toml index e139b06..cd59440 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["development-tools", "embedded"] rust-version = "1.79" [target.'cfg(loom)'.dependencies] -loom = "0.5" +loom = "0.7" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ["cfg(loom)"] } diff --git a/Makefile b/Makefile index 35e416b..4ff93e7 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,24 @@ -.PHONY= test, clippy +.PHONY= test, clippy, test-miri, lint test: cargo t RUSTFLAGS='--cfg loom' cargo t loom +test-miri: + cargo +nightly miri test + +check-fmt: + cargo fmt -- --check + clippy: cargo clippy --all-targets --all-features RUSTFLAGS='--cfg loom' cargo clippy --all-targets --all-features + +lint: + cargo clippy --all-targets + cargo clippy --all-targets --all-features + cargo doc --all-features --no-deps + cargo fmt --check + RUSTFLAGS="$(RUSTFLAGS) --cfg loom" cargo clippy --all-targets --all-features + +ci: test test-miri lint diff --git a/src/lib.rs b/src/lib.rs index 5b34126..8386080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -994,15 +994,10 @@ impl<'alloc, Rq, Rp> InterchangeRef<'alloc, Rq, Rp> { let index = self.last_claimed.fetch_add(1, Ordering::Relaxed); let n = self.channels.len(); - for i in (index % n)..n { - let tmp = self.channels[i].split(); - if tmp.is_some() { - return tmp; - } - } + let (channels_start, channels_end) = self.channels.split_at(index % n); - for i in 0..(index % n) { - let tmp = self.channels[i].split(); + for channel in channels_end.iter().chain(channels_start) { + let tmp = channel.split(); if tmp.is_some() { return tmp; } diff --git a/tests/loom.rs b/tests/loom.rs index d944980..63f4c17 100644 --- a/tests/loom.rs +++ b/tests/loom.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + #[cfg(loom)] use loom::thread; #[cfg(not(loom))] @@ -29,6 +31,8 @@ fn loom_interchange() { // This is tested even with the standard library to ensure that the Send/Sync traits are implemented as necessary // Loom's thread::spawn doesn't require the function to be `Send` +// +// miri doesn't like the box being dropped. #[cfg_attr(not(loom), test)] fn test_function() { // thread closures must be 'static