Repository: hannobraun/inotify-rs (language: rust)

Issue:
Consider using cargo clippy in test workflows
Clippy adds quite a few interesting lints that may be useful to have.

At the moment running clippy has 4 errors, mostly redundant field names in initialization. Clippy does also handle things such as warning you about unnecessary clones, redundant borrows on an already borrowed field, etc.


Discussion / hints:
Thank you for opening this issue, @i509VCB. I'm all for that! It's just an issue of someone doing the work, i.e. adding Clippy to the CI build and fixing the existing warnings.

Pull requests welcome!

Fix patch:
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 448b9ed..76355ff 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -12,15 +12,20 @@ jobs:
     - name: Install rust
       uses: actions-rs/toolchain@v1
       with:
-        toolchain: 1.47.0
+        toolchain: 1.49.0
         override: true
+        components: clippy
     - name: Check rust and cargo version
       run: rustc -V && cargo -V
     - name: Build
       run: cargo build --verbose
     - name: Run tests
       run: cargo test --verbose
+    - name: Run Clippy lints
+      run: cargo clippy --verbose -- -D warnings
     - name: Build (no default features)
       run: cargo build --verbose --no-default-features
     - name: Run tests (no default features)
       run: cargo test --verbose --no-default-features
+    - name: Run Clippy lints (no default features)
+      run: cargo clippy --verbose --no-default-features -- -D warnings
diff --git a/src/events.rs b/src/events.rs
index 2c5e010..5b3b44e 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -35,10 +35,10 @@ impl<'a> Events<'a> {
         -> Self
     {
         Events {
-            fd       : fd,
-            buffer   : buffer,
-            num_bytes: num_bytes,
-            pos      : 0,
+            fd,
+            buffer,
+            num_bytes,
+            pos: 0,
         }
     }
 }
@@ -118,7 +118,7 @@ impl<'a> Event<&'a OsStr> {
             fd,
         };
 
-        let name = if name == "" {
+        let name = if name.is_empty() {
             None
         }
         else {
@@ -206,8 +206,15 @@ impl<'a> Event<&'a OsStr> {
     }
 
     /// Returns an owned copy of the event.
-    #[must_use = "cloning is often expensive and is not expected to have side effects"]
+    #[deprecated = "use `to_owned()` instead; methods named `into_owned()` usually take self by value"]
+    #[allow(clippy::wrong_self_convention)]
     pub fn into_owned(&self) -> EventOwned {
+        self.to_owned()
+    }
+
+    /// Returns an owned copy of the event.
+    #[must_use = "cloning is often expensive and is not expected to have side effects"]
+    pub fn to_owned(&self) -> EventOwned {
         Event {
             wd: self.wd.clone(),
             mask: self.mask,
diff --git a/src/stream.rs b/src/stream.rs
index bad0ec1..7576738 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -34,7 +34,7 @@ where
     pub(crate) fn new(fd: Arc<FdGuard>, buffer: T) -> io::Result<Self> {
         Ok(EventStream {
             fd: AsyncFd::new(ArcFdGuard(fd))?,
-            buffer: buffer,
+            buffer,
             buffer_pos: 0,
             unused_bytes: 0,
         })
@@ -73,7 +73,7 @@ where
         self_.buffer_pos += bytes_consumed;
         self_.unused_bytes -= bytes_consumed;
 
-        Poll::Ready(Some(Ok(event.into_owned())))
+        Poll::Ready(Some(Ok(event.to_owned())))
     }
 }
 


Test patch: