From 4985c83b2372d1cd2ed87b7330df3151a8246820 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sat, 29 Jan 2022 13:40:51 +0100 Subject: [PATCH] clippy: Add more restrictive lint directives --- .github/workflows/pre-commit.yaml | 22 +++++++++++++++++++++- .github/workflows/security_audit.yaml | 1 - src/frame/mod.rs | 4 ++-- src/lib.rs | 17 +++++++++++++++++ src/server/rtu.rs | 1 + src/service/rtu.rs | 14 +++++++++----- src/slave.rs | 2 +- 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 101f4b91..29a73a6a 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - master + - '*' env: CARGO_TERM_COLOR: always @@ -28,6 +28,11 @@ jobs: profile: minimal components: rustfmt, clippy + - name: Generate Cargo.lock + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + - name: Detect code style issues (push) uses: pre-commit/action@v2.0.3 if: github.event_name == 'push' @@ -37,3 +42,18 @@ jobs: if: github.event_name == 'pull_request' env: SKIP: no-commit-to-branch + + - name: Generate patch file + if: failure() + run: | + git diff-index -p HEAD > "${PATCH_FILE}" + [ -s "${PATCH_FILE}" ] && echo "UPLOAD_PATCH_FILE=${PATCH_FILE}" >> "${GITHUB_ENV}" + env: + PATCH_FILE: pre-commit.patch + + - name: Upload patch artifact + if: failure() && env.UPLOAD_PATCH_FILE != null + uses: actions/upload-artifact@v2 + with: + name: ${{ env.UPLOAD_PATCH_FILE }} + path: ${{ env.UPLOAD_PATCH_FILE }} diff --git a/.github/workflows/security_audit.yaml b/.github/workflows/security_audit.yaml index 8a7f5260..7a0f5c2c 100644 --- a/.github/workflows/security_audit.yaml +++ b/.github/workflows/security_audit.yaml @@ -3,7 +3,6 @@ on: push: paths: - '**/Cargo.toml' - - '**/Cargo.lock' # schedule: # - cron: '0 0 * * *' diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 927110a5..a620fac1 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -236,7 +236,7 @@ impl From for Result { } impl fmt::Display for Exception { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.description()) } } @@ -248,7 +248,7 @@ impl error::Error for Exception { } impl fmt::Display for ExceptionResponse { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Modbus function {}: {}", self.function, self.exception) } } diff --git a/src/lib.rs b/src/lib.rs index 65d78885..c0636fc1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -141,6 +141,23 @@ //! - [MODBUS over serial line specification and implementation guide v1.02 (PDF)](http://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf) //! - [MODBUS Messaging on TCP/IP Implementation Guide v1.0b (PDF)](http://modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf) +#![deny(rust_2018_idioms)] +#![deny(rust_2021_compatibility)] +#![deny(missing_debug_implementations)] +// TODO: Add missing documentation +//#![deny(missing_docs)] +#![deny(rustdoc::broken_intra_doc_links)] +#![deny(clippy::all)] +#![deny(clippy::explicit_deref_methods)] +#![deny(clippy::explicit_into_iter_loop)] +#![deny(clippy::explicit_iter_loop)] +// TODO (v0.6): Decorate functions with #[must_use] +//#![deny(clippy::must_use_candidate)] +#![cfg_attr(not(test), warn(unsafe_code))] +#![cfg_attr(not(test), deny(clippy::panic_in_result_fn))] +#![cfg_attr(not(debug_assertions), deny(warnings))] +#![cfg_attr(not(debug_assertions), deny(clippy::used_underscore_binding))] + pub mod prelude; pub mod client; diff --git a/src/server/rtu.rs b/src/server/rtu.rs index 10cee412..6041b8d4 100644 --- a/src/server/rtu.rs +++ b/src/server/rtu.rs @@ -13,6 +13,7 @@ use std::{io::Error, path::Path}; use tokio_serial::SerialStream; use tokio_util::codec::Framed; +#[derive(Debug)] pub struct Server { serial: SerialStream, } diff --git a/src/service/rtu.rs b/src/service/rtu.rs index 82ca7b81..b31b5d39 100644 --- a/src/service/rtu.rs +++ b/src/service/rtu.rs @@ -116,23 +116,27 @@ mod tests { impl AsyncRead for MockTransport { fn poll_read( self: Pin<&mut Self>, - _: &mut Context, - _: &mut ReadBuf, + _: &mut Context<'_>, + _: &mut ReadBuf<'_>, ) -> Poll> { Poll::Ready(Ok(())) } } impl AsyncWrite for MockTransport { - fn poll_write(self: Pin<&mut Self>, _: &mut Context, _: &[u8]) -> Poll> { + fn poll_write( + self: Pin<&mut Self>, + _: &mut Context<'_>, + _: &[u8], + ) -> Poll> { Poll::Ready(Ok(2)) } - fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } - fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context) -> Poll> { + fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { unimplemented!() } } diff --git a/src/slave.rs b/src/slave.rs index 94b57ea5..21f3d52a 100644 --- a/src/slave.rs +++ b/src/slave.rs @@ -83,7 +83,7 @@ impl FromStr for Slave { } impl fmt::Display for Slave { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} (0x{:0>2X})", self.0, self.0) } }