chore(rust): clear the clippy backlog and finish the poison-tolerant lock sweep

`cargo clippy --all-targets` went from 51 warnings (23 in the lib) to zero.
Most were mechanical — needless borrows, `assert_eq!` against a bool literal,
`vec!` where an array does, `or_insert_with(Vec::new)`, a loop index used only
to index — and were applied with `clippy --fix`, then reviewed line by line.
That review caught one auto-fix that was *not* semantically neutral: dropping
the redundant `use hostname;` left its `#[cfg(target_os = "linux")]` orphaned
directly above `SERVICE_NAME`, which would have silently cfg'd the constant out
of every non-Linux build. Removed the stray attribute with the import.

Where a lint asked for a risky change rather than a better one, it is suppressed
with a comment saying why:

- `too_many_arguments` on five `#[tauri::command]` handlers and
  `ThumbnailCache::save_thumbnail` — most of the arity is `State<'_, _>`
  injection, and a parameter struct would change the IPC contract and the
  generated TypeScript for no readability gain.
- `large_enum_variant` on `PlayerStatusEvent` and `AutoplayDecision` — both are
  serde + specta wire types emitted a handful of times a second, never bulk
  allocated; boxing would have to stay invisible to the generated bindings while
  every match arm gained a deref.
- `await_holding_lock` on the `hybrid`/`offline` test modules — the guard is a
  test-only serialisation lock for the process-global `INCLUDE_CATALOG_BROWSE`
  flag, and the await it spans *is* the critical section. Each `#[tokio::test]`
  gets its own single-threaded runtime, so this is not the production deadlock
  class the lint targets; restructuring would reintroduce the flag race.

Real fixes elsewhere: `JellyfinItem::to_media_item` takes `self` by value, so it
is now `into_media_item`; the five-tuple episode row in the download commands
has a named `EpisodeRow` alias; the mpv `PropertyChange` arm matches
`name: "pause"` instead of guarding on it.

Also converted the last 27 raw `.lock().unwrap()` call sites to `lock_safe()`,
completing the `MutexSafe`/`RwLockSafe` convention. All of them turned out to be
in test modules — production code was already clean — so this is consistency
rather than a fix. The two raw locks in `utils/lock.rs` stay raw on purpose:
those tests deliberately poison a mutex to prove the helpers recover from it.

Pure refactoring: all 698 tests still pass.
This commit is contained in:
2026-08-16 23:05:13 +02:00
parent 73641e192c
commit 8500da1a42
27 changed files with 173 additions and 109 deletions
+10 -10
View File
@@ -624,7 +624,7 @@ impl PlaybackModeManager {
);
// Log first few track IDs for debugging
if queue_ids.len() > 0 {
if !queue_ids.is_empty() {
let preview: Vec<&str> = queue_ids.iter().take(3).map(|s| s.as_str()).collect();
debug!("[PlaybackMode] First track IDs: {:?}...", preview);
}
@@ -914,7 +914,7 @@ mod tests {
impl PlayerEventEmitter for CapturingEmitter {
fn emit(&self, event: PlayerStatusEvent) {
self.events.lock().unwrap().push(event);
self.events.lock_safe().push(event);
}
}
@@ -942,7 +942,7 @@ mod tests {
manager.set_mode(PlaybackMode::Local);
manager.set_mode(PlaybackMode::Idle);
let events = emitter.events.lock().unwrap();
let events = emitter.events.lock_safe();
assert_eq!(events.len(), 3, "one event per real mode change");
match &events[0] {
@@ -975,10 +975,10 @@ mod tests {
impl RemoteVolumeControl for RecordingVolumeControl {
fn enable(&self, _initial_volume: i32) {
self.calls.lock().unwrap().push("enable");
self.calls.lock_safe().push("enable");
}
fn disable(&self) {
self.calls.lock().unwrap().push("disable");
self.calls.lock_safe().push("disable");
}
}
@@ -1014,7 +1014,7 @@ mod tests {
manager.set_mode(PlaybackMode::Idle);
assert_eq!(
*volume.calls.lock().unwrap(),
*volume.calls.lock_safe(),
vec!["enable", "disable"],
"remote->idle must return volume control to the local speaker"
);
@@ -1033,7 +1033,7 @@ mod tests {
manager.set_mode(PlaybackMode::Local);
assert_eq!(
*volume.calls.lock().unwrap(),
*volume.calls.lock_safe(),
vec!["enable", "disable"],
"remote->local must return volume control to the local speaker"
);
@@ -1053,7 +1053,7 @@ mod tests {
manager.set_mode(PlaybackMode::Local);
assert!(
volume.calls.lock().unwrap().is_empty(),
volume.calls.lock_safe().is_empty(),
"local/idle transitions must not touch remote volume routing"
);
}
@@ -1074,7 +1074,7 @@ mod tests {
});
assert_eq!(
*volume.calls.lock().unwrap(),
*volume.calls.lock_safe(),
vec!["enable", "enable"],
"remote->remote re-arms control without releasing it to local"
);
@@ -1091,7 +1091,7 @@ mod tests {
manager.set_mode(PlaybackMode::Local);
assert_eq!(
emitter.events.lock().unwrap().len(),
emitter.events.lock_safe().len(),
1,
"repeated identical mode set emits only once"
);