Skip to contentSkip to conversation

bindings: rust: fix clippy warnings

PATCH Applied Erik Wierich 3 participants 5 messages Jul 21, 2025 GPIO

lore
Share & tools
lore
#0 lore raw

cover bindings: rust: fix clippy warnings

This fixes warnings reported by clippy 0.1.88.

---
Erik Wierich (2):
bindings: rust: remove newline between attribute and attribute
bindings: rust: simplify format statements

 bindings/rust/libgpiod-sys/src/lib.rs                          | 1 -
 bindings/rust/libgpiod/examples/find_line_by_name.rs           | 2 +-
 bindings/rust/libgpiod/examples/get_line_info.rs               | 3 +--
 bindings/rust/libgpiod/examples/get_line_value.rs              | 2 +-
 bindings/rust/libgpiod/examples/get_multiple_line_values.rs    | 2 +-
 bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs | 4 ++--
 bindings/rust/libgpiod/examples/toggle_line_value.rs           | 2 +-
 bindings/rust/libgpiod/src/lib.rs                              | 4 ++--
 8 files changed, 9 insertions(+), 11 deletions(-)

---
base-commit: e4427590d9d63a7104dd5df564dd6b7b0c784547
change-id: 20250721-rust-clippy-df73580f6624

Best regards,

Signature · 1 line
Erik Wierich <[email protected]>
#1 lore raw

PATCH 1/2 bindings: rust: remove newline between attribute and attribute

These are block attributes, but the newline in between suggests that they are for the whole module.

Fixes clippy warning:

    warning: empty line after outer attribute
     --> libgpiod-sys/src/lib.rs:6:1
      |
    6 | / #[cfg_attr(test, allow(deref_nullptr, non_snake_case))]
    7 | |
      | |_^
    8 |   mod bindings_raw {
      |   ---------------- the attribute applies to this module
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr
      = note: `#[warn(clippy::empty_line_after_outer_attr)]` on by default
      = help: if the empty line is unintentional, remove it
    help: if the attribute should apply to the crate use an inner attribute
      |
    5 ~ #![allow(non_camel_case_types, non_upper_case_globals)]
    6 ~ #![cfg_attr(test, allow(deref_nullptr, non_snake_case))]
      |
---
 bindings/rust/libgpiod-sys/src/lib.rs | 1 -
 1 file changed, 1 deletion(-)
bindings/rust/libgpiod-sys/src/lib.rs +0 -1
index 06f1a50c2753048a22617c480396a156af801321..93b1e7683b0518b5777500d675c68db7184221aa 100644
@@ -1,11 +1,10 @@
 // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
 // SPDX-FileCopyrightText: 2022 Linaro Ltd.
 // SPDX-FileCopyrightText: 2022 Viresh Kumar <[email protected]>
 
 #[allow(non_camel_case_types, non_upper_case_globals)]
 #[cfg_attr(test, allow(deref_nullptr, non_snake_case))]
-
 mod bindings_raw {
     include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
 }
 pub use bindings_raw::*;
Signature · 1 line
2.50.0
#2 lore raw

PATCH 2/2 bindings: rust: simplify format statements

In reply to Erik Wierich

clippy suggested these:

    warning: variables can be used directly in the `format!` string
       --> libgpiod/src/lib.rs:113:9
        |
    113 |         write!(f, "{:?}", self)
        |         ^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
        = note: `#[warn(clippy::uninlined_format_args)]` on by default
    help: change this to
        |
    113 -         write!(f, "{:?}", self)
    113 +         write!(f, "{self:?}")
        |

Generated with cargo clippy --fix.

The suggestions look like an improvement to me.

---
 bindings/rust/libgpiod/examples/find_line_by_name.rs           | 2 +-
 bindings/rust/libgpiod/examples/get_line_info.rs               | 3 +--
 bindings/rust/libgpiod/examples/get_line_value.rs              | 2 +-
 bindings/rust/libgpiod/examples/get_multiple_line_values.rs    | 2 +-
 bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs | 4 ++--
 bindings/rust/libgpiod/examples/toggle_line_value.rs           | 2 +-
 bindings/rust/libgpiod/src/lib.rs                              | 4 ++--
 7 files changed, 9 insertions(+), 10 deletions(-)
bindings/rust/libgpiod/examples/find_line_by_name.rs +1 -1
index f7b991933b44c8bd107507a9a5322e4cf8bdc312..6d6a37b083efce4c61ecfb8c57292c4ee299466c 100644
@@ -20,10 +20,10 @@ fn main() -> libgpiod::Result<()> {
                 info.name()?,
                 offset?
             );
             return Ok(());
         }
     }
 
-    println!("line '{}' not found", line_name);
+    println!("line '{line_name}' not found");
     Ok(())
 }
bindings/rust/libgpiod/examples/get_line_info.rs +1 -2
index 086db90dbc1af97203ac54f3aa3abc108216cd19..7fb91a0cffaf5d7419722e9c503ab75cef44488a 100644
@@ -25,13 +25,12 @@ fn main() -> libgpiod::Result<()> {
     let low = if info.is_active_low() {
         "active-low"
     } else {
         "active-high"
     };
 
     println!(
-        "line {:>3}: {:>12} {:>12} {:>8} {:>10}",
-        line_offset, name, consumer, dir, low
+        "line {line_offset:>3}: {name:>12} {consumer:>12} {dir:>8} {low:>10}"
     );
 
     Ok(())
 }
bindings/rust/libgpiod/examples/get_line_value.rs +1 -1
index 39141e23363d6a026c0e5f748f72b1b8e5c583c6..e1ef6c7896c3671667119a256d14e930a291d532 100644
@@ -19,10 +19,10 @@ fn main() -> libgpiod::Result<()> {
     let mut rconfig = libgpiod::request::Config::new()?;
     rconfig.set_consumer("get-line-value")?;
 
     let chip = libgpiod::chip::Chip::open(&chip_path)?;
     let request = chip.request_lines(Some(&rconfig), &lconfig)?;
 
     let value = request.value(line_offset)?;
-    println!("{}={:?}", line_offset, value);
+    println!("{line_offset}={value:?}");
     Ok(())
 }
bindings/rust/libgpiod/examples/get_multiple_line_values.rs +1 -1
index a1be5a6e670b41534a65f7435d99185d832a894d..b09f3be033246c61cda43bd0e947ba34bb421642 100644
@@ -20,10 +20,10 @@ fn main() -> libgpiod::Result<()> {
 
     let mut rconfig = libgpiod::request::Config::new()?;
     rconfig.set_consumer("get-multiple-line-values")?;
 
     let request = chip.request_lines(Some(&rconfig), &lconfig)?;
     let values = request.values()?;
 
-    println!("{:?}", values);
+    println!("{values:?}");
     Ok(())
 }
bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs +2 -2
index fb5402bf88bf56c28f1c43f0e54ced22ed64f39e..b872d7709f3ecc651cf6d372cb46d6fbdfed77b1 100644
@@ -21,22 +21,22 @@ fn main() -> libgpiod::Result<()> {
 
     let chip = libgpiod::chip::Chip::open(&chip_path)?;
     // request the line initially as an input
     let mut request = chip.request_lines(Some(&rconfig), &lconfig)?;
 
     // read the current line value
     let value = request.value(line_offset)?;
-    println!("{}={:?} (input)", line_offset, value);
+    println!("{line_offset}={value:?} (input)");
 
     // switch the line to an output and drive it low
     let mut lsettings = line::Settings::new()?;
     lsettings.set_direction(line::Direction::Output)?;
     lsettings.set_output_value(line::Value::InActive)?;
     lconfig.add_line_settings(&[line_offset], lsettings)?;
     request.reconfigure_lines(&lconfig)?;
 
     // report the current driven value
     let value = request.value(line_offset)?;
-    println!("{}={:?} (output)", line_offset, value);
+    println!("{line_offset}={value:?} (output)");
 
     Ok(())
 }
bindings/rust/libgpiod/examples/toggle_line_value.rs +1 -1
index 6d5f697310e9977677975ab3202cad3975ffdc6f..bf87222acc87f559af1467c59b1b98b299755759 100644
@@ -30,13 +30,13 @@ fn main() -> libgpiod::Result<()> {
     let mut rconfig = libgpiod::request::Config::new()?;
     rconfig.set_consumer("toggle-line-value")?;
 
     let chip = libgpiod::chip::Chip::open(&chip_path)?;
     let mut req = chip.request_lines(Some(&rconfig), &lconfig)?;
 
     loop {
-        println!("{}={:?}", line_offset, value);
+        println!("{line_offset}={value:?}");
         std::thread::sleep(Duration::from_secs(1));
         value = toggle_value(value);
         req.set_value(line_offset, value)?;
     }
 }
bindings/rust/libgpiod/src/lib.rs +2 -2
index c03831bce62b287c08804e2d9d96aea7320dec7c..f4e511d535b70fbc01f91fa059921545b405656a 100644
@@ -106,15 +106,15 @@ pub enum OperationType {
     SimDevNew,
     SimDevEnable,
     SimDevDisable,
 }
 
 impl fmt::Display for OperationType {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{:?}", self)
+        write!(f, "{self:?}")
     }
 }
 
 /// Result of libgpiod operations.
 pub type Result<T> = std::result::Result<T, Error>;
 
 /// Error codes for libgpiod operations.
@@ -378,15 +378,15 @@ pub mod line {
         EventClock(EventClock),
         /// Output value.
         OutputValue(Value),
     }
 
     impl fmt::Display for SettingVal {
         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-            write!(f, "{:?}", self)
+            write!(f, "{self:?}")
         }
     }
 
     /// Event clock settings.
     #[derive(Copy, Clone, Debug, Eq, PartialEq)]
     pub enum EventClock {
         /// Line uses the monotonic clock for edge event timestamps.
Signature · 1 line
2.50.0
#4 lore raw
In reply to Erik Wierich

From: Bartosz Golaszewski <[email protected]>

Quoted 3 lines · Erik Wierich

This fixes warnings reported by clippy 0.1.88.

Applied, thanks!

[1/2] bindings: rust: remove newline between attribute and attribute

      commit: b20401360ce35fabc123c379ab3fddb394ee467e
[2/2] bindings: rust: simplify format statements
      commit: 6263abf3abb6fcdb4b85745664a7bb3c1d3c4f8c

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>