Skip to content
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

Fix Clippy warnings #1696

Merged
merged 7 commits into from
Jul 26, 2023
Merged
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
5 changes: 2 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
freebsd_instance:
image: freebsd-12-2-release-amd64
image: freebsd-12-4-release-amd64

env:
RUST_BACKTRACE: full

task:
name: FreeBSD
setup_script:
- pkg install -y curl
- curl https://sh.rustup.rs -sSf --output rustup.sh
- fetch https://sh.rustup.rs -o rustup.sh
- sh rustup.sh -y --profile minimal
cargo_cache:
folder: $HOME/.cargo/registry
Expand Down
130 changes: 130 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: CI
on:
push:
branches: [ "master", "v0.7.x" ]
pull_request:
branches: [ "master", "v0.7.x" ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
CI: true

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
Test:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install Cargo-hack
run: cargo install --debug cargo-hack
- name: Check all features
run: cargo hack check --feature-powerset
- name: Tests
run: cargo test --all-features
- name: Tests release build
run: cargo test --release --all-features
MinimalVersions:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- name: Install minimal verions
run: cargo update -Zminimal-versions
- name: Tests
run: cargo test --all-features
MSRV:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
# NOTE: When updating also update Clippy flags, some are disabled due to
# MSRV.
toolchain: 1.46.0
- name: Check
# We only run check allowing us to use newer features in tests.
# We enable all features except for the `log` feature as since log v0.4.19
# it requires a MSRV later then rustc 1.46.
run: cargo check --no-default-features --features os-poll,os-ext,net
Nightly:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- name: Tests
run: cargo test --all-features
Clippy:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Clippy
# NOTE: `clippy::uninlined-format-args` is enabled due to MSRV.
run: cargo clippy --all-features -- -D warnings -A clippy::cognitive-complexity -A clippy::uninlined-format-args
Docs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Check docs
run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
Rustfmt:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting
# FIXME: for some reason this doesn't actually check all files.
# So instead we run `rustfmt` directly on each file.
#cargo fmt --all -- --check
run: find src tests examples -type f -iname "*.rs" | xargs rustfmt --check
CheckTargets:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install all targets
run: make install_targets
- name: Install Cargo-hack
run: cargo install --debug cargo-hack
- name: Check all targets
run: make check_all_targets
# Single job required to merge the pr.
Passed:
runs-on: ubuntu-latest
needs:
- Test
- MinimalVersions
- MSRV
- Nightly
- Clippy
- Docs
- Rustfmt
- CheckTargets
steps:
- run: exit 0
6 changes: 3 additions & 3 deletions src/event/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
token: Token,
interests: Interest,
) -> io::Result<()> {
(&mut **self).register(registry, token, interests)
(**self).register(registry, token, interests)
}

fn reregister(
Expand All @@ -130,10 +130,10 @@ where
token: Token,
interests: Interest,
) -> io::Result<()> {
(&mut **self).reregister(registry, token, interests)
(**self).reregister(registry, token, interests)
}

fn deregister(&mut self, registry: &Registry) -> io::Result<()> {
(&mut **self).deregister(registry)
(**self).deregister(registry)
}
}
2 changes: 1 addition & 1 deletion src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl fmt::Debug for Interest {
one = true
}
}
#[cfg(any(target_os = "freebsd"))]
#[cfg(target_os = "freebsd")]
{
if self.is_lio() {
if one {
Expand Down
6 changes: 3 additions & 3 deletions src/io_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl SelectorId {
/// Associate an I/O source with `registry`, returning an error if its
/// already registered.
fn associate(&self, registry: &Registry) -> io::Result<()> {
let registry_id = poll::selector(&registry).id();
let registry_id = poll::selector(registry).id();
let previous_id = self.id.swap(registry_id, Ordering::AcqRel);

if previous_id == Self::UNASSOCIATED {
Expand All @@ -247,7 +247,7 @@ impl SelectorId {
/// error if its registered with a different `Registry` or not registered at
/// all.
fn check_association(&self, registry: &Registry) -> io::Result<()> {
let registry_id = poll::selector(&registry).id();
let registry_id = poll::selector(registry).id();
let id = self.id.load(Ordering::Acquire);

if id == registry_id {
Expand All @@ -268,7 +268,7 @@ impl SelectorId {
/// Remove a previously made association from `registry`, returns an error
/// if it was not previously associated with `registry`.
fn remove_association(&self, registry: &Registry) -> io::Result<()> {
let registry_id = poll::selector(&registry).id();
let registry_id = poll::selector(registry).id();
let previous_id = self.id.swap(Self::UNASSOCIATED, Ordering::AcqRel);

if previous_id == registry_id {
Expand Down
2 changes: 1 addition & 1 deletion src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! [portability guidelines]: ../struct.Poll.html#portability

mod tcp;
pub use self::tcp::{TcpListener, TcpSocket, TcpStream, TcpKeepalive};
pub use self::tcp::{TcpKeepalive, TcpListener, TcpSocket, TcpStream};

mod udp;
pub use self::udp::UdpSocket;
Expand Down
2 changes: 1 addition & 1 deletion src/net/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod listener;
pub use self::listener::TcpListener;

mod socket;
pub use self::socket::{TcpSocket, TcpKeepalive};
pub use self::socket::{TcpKeepalive, TcpSocket};

mod stream;
pub use self::stream::TcpStream;
1 change: 1 addition & 0 deletions src/net/tcp/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct TcpSocket {

/// Configures a socket's TCP keepalive parameters.
#[derive(Debug, Default, Clone)]
#[allow(dead_code)]
pub struct TcpKeepalive {
pub(crate) time: Option<Duration>,
#[cfg(any(
Expand Down
20 changes: 10 additions & 10 deletions src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,49 +174,49 @@ impl TcpStream {

impl Read for TcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read(buf))
self.inner.do_io(|mut inner| inner.read(buf))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read_vectored(bufs))
self.inner.do_io(|mut inner| inner.read_vectored(bufs))
}
}

impl<'a> Read for &'a TcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read(buf))
self.inner.do_io(|mut inner| inner.read(buf))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read_vectored(bufs))
self.inner.do_io(|mut inner| inner.read_vectored(bufs))
}
}

impl Write for TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write(buf))
self.inner.do_io(|mut inner| inner.write(buf))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write_vectored(bufs))
self.inner.do_io(|mut inner| inner.write_vectored(bufs))
}

fn flush(&mut self) -> io::Result<()> {
self.inner.do_io(|inner| (&*inner).flush())
self.inner.do_io(|mut inner| inner.flush())
}
}

impl<'a> Write for &'a TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write(buf))
self.inner.do_io(|mut inner| inner.write(buf))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write_vectored(bufs))
self.inner.do_io(|mut inner| inner.write_vectored(bufs))
}

fn flush(&mut self) -> io::Result<()> {
self.inner.do_io(|inner| (&*inner).flush())
self.inner.do_io(|mut inner| inner.flush())
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/net/uds/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,49 +73,49 @@ impl UnixStream {

impl Read for UnixStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read(buf))
self.inner.do_io(|mut inner| inner.read(buf))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read_vectored(bufs))
self.inner.do_io(|mut inner| inner.read_vectored(bufs))
}
}

impl<'a> Read for &'a UnixStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read(buf))
self.inner.do_io(|mut inner| inner.read(buf))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).read_vectored(bufs))
self.inner.do_io(|mut inner| inner.read_vectored(bufs))
}
}

impl Write for UnixStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write(buf))
self.inner.do_io(|mut inner| inner.write(buf))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write_vectored(bufs))
self.inner.do_io(|mut inner| inner.write_vectored(bufs))
}

fn flush(&mut self) -> io::Result<()> {
self.inner.do_io(|inner| (&*inner).flush())
self.inner.do_io(|mut inner| inner.flush())
}
}

impl<'a> Write for &'a UnixStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write(buf))
self.inner.do_io(|mut inner| inner.write(buf))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.do_io(|inner| (&*inner).write_vectored(bufs))
self.inner.do_io(|mut inner| inner.write_vectored(bufs))
}

fn flush(&mut self) -> io::Result<()> {
self.inner.do_io(|inner| (&*inner).flush())
self.inner.do_io(|mut inner| inner.flush())
}
}

Expand Down
Loading