Skip to content

pre-commit: enable check and clippy#4947

Open
Saviq wants to merge 9 commits into
mainfrom
cargo-clippy
Open

pre-commit: enable check and clippy#4947
Saviq wants to merge 9 commits into
mainfrom
cargo-clippy

Conversation

@Saviq
Copy link
Copy Markdown
Contributor

@Saviq Saviq commented May 14, 2026

What's new?

pre-commit runs cargo check and cargo clippy.

How to test

CI

Checklist

  • Tests added and pass
  • Adequate documentation added
  • (optional) Added Screenshots or videos

@Saviq Saviq force-pushed the cargo-clippy branch 7 times, most recently from 7df11af to b7644a7 Compare May 14, 2026 10:52
@Saviq
Copy link
Copy Markdown
Contributor Author

Saviq commented May 14, 2026

@copilot please try and fix the following clippy violations:

error: field assignment outside of initializer for an instance created with Default::default()
   --> src/platforms/evdev-rs/src/device.rs:132:13
    |
132 |             settings.has_error = true;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: consider initializing the variable with `ffi_bridge::PointerSettings { has_error: true, ..Default::default() }` and removing relevant reassignments
   --> src/platforms/evdev-rs/src/device.rs:131:13
    |
131 |             let mut settings = PointerSettings::default();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#field_reassign_with_default
    = note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::field_reassign_with_default)]`

error: this lifetime isn't used in the function definition
   --> src/platforms/evdev-rs/src/device.rs:235:30
    |
235 |     pub fn find_device_by_id<'a>(&mut self, id: i32) -> Option<&'_ mut LibinputDeviceInfo> {
    |                              ^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#extra_unused_lifetimes
    = note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::extra_unused_lifetimes)]`

error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
  --> src/platforms/evdev-rs/src/event_processing.rs:88:20
   |
88 |     known_devices: &'a mut Vec<LibinputDeviceInfo>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
   = note: `-D clippy::ptr-arg` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]`
help: change this to
   |
88 -     known_devices: &'a mut Vec<LibinputDeviceInfo>,
88 +     known_devices: &'a mut [LibinputDeviceInfo],
   |

error: this `let...else` may be rewritten with the `?` operator
   --> src/platforms/evdev-rs/src/event_processing.rs:161:13
    |
161 | /             let Some(index) = known_devices
162 | |                 .iter()
163 | |                 .position(|x| x.device.as_raw() == dev.as_raw())
164 | |             else {
165 | |                 return None;
166 | |             };
    | |______________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#question_mark
    = note: `-D clippy::question-mark` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::question_mark)]`
help: replace it with
    |
161 ~             let index = known_devices
162 +                 .iter()
163 +                 .position(|x| x.device.as_raw() == dev.as_raw())?;
    |

error: usage of an `Arc` that is not `Send` and `Sync`
  --> src/platforms/evdev-rs/src/platform.rs:83:27
   |
83 |           self.state = Some(Arc::new(Mutex::new(LibinputDeviceState {
   |  ___________________________^
84 | |             libinput,
85 | |             known_devices: Vec::new(),
86 | |             next_device_id: 0,
...  |
90 | |             y_scroll_scale: 1.0,
91 | |         })));
   | |___________^
   |
   = note: `Arc<Mutex<LibinputDeviceState>>` is not `Send` and `Sync` as `Mutex<LibinputDeviceState>` is neither `Send` nor `Sync`
   = help: if the `Arc` will not be used across threads replace it with an `Rc`
   = help: otherwise make `Mutex<LibinputDeviceState>` `Send` and `Sync` or consider a wrapper type such as `Mutex`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#arc_with_non_send_sync
   = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]`

error: usage of an `Arc` that is not `Send` and `Sync`
   --> src/platforms/evdev-rs/src/platform.rs:301:17
    |
301 | /                 Arc::new(Mutex::new(LibinputDeviceState {
302 | |                     libinput,
303 | |                     known_devices: Vec::new(),
304 | |                     next_device_id: 0,
...   |
308 | |                     y_scroll_scale: 1.0,
309 | |                 }))
    | |___________________^
    |
    = note: `Arc<Mutex<LibinputDeviceState>>` is not `Send` and `Sync` as `Mutex<LibinputDeviceState>` is neither `Send` nor `Sync`
    = help: if the `Arc` will not be used across threads replace it with an `Rc`
    = help: otherwise make `Mutex<LibinputDeviceState>` `Send` and `Sync` or consider a wrapper type such as `Mutex`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#arc_with_non_send_sync

error: unsafe function's docs are missing a `# Safety` section
   --> src/platforms/evdev-rs/src/lib.rs:274:9
    |
274 | /         pub unsafe fn create_event_builder_wrapper(
275 | |             self: &PlatformBridge,
276 | |             event_builder: *mut EventBuilder,
277 | |         ) -> UniquePtr<EventBuilderWrapper>;
    | |___________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#missing_safety_doc
    = note: `-D clippy::missing-safety-doc` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]`

error: could not compile `mir_platforms_evdev_rs` (lib) due to 7 previous errors
warning: build failed, waiting for other jobs to finish...
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> src/server/frontend_wayland/wayland_rs/build_script/ffi_generation.rs:22:32
   |
22 | pub fn generate_ffi(protocols: &Vec<WaylandProtocol>, builders: &Vec<CppBuilder>) -> TokenStream {
   |                                ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
   = note: `-D clippy::ptr-arg` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]`
help: change this to
   |
22 - pub fn generate_ffi(protocols: &Vec<WaylandProtocol>, builders: &Vec<CppBuilder>) -> TokenStream {
22 + pub fn generate_ffi(protocols: &[WaylandProtocol], builders: &Vec<CppBuilder>) -> TokenStream {
   |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> src/server/frontend_wayland/wayland_rs/build_script/ffi_generation.rs:22:65
   |
22 | pub fn generate_ffi(protocols: &Vec<WaylandProtocol>, builders: &Vec<CppBuilder>) -> TokenStream {
   |                                                                 ^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
   |
22 - pub fn generate_ffi(protocols: &Vec<WaylandProtocol>, builders: &Vec<CppBuilder>) -> TokenStream {
22 + pub fn generate_ffi(protocols: &Vec<WaylandProtocol>, builders: &[CppBuilder]) -> TokenStream {
   |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> src/server/frontend_wayland/wayland_rs/build_script/protocol_middleware_generation.rs:22:57
   |
22 | pub fn generate_wayland_interface_middleware(protocols: &Vec<WaylandProtocol>) -> TokenStream {
   |                                                         ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
   |
22 - pub fn generate_wayland_interface_middleware(protocols: &Vec<WaylandProtocol>) -> TokenStream {
22 + pub fn generate_wayland_interface_middleware(protocols: &[WaylandProtocol]) -> TokenStream {
   |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> src/server/frontend_wayland/wayland_rs/build_script/wayland_server_generation.rs:15:56
   |
15 | pub fn generate_wayland_server_generated_rs(protocols: &Vec<WaylandProtocol>) -> TokenStream {
   |                                                        ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
   |
15 - pub fn generate_wayland_server_generated_rs(protocols: &Vec<WaylandProtocol>) -> TokenStream {
15 + pub fn generate_wayland_server_generated_rs(protocols: &[WaylandProtocol]) -> TokenStream {
   |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> src/server/frontend_wayland/wayland_rs/build_script/main.rs:79:34
   |
79 | fn write_protocols_rs(protocols: &Vec<WaylandProtocol>) {
   |                                  ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
   |
79 - fn write_protocols_rs(protocols: &Vec<WaylandProtocol>) {
79 + fn write_protocols_rs(protocols: &[WaylandProtocol]) {
   |

error: match expression looks like `matches!` macro
   --> src/server/frontend_wayland/wayland_rs/build_script/main.rs:490:68
    |
490 |       let interface_has_requests = interface.items.iter().any(|item| match item {
    |  ____________________________________________________________________^
491 | |         InterfaceItem::Request(_) => true,
492 | |         _ => false,
493 | |     });
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#match_like_matches_macro
    = note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]`
help: use `matches!` directly
    |
490 -     let interface_has_requests = interface.items.iter().any(|item| match item {
491 -         InterfaceItem::Request(_) => true,
492 -         _ => false,
493 -     });
490 +     let interface_has_requests = interface.items.iter().any(|item| matches!(item, InterfaceItem::Request(_)));
    |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
   --> src/server/frontend_wayland/wayland_rs/build_script/main.rs:572:33
    |
572 | fn write_dispatch_rs(protocols: &Vec<WaylandProtocol>) {
    |                                 ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
    |
572 - fn write_dispatch_rs(protocols: &Vec<WaylandProtocol>) {
572 + fn write_dispatch_rs(protocols: &[WaylandProtocol]) {
    |

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
   --> src/server/frontend_wayland/wayland_rs/build_script/main.rs:629:37
    |
629 | fn create_global_factory(protocols: &Vec<WaylandProtocol>) -> CppBuilder {
    |                                     ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#ptr_arg
help: change this to
    |
629 - fn create_global_factory(protocols: &Vec<WaylandProtocol>) -> CppBuilder {
629 + fn create_global_factory(protocols: &[WaylandProtocol]) -> CppBuilder {
    |

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

@copilot please try and fix the following clippy violations:

...

Implemented the requested clippy fixes in commit f0c4366.

This includes the evdev-rs fixes (field_reassign_with_default, unused lifetime removal, ptr_arg, question_mark, missing safety docs) and wayland_rs build-script fixes (ptr_arg, match_like_matches_macro). I also localized arc_with_non_send_sync allowances to the two evdev-rs construction sites where Arc<Mutex<LibinputDeviceState>> is intentionally used.

Copilot finished work on behalf of Saviq May 14, 2026 12:16
@Saviq Saviq marked this pull request as ready for review May 14, 2026 12:44
Copilot AI review requested due to automatic review settings May 14, 2026 12:44
Copy link
Copy Markdown
Contributor Author

@Saviq Saviq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks legit to me, pre-commit autofixed in 9ba64b1 and then Copilot did the rest in f0c4366

@Saviq Saviq requested a review from mattkae May 14, 2026 12:46
@Saviq Saviq assigned RAOF and unassigned RAOF May 14, 2026
@Saviq Saviq requested a review from RAOF May 14, 2026 12:47
@Saviq
Copy link
Copy Markdown
Contributor Author

Saviq commented May 14, 2026

@mattkae remaining violation:

error: unsafe function's docs are missing a `# Safety` section
   --> src/platforms/evdev-rs/src/lib.rs:274:9
    |
274 | /         pub unsafe fn create_event_builder_wrapper(
275 | |             self: &PlatformBridge,
276 | |             event_builder: *mut EventBuilder,
277 | |         ) -> UniquePtr<EventBuilderWrapper>;
    | |___________________________________________^

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the repository’s pre-commit/CI enforcement by running Rust workspace validation (cargo check and cargo clippy) and includes several small Rust refactors/cleanups to satisfy clippy and general linting.

Changes:

  • Enable cargo check and cargo clippy (plus a clippy fix hook) in .pre-commit-config.yaml.
  • Update the pre-commit GitHub Actions workflow to install additional system dependencies needed for Rust checks.
  • Apply minor Rust refactors across the Wayland build script and evdev-rs to reduce warnings and improve idiomatic usage (e.g., slice args, matches!, iterator cleanups).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/server/frontend_wayland/wayland_rs/build_script/wayland_server_generation.rs Use slice parameters instead of &Vec for generated server code helpers.
src/server/frontend_wayland/wayland_rs/build_script/protocol_parser.rs Minor control-flow simplification in global-interface detection logic.
src/server/frontend_wayland/wayland_rs/build_script/protocol_middleware_generation.rs Use slice parameters instead of &Vec for middleware generation.
src/server/frontend_wayland/wayland_rs/build_script/main.rs Propagate slice-based APIs and apply small iterator/matcher cleanups.
src/server/frontend_wayland/wayland_rs/build_script/helpers.rs Minor cleanup for create_dir_all argument usage.
src/server/frontend_wayland/wayland_rs/build_script/ffi_generation.rs Update FFI generator to accept slices and iterate without moving.
src/server/frontend_wayland/wayland_rs/build_script/cpp_builder.rs Small idiomatic Rust cleanups (e.g., push('\n'), field init shorthand).
src/platforms/evdev-rs/src/platform.rs Clippy-driven refactors; adds #[allow(clippy::arc_with_non_send_sync)] in two places.
src/platforms/evdev-rs/src/libinput_interface.rs Remove unused imports to satisfy clippy.
src/platforms/evdev-rs/src/lib.rs Doc/comment formatting and minor return-style cleanup.
src/platforms/evdev-rs/src/event_processing.rs Clippy-driven refactors (slice args, ?, or_default, loop/typing cleanups).
src/platforms/evdev-rs/src/device.rs Idiomatic operator/return/initializer cleanups and signature simplification.
.pre-commit-config.yaml Enable cargo-check and cargo-clippy hooks (including a clippy-fix variant).
.github/workflows/pre-commit.yaml Install extra apt packages so Rust checks can run in CI.
Comments suppressed due to low confidence (1)

src/platforms/evdev-rs/src/platform.rs:284

  • Same as above: this #[allow(clippy::arc_with_non_send_sync)] should ideally be accompanied by a short justification comment, or replaced with Rc if the state is guaranteed to be single-threaded. Leaving it unexplained makes it easy to accidentally introduce real cross-thread usage later.
    #[allow(clippy::arc_with_non_send_sync)]
    pub fn create_input_device(&mut self, device_id: i32) -> Box<LibinputDevice> {

Comment thread .github/workflows/pre-commit.yaml Outdated
@@ -66,6 +64,7 @@ impl PlatformRs {
/// was already started. The caller must only schedule `assign_seat()` when
/// this returns `true` to avoid calling `udev_assign_seat()` on an already-
/// assigned libinput context.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooof. On closer inspection, this is not a false-positive, but a (potentially) real problem that's hidden under a couple of layers of indirection — LibInputDeviceState contains a LibInput that contains an Option<Rc<dyn LibInputInterface + 'static>>, and that is unsafe to send across threads (even wrapped in a Mutex), because you can .clone() an Rc<> from a shared reference (that's the point), and if you do that on two different threads then the reference counting can race (leading to either a memory leak or use-after-free, depending).

So this is something we should fix, rather than #[allow()].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot suggest a fix per above analysis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented a fix in 9006b2e (with core refactor in f37eb3b): libinput is no longer stored inside the shared Arc<Mutex<LibinputDeviceState>>. PlatformRs now owns libinput separately, event-processing functions take &mut Libinput explicitly, and fallback initialization now creates both libinput and shared state together to keep them consistent.

No UI changes were made, so screenshot is not applicable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! I see what you mean. It seems that copilot figured out a decent solution of:

  1. Moving it out of the state
  2. Just piping it down where and when it's needed

Copy link
Copy Markdown
Contributor

@RAOF RAOF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes look good to me.

@@ -66,6 +64,7 @@ impl PlatformRs {
/// was already started. The caller must only schedule `assign_seat()` when
/// this returns `true` to avoid calling `udev_assign_seat()` on an already-
/// assigned libinput context.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooof. On closer inspection, this is not a false-positive, but a (potentially) real problem that's hidden under a couple of layers of indirection — LibInputDeviceState contains a LibInput that contains an Option<Rc<dyn LibInputInterface + 'static>>, and that is unsafe to send across threads (even wrapped in a Mutex), because you can .clone() an Rc<> from a shared reference (that's the point), and if you do that on two different threads then the reference counting can race (leading to either a memory leak or use-after-free, depending).

So this is something we should fix, rather than #[allow()].

@mattkae
Copy link
Copy Markdown
Contributor

mattkae commented May 22, 2026

@mattkae remaining violation:

error: unsafe function's docs are missing a `# Safety` section
   --> src/platforms/evdev-rs/src/lib.rs:274:9
    |
274 | /         pub unsafe fn create_event_builder_wrapper(
275 | |             self: &PlatformBridge,
276 | |             event_builder: *mut EventBuilder,
277 | |         ) -> UniquePtr<EventBuilderWrapper>;
    | |___________________________________________^

Heh - but we have one there! I think clippy is unable to reason about it in the unsafe extern C++ block...

@mattkae
Copy link
Copy Markdown
Contributor

mattkae commented May 22, 2026

@Saviq Evdev-rs is fixed, but I am tempted to leave wayland-rs for later, since so much of it is currently in flux

@Saviq
Copy link
Copy Markdown
Contributor Author

Saviq commented May 22, 2026

@Saviq Evdev-rs is fixed, but I am tempted to leave wayland-rs for later, since so much of it is currently in flux

Sure, just make clippy pass by suppressing what it's unhappy with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants