diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fa27d5b..60d314d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,19 +13,23 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build run: cargo build --verbose - name: Run tests run: cargo test --verbose - - name: Run tests (gecko-ffi) - run: cargo test --tests --verbose + - name: Run miniserde tests + run: cargo test --features miniserde --verbose + - name: Run nanoserde tests + run: cargo test --features nanoserde --verbose + - name: Run borsh tests + run: cargo test --features borsh --verbose miri: name: "Miri" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Miri run: | rustup toolchain install nightly --component miri @@ -37,51 +41,69 @@ jobs: fmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal components: rustfmt - override: true - - uses: actions-rs/cargo@v1 + - run: cargo fmt --all -- --check + + msrv: + name: Rust ${{matrix.rust}} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: [1.11.0, 1.12.0] + timeout-minutes: 45 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - command: fmt - args: --all -- --check - - + toolchain: ${{matrix.rust}} + - run: cargo build + - run: cargo test + + msrv-serde: + name: Rust ${{matrix.rust}} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: [1.31.0, 1.32.0] + timeout-minutes: 45 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + - run: cargo build + - run: cargo test + - run: cargo test --features serde + - run: cargo test --features miniserde + - run: cargo test --features nanoserde + clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal components: clippy - override: true - - uses: actions-rs/clippy-check@v1 - env: - PWD: ${{ env.GITHUB_WORKSPACE }} - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --workspace --tests --examples - - + - run: cargo clippy --workspace --tests --examples + - run: cargo clippy --workspace --tests --examples --features serde + - run: cargo clippy --workspace --tests --examples --features miniserde + - run: cargo clippy --workspace --tests --examples --features nanoserde + docs: runs-on: ubuntu-latest env: RUSTDOCFLAGS: -Dwarnings steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal - components: rust-docs - override: true - - uses: swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: doc - args: --workspace --no-deps + - uses: swatinem/rust-cache@v2 + - run: cargo doc --workspace --no-deps diff --git a/Cargo.toml b/Cargo.toml index 1c443c5..e53dea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,10 @@ documentation = "https://docs.rs/bit-vec/" keywords = ["data-structures", "bitvec", "bitmask", "bitmap", "bit"] readme = "README.md" edition = "2015" +rust-version = "1.11.0" [dependencies] -borsh = { version = "1.5", default-features = false, features = ["derive"], optional = true } +borsh = { version = "1.5.5", default-features = false, features = ["derive"], optional = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } miniserde = { version = "0.1", optional = true } nanoserde = { version = "0.1", optional = true } diff --git a/README.md b/README.md index 2d69953..c4f113e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![crates.io][crates.io shield]][crates.io link] [![Documentation][docs.rs badge]][docs.rs link] ![Rust CI][github ci badge] -[![rustc 1.0+]][Rust 1.0] +[![rustc 1.11+]][Rust 1.11] [![serde_derive: rustc 1.31+]][Rust 1.31]

@@ -22,8 +22,8 @@ [crates.io link]: https://crates.io/crates/bit-vec [docs.rs badge]: https://docs.rs/bit-vec/badge.svg?version=0.8.0 [docs.rs link]: https://docs.rs/bit-vec/0.8.0/bit_vec/ -[github ci badge]: https://github.com/contain-rs/linked-hash-map/workflows/Rust/badge.svg?branch=master -[rustc 1.0+]: https://img.shields.io/badge/rustc-1.0%2B-blue.svg +[github ci badge]: https://github.com/contain-rs/bit-vec/workflows/Rust/badge.svg?branch=master +[rustc 1.11+]: https://img.shields.io/badge/rustc-1.11%2B-blue.svg [serde_derive: rustc 1.31+]: https://img.shields.io/badge/serde_derive-rustc_1.31+-lightgray.svg [Rust 1.0]: https://blog.rust-lang.org/2015/05/15/Rust-1.0.html [Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html diff --git a/crusader.sh b/crusader.sh deleted file mode 100755 index 8becfed..0000000 --- a/crusader.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -git clone https://github.com/brson/cargo-crusader -cd cargo-crusader -cargo build --release -export PATH=$PATH:`pwd`/target/release/ -cd ../ - -cargo crusader - -exit diff --git a/src/lib.rs b/src/lib.rs index d5b540a..1d8f477 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,13 @@ #![doc(html_root_url = "https://docs.rs/bit-vec/0.8.0")] #![no_std] +#![deny(clippy::shadow_reuse)] +#![deny(clippy::shadow_same)] +#![deny(clippy::shadow_unrelated)] +#![warn(clippy::multiple_inherent_impl)] +#![warn(clippy::multiple_crate_versions)] +#![warn(clippy::single_match)] +#![warn(clippy::missing_safety_doc)] #[cfg(any(test, feature = "std"))] #[macro_use] @@ -305,7 +312,9 @@ impl BitVec { pub fn new() -> Self { Default::default() } +} +impl BitVec { /// Creates a `BitVec` that holds `nbits` elements, setting each element /// to `bit`. /// @@ -1888,11 +1897,10 @@ pub struct IterMut<'a, B: 'a + BitBlock = u32> { impl<'a, B: 'a + BitBlock> IterMut<'a, B> { fn get(&mut self, index: Option) -> Option> { - let index = index?; - let value = (*self.vec).borrow().get(index)?; + let value = (*self.vec).borrow().get(index?)?; Some(MutBorrowedBit { vec: self.vec.clone(), - index, + index: index?, #[cfg(debug_assertions)] old_value: value, new_value: value, @@ -1900,7 +1908,7 @@ impl<'a, B: 'a + BitBlock> IterMut<'a, B> { } } -impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> { +impl Deref for MutBorrowedBit<'_, B> { type Target = bool; fn deref(&self) -> &Self::Target { @@ -1908,13 +1916,13 @@ impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> { } } -impl<'a, B: BitBlock> DerefMut for MutBorrowedBit<'a, B> { +impl DerefMut for MutBorrowedBit<'_, B> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.new_value } } -impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> { +impl Drop for MutBorrowedBit<'_, B> { fn drop(&mut self) { let mut vec = (*self.vec).borrow_mut(); #[cfg(debug_assertions)] @@ -1927,7 +1935,7 @@ impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Iter<'a, B> { +impl Iterator for Iter<'_, B> { type Item = bool; #[inline] @@ -1956,14 +1964,14 @@ impl<'a, B: BitBlock> Iterator for IterMut<'a, B> { } } -impl<'a, B: BitBlock> DoubleEndedIterator for Iter<'a, B> { +impl DoubleEndedIterator for Iter<'_, B> { #[inline] fn next_back(&mut self) -> Option { self.range.next_back().map(|i| self.bit_vec.get(i).unwrap()) } } -impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> { +impl DoubleEndedIterator for IterMut<'_, B> { #[inline] fn next_back(&mut self) -> Option { let index = self.range.next_back(); @@ -1971,9 +1979,9 @@ impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> { } } -impl<'a, B: BitBlock> ExactSizeIterator for Iter<'a, B> {} +impl ExactSizeIterator for Iter<'_, B> {} -impl<'a, B: BitBlock> ExactSizeIterator for IterMut<'a, B> {} +impl ExactSizeIterator for IterMut<'_, B> {} impl<'a, B: BitBlock> IntoIterator for &'a BitVec { type Item = bool; @@ -2028,7 +2036,7 @@ pub struct Blocks<'a, B: 'a> { iter: slice::Iter<'a, B>, } -impl<'a, B: BitBlock> Iterator for Blocks<'a, B> { +impl Iterator for Blocks<'_, B> { type Item = B; #[inline] @@ -2042,17 +2050,21 @@ impl<'a, B: BitBlock> Iterator for Blocks<'a, B> { } } -impl<'a, B: BitBlock> DoubleEndedIterator for Blocks<'a, B> { +impl DoubleEndedIterator for Blocks<'_, B> { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().cloned() } } -impl<'a, B: BitBlock> ExactSizeIterator for Blocks<'a, B> {} +impl ExactSizeIterator for Blocks<'_, B> {} #[cfg(test)] mod tests { + #![allow(clippy::shadow_reuse)] + #![allow(clippy::shadow_same)] + #![allow(clippy::shadow_unrelated)] + use super::{BitVec, Iter, Vec}; // This is stupid, but I want to differentiate from a "random" 32