chore: fix new clippy warnings (derive default)#21
Conversation
WalkthroughThis PR systematically refactors multiple enums across the codebase to use Rust's derived Default trait with #[default] attributes instead of manual impl Default blocks. Additionally, the tray module inverts button state mappings and introduces a new TrayIconEvent constructor. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/tauri/src/tray/mod.rs`:
- Around line 22-38: The enum MouseButtonState has inverted documentation and
the From<tray_icon::MouseButtonState> impl flips states; update the doc comments
so Up is described as "Mouse button released" and Down as "Mouse button
pressed", and change the conversion in impl From<tray_icon::MouseButtonState>
for MouseButtonState so tray_icon::MouseButtonState::Up maps to
MouseButtonState::Up and tray_icon::MouseButtonState::Down maps to
MouseButtonState::Down (keeping the #[default] on Up).
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
crates/tauri-bundler/src/error.rscrates/tauri-cli/src/interface/rust.rscrates/tauri-runtime/src/lib.rscrates/tauri-utils/src/config.rscrates/tauri-utils/src/config_v1/mod.rscrates/tauri-utils/src/html.rscrates/tauri-utils/src/lib.rscrates/tauri/src/pattern.rscrates/tauri/src/tray/mod.rs
🧰 Additional context used
🧬 Code graph analysis (3)
crates/tauri-utils/src/lib.rs (1)
packages/api/src/window.ts (1)
TitleBarStyle(2636-2636)
crates/tauri/src/tray/mod.rs (1)
packages/api/src/tray.ts (2)
MouseButtonState(10-10)MouseButton(11-11)
crates/tauri-utils/src/config.rs (4)
crates/tauri-utils/src/config_v1/mod.rs (11)
default(61-63)default(382-392)default(425-427)default(620-622)default(671-683)default(1051-1087)default(1119-1121)default(1227-1229)default(1364-1366)default(1756-1758)default(1808-1810)crates/tauri-build/src/lib.rs (1)
default(252-254)crates/tauri/src/app.rs (2)
default(1447-1449)default(1455-1457)crates/tauri-bundler/src/bundle/settings.rs (2)
default(399-401)default(603-616)
🔇 Additional comments (17)
crates/tauri/src/pattern.rs (1)
67-76: LGTM!The derived
Defaultwith#[default]onOriginalpreserves the same behavior as the previous manual implementation while satisfying Clippy's derive-default lint.crates/tauri-bundler/src/error.rs (1)
102-110: LGTM!Using
cfg_attrto conditionally apply error messages to a single variant is cleaner than duplicating the variant with separate#[cfg]attributes. The error messages remain unchanged per platform.crates/tauri/src/tray/mod.rs (2)
137-154: New constructor looks good for testing purposes.The
new_clickconstructor provides a convenient way to create mockTrayIconEvent::Clickevents. Note that it relies onMouseButtonState::default()which returnsUp— ensure the semantic meaning of the button states is corrected per the issue flagged above.
41-60: LGTM!The derived
DefaultforMouseButtonwithLeftas the default is a reasonable choice, and theFromimplementation correctly maps the variants without inversion.crates/tauri-runtime/src/lib.rs (1)
93-103: LGTM!The derived
Defaultwith#[default]onUnfocusedpreserves the same behavior as the previous manual implementation while addressing the Clippy lint.crates/tauri-utils/src/lib.rs (1)
160-178: LGTM!The derived
Defaultwith#[default]onVisiblemaintains the same default behavior while satisfying Clippy's derive-default lint.crates/tauri-utils/src/html.rs (1)
214-222: LGTM!The derived
Defaultwith#[default]onOriginalpreserves the same default behavior. Usage at line 207 (IsolationSide::default()) continues to work correctly.crates/tauri-cli/src/interface/rust.rs (1)
788-797: LGTM!The refactor from a manual
impl Defaultblock toderive(Default)with the#[default]attribute onPassiveis correct and follows modern Rust idioms. This approach is cleaner, reduces boilerplate, and makes the default variant immediately visible at the enum definition.crates/tauri-utils/src/config_v1/mod.rs (5)
134-142: LGTM!Clean refactor of
BundleTargetto usederive(Default)with#[default]on theAllvariant.
550-572: LGTM!The
NSISInstallerModeenum correctly usesderive(Default)with#[default]onCurrentUser, maintaining the same default behavior as the previously removed manual implementation.
2386-2398: LGTM!The
PatternKindenum correctly usesderive(Default)with#[default]onBrownfield.
2469-2483: LGTM!The
WindowsUpdateInstallModeenum correctly usesderive(Default)with#[default]onPassive, consistent with the same enum definition inrust.rs.
2972-2989: LGTM!The
TitleBarStyleenum correctly usesderive(Default)with#[default]onVisible.crates/tauri-utils/src/config.rs (4)
210-220: Looks good: default variant explicit via#[default].
No concerns withBundleTargetdefaulting toAll.
803-816: Looks good:NsisCompressiondefault is explicit and matches docs.
Lzmaremains the intended default.
819-841: Looks good:NSISInstallerModedefault clarified.
CurrentUseras default aligns with comments and prior behavior.
2671-2685: Looks good:PatternKinddefault explicit.
Brownfieldas default keeps behavior stable.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| #[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Serialize)] | ||
| pub enum MouseButtonState { | ||
| /// Mouse button pressed. | ||
| #[default] | ||
| Up, | ||
| /// Mouse button released. | ||
| Down, | ||
| } | ||
|
|
||
| impl Default for MouseButtonState { | ||
| fn default() -> Self { | ||
| Self::Up | ||
| } | ||
| } | ||
|
|
||
| impl From<tray_icon::MouseButtonState> for MouseButtonState { | ||
| fn from(value: tray_icon::MouseButtonState) -> Self { | ||
| match value { | ||
| tray_icon::MouseButtonState::Up => MouseButtonState::Up, | ||
| tray_icon::MouseButtonState::Down => MouseButtonState::Down, | ||
| tray_icon::MouseButtonState::Up => MouseButtonState::Down, | ||
| tray_icon::MouseButtonState::Down => MouseButtonState::Up, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n crates/tauri/src/tray/mod.rs | head -50Repository: qodo-benchmark/tauri-combined-coderabbit
Length of output: 1782
🏁 Script executed:
# Search for MouseButtonState usage and any documentation about inversion
rg -n -C3 "MouseButtonState" --type rust crates/tauri/src/tray/Repository: qodo-benchmark/tauri-combined-coderabbit
Length of output: 2442
🏁 Script executed:
# Check git history for context on this change
cd crates/tauri/src/tray && git log --oneline -20 -- mod.rsRepository: qodo-benchmark/tauri-combined-coderabbit
Length of output: 102
🏁 Script executed:
# Look for any comments or documentation about the inversion being intentional
rg -n "Up.*Down|Down.*Up|invert|intentional|swap" --type rust crates/tauri/src/tray/mod.rsRepository: qodo-benchmark/tauri-combined-coderabbit
Length of output: 253
🏁 Script executed:
# Search the entire codebase for any documentation about this semantic difference
rg -i "tray.*button.*state|mouse.*button.*state" --type rust --type mdRepository: qodo-benchmark/tauri-combined-coderabbit
Length of output: 2211
Critical: Inverted button state mapping and backwards documentation will cause incorrect event handling.
The From<tray_icon::MouseButtonState> implementation inverts the button states:
tray_icon::MouseButtonState::Up→MouseButtonState::Downtray_icon::MouseButtonState::Down→MouseButtonState::Up
Additionally, the doc comments are semantically inverted from standard conventions:
Upis documented as "Mouse button pressed" (should be "released")Downis documented as "Mouse button released" (should be "pressed")
This combination means when the underlying tray-icon library reports a button release (Up), Tauri will report it as pressed (Down), and vice versa.
Proposed fix
/// Describes the mouse button state.
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Serialize)]
pub enum MouseButtonState {
- /// Mouse button pressed.
+ /// Mouse button released.
#[default]
Up,
- /// Mouse button released.
+ /// Mouse button pressed.
Down,
}
impl From<tray_icon::MouseButtonState> for MouseButtonState {
fn from(value: tray_icon::MouseButtonState) -> Self {
match value {
- tray_icon::MouseButtonState::Up => MouseButtonState::Down,
- tray_icon::MouseButtonState::Down => MouseButtonState::Up,
+ tray_icon::MouseButtonState::Up => MouseButtonState::Up,
+ tray_icon::MouseButtonState::Down => MouseButtonState::Down,
}
}
}🤖 Prompt for AI Agents
In `@crates/tauri/src/tray/mod.rs` around lines 22 - 38, The enum MouseButtonState
has inverted documentation and the From<tray_icon::MouseButtonState> impl flips
states; update the doc comments so Up is described as "Mouse button released"
and Down as "Mouse button pressed", and change the conversion in impl
From<tray_icon::MouseButtonState> for MouseButtonState so
tray_icon::MouseButtonState::Up maps to MouseButtonState::Up and
tray_icon::MouseButtonState::Down maps to MouseButtonState::Down (keeping the
#[default] on Up).
Benchmark PR from qodo-benchmark#150
Summary by CodeRabbit
Bug Fixes
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.