Skip to content

Enable some clippy lints #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 57 additions & 35 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
<br />
<br />
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions crusader.sh

This file was deleted.

40 changes: 26 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -305,7 +312,9 @@ impl BitVec<u32> {
pub fn new() -> Self {
Default::default()
}
}

impl BitVec<u32> {
/// Creates a `BitVec` that holds `nbits` elements, setting each element
/// to `bit`.
///
Expand Down Expand Up @@ -1888,33 +1897,32 @@ pub struct IterMut<'a, B: 'a + BitBlock = u32> {

impl<'a, B: 'a + BitBlock> IterMut<'a, B> {
fn get(&mut self, index: Option<usize>) -> Option<MutBorrowedBit<'a, B>> {
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,
})
}
}

impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> {
impl<B: BitBlock> Deref for MutBorrowedBit<'_, B> {
type Target = bool;

fn deref(&self) -> &Self::Target {
&self.new_value
}
}

impl<'a, B: BitBlock> DerefMut for MutBorrowedBit<'a, B> {
impl<B: BitBlock> 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<B: BitBlock> Drop for MutBorrowedBit<'_, B> {
fn drop(&mut self) {
let mut vec = (*self.vec).borrow_mut();
#[cfg(debug_assertions)]
Expand All @@ -1927,7 +1935,7 @@ impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> {
}
}

impl<'a, B: BitBlock> Iterator for Iter<'a, B> {
impl<B: BitBlock> Iterator for Iter<'_, B> {
type Item = bool;

#[inline]
Expand Down Expand Up @@ -1956,24 +1964,24 @@ impl<'a, B: BitBlock> Iterator for IterMut<'a, B> {
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for Iter<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for Iter<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<bool> {
self.range.next_back().map(|i| self.bit_vec.get(i).unwrap())
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for IterMut<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
let index = self.range.next_back();
self.get(index)
}
}

impl<'a, B: BitBlock> ExactSizeIterator for Iter<'a, B> {}
impl<B: BitBlock> ExactSizeIterator for Iter<'_, B> {}

impl<'a, B: BitBlock> ExactSizeIterator for IterMut<'a, B> {}
impl<B: BitBlock> ExactSizeIterator for IterMut<'_, B> {}

impl<'a, B: BitBlock> IntoIterator for &'a BitVec<B> {
type Item = bool;
Expand Down Expand Up @@ -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<B: BitBlock> Iterator for Blocks<'_, B> {
type Item = B;

#[inline]
Expand All @@ -2042,17 +2050,21 @@ impl<'a, B: BitBlock> Iterator for Blocks<'a, B> {
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for Blocks<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for Blocks<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<B> {
self.iter.next_back().cloned()
}
}

impl<'a, B: BitBlock> ExactSizeIterator for Blocks<'a, B> {}
impl<B: BitBlock> 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
Expand Down
Loading