bindings: rust: clippy: fix warnings
v2 cover bindings: rust: clippy: fix warnings
This follows up on my promise on Kent's series [1] to look into whether these casts are needed or not. Most are not, a few are false-positives.
I also explored some shunit2 based test-script to automate the testing, but that became ugly with linking issue and needs me to revisit it another time. So this only sends the clippy fixes for now.
Tested the build (lib + examples + test) and clippy report on:
- Fedora 38 x86_64
- Fedora 38 aarch64
- Debian 12 armv7hf
Test execution (cargo test) was tested on:
- Fedora 38 x86_64
- Fedora 38 aarch64
Could not execute tests on armv7hf due to lack of suitable test environment.
[1] https://lore.kernel.org/r/[email protected]
To: Linux-GPIO <[email protected]>
Cc: Kent Gibson <[email protected]>
Cc: Viresh Kumar <[email protected]>
---
Changes in v2:
- Changed cover letter title to active language
- Improved commit messages (hopefully)
- Elaborated what was built and tested
- Resent with hacked b4 for proper [libgpiod] tag
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Erik Schilling (4):
bindings: rust: clippy: drop unnecessary casts
bindings: rust: clippy: silence false-positives on casts
bindings: rust: clippy: drop unneeded conversions
bindings: rust: clippy: silence false-positive on iterator
bindings/rust/gpiosim-sys/src/lib.rs | 2 +- bindings/rust/gpiosim-sys/src/sim.rs | 4 ++-- bindings/rust/libgpiod/src/chip.rs | 2 +- bindings/rust/libgpiod/src/edge_event.rs | 2 +- bindings/rust/libgpiod/src/event_buffer.rs | 7 +++++-- bindings/rust/libgpiod/src/info_event.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 2 +- bindings/rust/libgpiod/src/line_config.rs | 4 ++-- bindings/rust/libgpiod/src/line_info.rs | 3 +++ bindings/rust/libgpiod/src/line_request.rs | 8 ++++---- bindings/rust/libgpiod/src/line_settings.rs | 5 ++++- bindings/rust/libgpiod/src/request_config.rs | 2 +- bindings/rust/libgpiod/tests/chip.rs | 2 +- 13 files changed, 27 insertions(+), 18 deletions(-)
---
base-commit: 4510231c95a087f58a155cf74164e403e1e0584f
change-id: 20230629-clippy-890c541c6d09
Best regards,
Signature · 1 line
Erik Schilling <[email protected]>
PATCH v2 1/4 bindings: rust: clippy: drop unnecessary casts
Fixes clippy warnings on these lines.
Applied the suggested fix using:
cargo clippy --fix
clippy version: clippy 0.1.70 (90c5418 2023-05-31).
--- bindings/rust/gpiosim-sys/src/lib.rs | 2 +- bindings/rust/gpiosim-sys/src/sim.rs | 2 +- bindings/rust/libgpiod/src/chip.rs | 2 +- bindings/rust/libgpiod/src/edge_event.rs | 2 +- bindings/rust/libgpiod/src/event_buffer.rs | 2 +- bindings/rust/libgpiod/src/info_event.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 2 +- bindings/rust/libgpiod/src/line_config.rs | 4 ++-- bindings/rust/libgpiod/src/line_request.rs | 8 ++++---- bindings/rust/libgpiod/src/line_settings.rs | 2 +- bindings/rust/libgpiod/src/request_config.rs | 2 +- bindings/rust/libgpiod/tests/chip.rs | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-)
bindings/rust/gpiosim-sys/src/lib.rs +1 -1
@@ -46,7 +46,7 @@ impl Value { errno::errno(), )) } - _ => return Err(Error::InvalidEnumValue("Value", val as i32)), + _ => return Err(Error::InvalidEnumValue("Value", val)), }) } }
bindings/rust/gpiosim-sys/src/sim.rs +1 -1
@@ -164,7 +164,7 @@ impl SimBank { errno::errno(), )) }else { -Value ::new (retas i32 ) +Value ::new (ret) } }
bindings/rust/libgpiod/src/chip.rs +1 -1
@@ -279,7 +279,7 @@ impl Info {/// Get the number of GPIO lines exposed by the chip. pub fn num_lines (&self) ->usize {// SAFETY: `gpiod_chip` is guaranteed to be valid here. -unsafe { gpiod::gpiod_chip_info_get_num_lines (self.info)as usize } +unsafe { gpiod::gpiod_chip_info_get_num_lines (self.info) } } }
bindings/rust/libgpiod/src/edge_event.rs +1 -1
@@ -41,7 +41,7 @@ impl Event {/// Get the event type. pub fn event_type (&self) ->Result <EdgeKind > {// SAFETY: `gpiod_edge_event` is guaranteed to be valid here. -EdgeKind ::new (unsafe { gpiod::gpiod_edge_event_get_event_type (self.0 ) }as u32 ) +EdgeKind ::new (unsafe { gpiod::gpiod_edge_event_get_event_type (self.0 ) }) }/// Get the timestamp of the event.
bindings/rust/libgpiod/src/event_buffer.rs +1 -1
@@ -82,7 +82,7 @@ impl Buffer { }// SAFETY: `gpiod_edge_event_buffer` is guaranteed to be valid here. -let capacity =unsafe { gpiod::gpiod_edge_event_buffer_get_capacity (buffer)as usize }; +let capacity =unsafe { gpiod::gpiod_edge_event_buffer_get_capacity (buffer) };Ok (Self { buffer,
bindings/rust/libgpiod/src/info_event.rs +1 -1
@@ -34,7 +34,7 @@ impl Event {/// Get the event type of the status change event. pub fn event_type (&self) ->Result <InfoChangeKind > {// SAFETY: `gpiod_info_event` is guaranteed to be valid here. -InfoChangeKind ::new (unsafe { gpiod::gpiod_info_event_get_event_type (self.event) }as u32 ) +InfoChangeKind ::new (unsafe { gpiod::gpiod_info_event_get_event_type (self.event) }) }/// Get the timestamp of the event, read from the monotonic clock.
bindings/rust/libgpiod/src/lib.rs +1 -1
@@ -193,7 +193,7 @@ pub mod line { errno::errno(), )) } - _ => return Err(Error::InvalidEnumValue("Value", val as i32)), + _ => return Err(Error::InvalidEnumValue("Value", val)), }) }
bindings/rust/libgpiod/src/line_config.rs +2 -2
@@ -108,7 +108,7 @@ impl Config {let mut map =SettingsMap ::new ();// SAFETY: gpiod_line_config is guaranteed to be valid here let num_lines =unsafe { gpiod::gpiod_line_config_get_num_configured_offsets (self.config) }; -let mut offsets =vec! [0 ; num_linesas usize ]; +let mut offsets =vec! [0 ; num_lines];// SAFETY: gpiod_line_config is guaranteed to be valid here. let num_stored =unsafe {
@@ -119,7 +119,7 @@ impl Config { ) }; -for offsetin &offsets[0 ..num_storedas usize ] { +for offsetin &offsets[0 ..num_stored] {// SAFETY: `gpiod_line_config` is guaranteed to be valid here. let settings =unsafe { gpiod::gpiod_line_config_get_line_settings (self.config, *offset) };
bindings/rust/libgpiod/src/line_request.rs +4 -4
@@ -28,12 +28,12 @@ impl Request {/// Get the number of lines in the request. pub fn num_lines (&self) ->usize {// SAFETY: `gpiod_line_request` is guaranteed to be valid here. -unsafe { gpiod::gpiod_line_request_get_num_requested_lines (self.request)as usize } +unsafe { gpiod::gpiod_line_request_get_num_requested_lines (self.request) } }/// Get the offsets of lines in the request. pub fn offsets (&self) ->Vec <Offset > { -let mut offsets =vec! [0 ; self.num_lines ()as usize ]; +let mut offsets =vec! [0 ; self.num_lines ()];// SAFETY: `gpiod_line_request` is guaranteed to be valid here. let num_offsets =unsafe {
@@ -43,7 +43,7 @@ impl Request { self.num_lines(), ) }; - offsets.shrink_to (num_offsetsas usize ); + offsets.shrink_to (num_offsets); offsets }
@@ -145,7 +145,7 @@ impl Request {/// Set values of all lines associated with the request. pub fn set_values (&mut self, values: &[Value ]) ->Result <&mut Self > { -if values.len () != self.num_lines ()as usize { +if values.len () != self.num_lines () {return Err (Error ::InvalidArguments ); }
bindings/rust/libgpiod/src/line_settings.rs +1 -1
@@ -244,7 +244,7 @@ impl Settings {/// Get the event clock setting. pub fn event_clock (&self) ->Result <EventClock > {// SAFETY: `gpiod_line_settings` is guaranteed to be valid here. -EventClock ::new (unsafe { gpiod::gpiod_line_settings_get_event_clock (self.settings) }as u32 ) +EventClock ::new (unsafe { gpiod::gpiod_line_settings_get_event_clock (self.settings) }) }/// Set the output value setting.
bindings/rust/libgpiod/src/request_config.rs +1 -1
@@ -83,7 +83,7 @@ impl Config {/// Get the edge event buffer size setting for the request config. pub fn event_buffer_size (&self) ->usize {// SAFETY: `gpiod_request_config` is guaranteed to be valid here. -unsafe { gpiod::gpiod_request_config_get_event_buffer_size (self.config)as usize } +unsafe { gpiod::gpiod_request_config_get_event_buffer_size (self.config) } } }
bindings/rust/libgpiod/tests/chip.rs +1 -1
@@ -59,7 +59,7 @@ mod chip {assert_eq! (info.label ().unwrap (),LABEL );assert_eq! (info.name ().unwrap (), sim.chip_name ());assert_eq! (chip.path ().unwrap (), sim.dev_path ().to_str ().unwrap ()); -assert_eq! (info.num_lines (),NGPIO as usize ); +assert_eq! (info.num_lines (),NGPIO ); }#[test]
Signature · 1 line
2.41.0
PATCH v2 2/4 bindings: rust: clippy: silence false-positives on casts
In reply to Erik Schillingclippy falsely complains about these lines. The problem is known, but unfixed [1]. So lets silence the warning until a fix is widely available.
clippy version: clippy 0.1.70 (90c5418 2023-05-31).
[1] https://github.com/rust-lang/rust-clippy/issues/10555
--- bindings/rust/libgpiod/src/line_info.rs | 3 +++ bindings/rust/libgpiod/src/line_settings.rs | 3 +++ 2 files changed, 6 insertions(+)
bindings/rust/libgpiod/src/line_info.rs +3 -0
@@ -142,6 +142,9 @@ impl Info {/// Get the debounce period of the line. pub fn debounce_period (&self) ->Duration { +// c_ulong may be 32bit OR 64bit, clippy reports a false-positive here: +// https://github.com/rust-lang/rust-clippy/issues/10555 +#[allow(clippy::unnecessary_cast)] // SAFETY: `gpiod_line_info` is guaranteed to be valid here. Duration ::from_micros (unsafe { gpiod::gpiod_line_info_get_debounce_period_us (self.info)as u64
bindings/rust/libgpiod/src/line_settings.rs +3 -0
@@ -218,6 +218,9 @@ impl Settings {/// Get the debounce period. pub fn debounce_period (&self) ->Result <Duration > { +// c_ulong may be 32bit OR 64bit, clippy reports a false-positive here: +// https://github.com/rust-lang/rust-clippy/issues/10555 +#[allow(clippy::unnecessary_cast)] // SAFETY: `gpiod_line_settings` is guaranteed to be valid here. Ok(Duration::from_micros(unsafe { gpiod::gpiod_line_settings_get_debounce_period_us(self.settings) as u64
Signature · 1 line
2.41.0
PATCH v2 3/4 bindings: rust: clippy: drop unneeded conversions
In reply to Erik SchillingFixes clippy warnings on these lines.
Applied the suggested fix using:
cargo clippy --fix
clippy version: clippy 0.1.70 (90c5418 2023-05-31).
--- bindings/rust/gpiosim-sys/src/sim.rs | 2 +- bindings/rust/libgpiod/src/event_buffer.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
bindings/rust/gpiosim-sys/src/sim.rs +1 -1
@@ -186,7 +186,7 @@ impl SimBank { fn set_num_lines(&self, num: usize) -> Result<()> { // SAFETY: `gpiosim_bank` is guaranteed to be valid here. - let ret = unsafe { gpiosim_bank_set_num_lines(self.bank, num.try_into().unwrap()) }; + let ret = unsafe { gpiosim_bank_set_num_lines(self.bank, num) }; if ret == -1 { Err(Error::OperationFailed( OperationType::SimBankSetNumLines,
bindings/rust/libgpiod/src/event_buffer.rs +1 -1
@@ -108,7 +108,7 @@ impl Buffer { gpiod::gpiod_line_request_read_edge_events ( request.request, self.buffer, - self.events.len ().try_into ().unwrap (), + self.events.len (), ) };
Signature · 1 line
2.41.0
PATCH v2 4/4 bindings: rust: clippy: silence false-positive on iterator
In reply to Erik SchillingThis was fixed on clippy master [1], but it is still broken on 0.1.70. So lets silence it until the clippy fix is widely available.
clippy version: clippy 0.1.70 (90c5418 2023-05-31).
[1] https://github.com/rust-lang/rust-clippy/commit/9fa40894103e32364fdbade539d4ecb3d40f3d7f
--- bindings/rust/libgpiod/src/event_buffer.rs | 3 +++ 1 file changed, 3 insertions(+)
bindings/rust/libgpiod/src/event_buffer.rs +3 -0
@@ -54,6 +54,9 @@ impl<'a> Iterator for Events<'a> { }fn next (&mut self) ->Option <Self ::Item > { +// clippy false-positive, fixed in next clippy release: +// https://github.com/rust-lang/rust-clippy/issues/9820 +#[allow(clippy::iter_nth_zero)] self.nth (0 ) } }
Signature · 1 line
2.41.0
Quoted 16 lines · Erik Schilling
This follows up on my promise on Kent's series [1] to look into whether these casts are needed or not. Most are not, a few are false-positives.
I also explored some shunit2 based test-script to automate the testing, but that became ugly with linking issue and needs me to revisit it another time. So this only sends the clippy fixes for now.
Tested the build (lib + examples + test) and clippy report on:
- Fedora 38x86_64
- Fedora 38 aarch64
- Debian 12 armv7hfTest execution (cargo test) was tested on:
- Fedora 38x86_64
- Fedora 38 aarch64
Quoted 9 lines
Could not execute tests on armv7hf due to lack of suitable test environment.
[1] https://lore.kernel.org/r/[email protected]
To: Linux-GPIO <[email protected]>
Cc: Kent Gibson <[email protected]>
Cc: Viresh Kumar <[email protected]>
for the series.
Quoted 1 line
Signed-off-by Erik Schilling <[email protected]>
Not sure you need to sign-off the cover letter.
e.g. git format-patch --cover-letter -s only signs off the patches, not the cover letter.
Not that it matters - just for future reference.
Good to see the end all those clippy warnings.
Cheers,
Kent.
Quoted 37 lines
---
Changes in v2:
- Changed cover letter title to active language
- Improved commit messages (hopefully)
- Elaborated what was built and tested
- Resent with hacked b4 for proper [libgpiod] tag
- Link to v1: https://lore.kernel.org/r/[email protected]---
Erik Schilling (4):
bindings: rust: clippy: drop unnecessary casts
bindings: rust: clippy: silence false-positives on casts
bindings: rust: clippy: drop unneeded conversions
bindings: rust: clippy: silence false-positive on iteratorbindings/rust/gpiosim-sys/src/lib.rs | 2 +- bindings/rust/gpiosim-sys/src/sim.rs | 4 ++-- bindings/rust/libgpiod/src/chip.rs | 2 +- bindings/rust/libgpiod/src/edge_event.rs | 2 +- bindings/rust/libgpiod/src/event_buffer.rs | 7 +++++-- bindings/rust/libgpiod/src/info_event.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 2 +- bindings/rust/libgpiod/src/line_config.rs | 4 ++-- bindings/rust/libgpiod/src/line_info.rs | 3 +++ bindings/rust/libgpiod/src/line_request.rs | 8 ++++---- bindings/rust/libgpiod/src/line_settings.rs | 5 ++++- bindings/rust/libgpiod/src/request_config.rs | 2 +- bindings/rust/libgpiod/tests/chip.rs | 2 +- 13 files changed, 27 insertions(+), 18 deletions(-)---
base-commit:4510231c95a087f58a155cf74164e403e1e0584f
change-id: 20230629-clippy-890c541c6d09Best regards,
Signature · 1 line
Erik Schilling <[email protected]>
Quoted 56 lines · Erik Schilling
This follows up on my promise on Kent's series [1] to look into whether these casts are needed or not. Most are not, a few are false-positives.
I also explored some shunit2 based test-script to automate the testing, but that became ugly with linking issue and needs me to revisit it another time. So this only sends the clippy fixes for now.
Tested the build (lib + examples + test) and clippy report on:
- Fedora 38x86_64
- Fedora 38 aarch64
- Debian 12 armv7hfTest execution (cargo test) was tested on:
- Fedora 38x86_64
- Fedora 38 aarch64Could not execute tests on armv7hf due to lack of suitable test environment.
[1] https://lore.kernel.org/r/[email protected]
To: Linux-GPIO <[email protected]>
Cc: Kent Gibson <[email protected]>
Cc: Viresh Kumar <[email protected]>Signed-off-by Erik Schilling <[email protected]>---
Changes in v2:
- Changed cover letter title to active language
- Improved commit messages (hopefully)
- Elaborated what was built and tested
- Resent with hacked b4 for proper [libgpiod] tag
- Link to v1: https://lore.kernel.org/r/[email protected]---
Erik Schilling (4):
bindings: rust: clippy: drop unnecessary casts
bindings: rust: clippy: silence false-positives on casts
bindings: rust: clippy: drop unneeded conversions
bindings: rust: clippy: silence false-positive on iteratorbindings/rust/gpiosim-sys/src/lib.rs | 2 +- bindings/rust/gpiosim-sys/src/sim.rs | 4 ++-- bindings/rust/libgpiod/src/chip.rs | 2 +- bindings/rust/libgpiod/src/edge_event.rs | 2 +- bindings/rust/libgpiod/src/event_buffer.rs | 7 +++++-- bindings/rust/libgpiod/src/info_event.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 2 +- bindings/rust/libgpiod/src/line_config.rs | 4 ++-- bindings/rust/libgpiod/src/line_info.rs | 3 +++ bindings/rust/libgpiod/src/line_request.rs | 8 ++++---- bindings/rust/libgpiod/src/line_settings.rs | 5 ++++- bindings/rust/libgpiod/src/request_config.rs | 2 +- bindings/rust/libgpiod/tests/chip.rs | 2 +- 13 files changed, 27 insertions(+), 18 deletions(-)
Quoted 8 lines
---
base-commit:4510231c95a087f58a155cf74164e403e1e0584f
change-id: 20230629-clippy-890c541c6d09Best regards,
--
Erik Schilling <[email protected]>
Applied the series with Kent's and Viresh' tags.
Bart