What changed, and why it matters
This commit is a routine code cleanup in the Rust portions of the Trezor firmware. It fixes compiler lint warnings by modernizing syntax (for example replacing manual remainder checks with built-in methods, adding explicit lifetime markers, and simplifying match statements). There is no indication it fixes a security bug or changes product behavior.
No security action required. Treat as normal code hygiene; review in the standard CI/lint workflow.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff consists entirely of style and lint fixes across 38 Rust source files. Changes include: adding anonymous/elided lifetime annotations (Iter<’>, MapRef<’>, RefMut<’>, BitmapView<’>), replacing x % n == 0 with is_multiple_of(n), replacing x % n != 0 with !is_multiple_of(n), collapsing if-let and match guards, removing unnecessary parentheses, adding #[allow(clippy::mut_from_ref)] and #[allow(unnecessary_transmutes)], and minor refactorings such as using checked_div for stride calculations and iter().enumerate(). No functional security fixes are present.
Changed components
core/embed/rust/src/micropython/iter.rscore/embed/rust/src/micropython/map.rscore/embed/rust/src/protobuf/defs.rscore/embed/rust/src/smp/base64.rscore/embed/rust/src/trezorhal/ble/mod.rscore/embed/rust/src/trezorhal/ffi.rscore/embed/rust/src/ui/component/marquee.rscore/embed/rust/src/ui/component/text/paragraphs.rscore/embed/rust/src/ui/layout/obj.rscore/embed/rust/src/ui/layout/util.rscore/embed/rust/src/ui/layout_bolt/component/coinjoin_progress.rscore/embed/rust/src/ui/layout_caesar/component/changing_text.rscore/embed/rust/src/ui/layout_caesar/component/hold_to_confirm.rscore/embed/rust/src/ui/layout_caesar/component/input_methods/pin.rscore/embed/rust/src/ui/layout_caesar/component/loader.rscore/embed/rust/src/ui/layout_caesar/component/title.rscore/embed/rust/src/ui/layout_delizia/component/button.rscore/embed/rust/src/ui/layout_delizia/component/coinjoin_progress.rscore/embed/rust/src/ui/layout_delizia/component/hold_to_confirm.rscore/embed/rust/src/ui/layout_delizia/component/homescreen.rscore/embed/rust/src/ui/layout_delizia/component/swipe_content.rscore/embed/rust/src/ui/layout_eckhart/bootloader/bld_text_screen.rscore/embed/rust/src/ui/layout_eckhart/component/button.rscore/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/pin.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/string.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rscore/embed/rust/src/ui/layout_eckhart/firmware/progress_screen.rscore/embed/rust/src/ui/shape/base.rscore/embed/rust/src/ui/shape/bitmap.rscore/embed/rust/src/ui/shape/cache/drawing_cache.rscore/embed/rust/src/ui/shape/canvas/common.rscore/embed/rust/src/ui/shape/canvas/mono8.rscore/embed/rust/src/ui/shape/canvas/rgb565.rscore/embed/rust/src/ui/shape/canvas/rgba8888.rscore/embed/rust/src/ui/shape/utils/imagebuf.rsInspect captured patch +107 / −118
diff --git a/core/embed/rust/src/micropython/iter.rs b/core/embed/rust/src/micropython/iter.rs
index fbc32204..04071732 100644
--- a/core/embed/rust/src/micropython/iter.rs
+++ b/core/embed/rust/src/micropython/iter.rs
@@ -30,7 +30,7 @@ impl IterBuf {
new
}
- pub fn try_iterate(&mut self, o: Obj) -> Result<Iter, Error> {
+ pub fn try_iterate(&mut self, o: Obj) -> Result<Iter<'_>, Error> {
Iter::try_from_obj_with_buf(o, self)
}
diff --git a/core/embed/rust/src/micropython/map.rs b/core/embed/rust/src/micropython/map.rs
index 51789abd..3910a209 100644
--- a/core/embed/rust/src/micropython/map.rs
+++ b/core/embed/rust/src/micropython/map.rs
@@ -42,7 +42,7 @@ impl Map {
}
impl Map {
- pub fn from_fixed(table: &[MapElem]) -> MapRef {
+ pub fn from_fixed(table: &[MapElem]) -> MapRef<'_> {
let mut map = MaybeUninit::uninit();
// SAFETY: `mp_map_init_fixed_table` completely initializes all fields of `map`.
unsafe {
diff --git a/core/embed/rust/src/protobuf/defs.rs b/core/embed/rust/src/protobuf/defs.rs
index cf47172b..6ffbc852 100644
--- a/core/embed/rust/src/protobuf/defs.rs
+++ b/core/embed/rust/src/protobuf/defs.rs
@@ -225,7 +225,10 @@ pub fn get_msg(msg_offset: u16) -> MsgDef {
// * FieldDef has the same alignment
debug_assert!(mem::align_of::<FieldDef>() == mem::align_of::<u16>());
// * both msg_offset and fields_start added together keep the alignment:
- debug_assert!(fields_byteslice.as_ptr().addr() % mem::align_of::<FieldDef>() == 0);
+ debug_assert!(fields_byteslice
+ .as_ptr()
+ .addr()
+ .is_multiple_of(mem::align_of::<FieldDef>()));
// SAFETY: FieldDef is a packed struct of ints, so all bit patterns are valid.
let (_pre, fields, _post) = unsafe { fields_byteslice.align_to::<FieldDef>() };
@@ -263,7 +266,7 @@ fn get_enum(enum_offset: u16) -> EnumDef {
// enum_offset is a raw byte offset, we check that it is also a valid index of
// an u16
- assert!(enum_offset % SIZE == 0);
+ assert!(enum_offset.is_multiple_of(SIZE));
let offset: usize = (enum_offset / SIZE).into();
let count: usize = enum_defs[offset].into();
EnumDef {
diff --git a/core/embed/rust/src/smp/base64.rs b/core/embed/rust/src/smp/base64.rs
index 99e99642..ad2f7f3c 100644
--- a/core/embed/rust/src/smp/base64.rs
+++ b/core/embed/rust/src/smp/base64.rs
@@ -67,7 +67,7 @@ fn base64_char_value(c: u8) -> Option<u8> {
/// Returns the number of bytes written on success.
pub fn base64_decode(input: &[u8], output: &mut [u8]) -> Result<usize, Base64Error> {
let len = input.len();
- if len % 4 != 0 {
+ if !len.is_multiple_of(4) {
return Err(Base64Error::InvalidLength);
}
diff --git a/core/embed/rust/src/trezorhal/ble/mod.rs b/core/embed/rust/src/trezorhal/ble/mod.rs
index 1086026d..46bc9c63 100644
--- a/core/embed/rust/src/trezorhal/ble/mod.rs
+++ b/core/embed/rust/src/trezorhal/ble/mod.rs
@@ -40,7 +40,7 @@ pub fn ble_parse_event(event: ffi::ble_event_t) -> BLEEvent {
.data
.iter()
.take(6)
- .map(|&b| (b - b'0'))
+ .map(|&b| b - b'0')
.fold(0, |acc, d| acc * 10 + d as u32);
BLEEvent::PairingRequest(code)
}
diff --git a/core/embed/rust/src/trezorhal/ffi.rs b/core/embed/rust/src/trezorhal/ffi.rs
index 138657c6..819ee593 100644
--- a/core/embed/rust/src/trezorhal/ffi.rs
+++ b/core/embed/rust/src/trezorhal/ffi.rs
@@ -3,6 +3,7 @@
#![allow(clippy::upper_case_acronyms)]
#![allow(non_snake_case)]
#![allow(dead_code)]
+#![allow(unnecessary_transmutes)]
#![allow(clippy::transmute_int_to_bool)]
#![allow(clippy::too_many_arguments)]
diff --git a/core/embed/rust/src/ui/component/marquee.rs b/core/embed/rust/src/ui/component/marquee.rs
index 30d2b981..990665db 100644
--- a/core/embed/rust/src/ui/component/marquee.rs
+++ b/core/embed/rust/src/ui/component/marquee.rs
@@ -182,17 +182,13 @@ impl Component for Marquee {
}
match self.state {
- State::Right(_) => {
- if self.is_at_right(now) {
- self.pause_timer.start(ctx, self.pause);
- self.state = State::PauseRight;
- }
+ State::Right(_) if self.is_at_right(now) => {
+ self.pause_timer.start(ctx, self.pause);
+ self.state = State::PauseRight;
}
- State::Left(_) => {
- if self.is_at_left(now) {
- self.pause_timer.start(ctx, self.pause);
- self.state = State::PauseLeft;
- }
+ State::Left(_) if self.is_at_left(now) => {
+ self.pause_timer.start(ctx, self.pause);
+ self.state = State::PauseLeft;
}
_ => {}
}
diff --git a/core/embed/rust/src/ui/component/text/paragraphs.rs b/core/embed/rust/src/ui/component/text/paragraphs.rs
index 639fbdae..07c4dfd6 100644
--- a/core/embed/rust/src/ui/component/text/paragraphs.rs
+++ b/core/embed/rust/src/ui/component/text/paragraphs.rs
@@ -142,7 +142,7 @@ where
}
}
- fn break_pages_from(&self, offset: Option<PageOffset>) -> PageBreakIterator<T> {
+ fn break_pages_from(&self, offset: Option<PageOffset>) -> PageBreakIterator<'_, T> {
PageBreakIterator {
paragraphs: self,
current: offset,
@@ -152,14 +152,14 @@ where
/// Break pages from the start of the document.
///
/// The first pagebreak is at the start of the first screen.
- fn break_pages_from_start(&self) -> PageBreakIterator<T> {
+ fn break_pages_from_start(&self) -> PageBreakIterator<'_, T> {
self.break_pages_from(None)
}
/// Break pages, continuing from the current page.
///
/// The first pagebreak is at the start of the next screen.
- fn break_pages_from_next(&self) -> PageBreakIterator<T> {
+ fn break_pages_from_next(&self) -> PageBreakIterator<'_, T> {
self.break_pages_from(Some(self.offset))
}
diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs
index cfc3f779..121c9bc3 100644
--- a/core/embed/rust/src/ui/layout/obj.rs
+++ b/core/embed/rust/src/ui/layout/obj.rs
@@ -399,7 +399,7 @@ impl LayoutObj {
}
}
- fn inner_mut(&self) -> RefMut<LayoutObjInner> {
+ fn inner_mut(&self) -> RefMut<'_, LayoutObjInner> {
self.inner.borrow_mut()
}
diff --git a/core/embed/rust/src/ui/layout/util.rs b/core/embed/rust/src/ui/layout/util.rs
index 0029f6e9..289f8cf6 100644
--- a/core/embed/rust/src/ui/layout/util.rs
+++ b/core/embed/rust/src/ui/layout/util.rs
@@ -159,7 +159,7 @@ impl ParagraphSource<'static> for PropsList {
let obj: Obj;
let style: &TextStyle;
- if index % 2 == 0 {
+ if index.is_multiple_of(2) {
if !key.is_str() && key != Obj::const_none() {
return Err(Error::TypeError);
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/coinjoin_progress.rs b/core/embed/rust/src/ui/layout_bolt/component/coinjoin_progress.rs
index 3ac17d34..fa5a134b 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/coinjoin_progress.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/coinjoin_progress.rs
@@ -100,10 +100,10 @@ where
ctx.request_anim_frame();
ctx.request_paint();
}
- Event::Progress(new_value, _new_description) => {
- if mem::replace(&mut self.value, new_value) != new_value {
- ctx.request_paint();
- }
+ Event::Progress(new_value, _new_description)
+ if mem::replace(&mut self.value, new_value) != new_value =>
+ {
+ ctx.request_paint();
}
_ => {}
}
diff --git a/core/embed/rust/src/ui/layout_caesar/component/changing_text.rs b/core/embed/rust/src/ui/layout_caesar/component/changing_text.rs
index 878a79a1..bb662d9e 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/changing_text.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/changing_text.rs
@@ -138,7 +138,11 @@ impl ChangingTextLine {
// Creating the notion of motion by shifting the text left and right with
// each new text character.
// (So that it is apparent for the user that the text is changing.)
- let x_offset = if self.text.len() % 2 == 0 { 0 } else { 2 };
+ let x_offset = if self.text.len().is_multiple_of(2) {
+ 0
+ } else {
+ 2
+ };
let baseline = Point::new(self.pad.area.x0 + x_offset, self.y_baseline());
shape::Text::new(baseline, &text_to_display, self.font).render(target);
diff --git a/core/embed/rust/src/ui/layout_caesar/component/hold_to_confirm.rs b/core/embed/rust/src/ui/layout_caesar/component/hold_to_confirm.rs
index 9ae98b2c..34784756 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/hold_to_confirm.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/hold_to_confirm.rs
@@ -100,10 +100,8 @@ impl Component for HoldToConfirm {
Event::Button(ButtonEvent::HoldStarted) => {
self.loader.start_growing(ctx, Instant::now());
}
- Event::Button(ButtonEvent::HoldEnded) => {
- if self.loader.is_animating() {
- self.loader.start_shrinking(ctx, Instant::now());
- }
+ Event::Button(ButtonEvent::HoldEnded) if self.loader.is_animating() => {
+ self.loader.start_shrinking(ctx, Instant::now());
}
Event::Button(ButtonEvent::HoldCanceled) => {
self.loader.shrink_completely(ctx, Instant::now());
diff --git a/core/embed/rust/src/ui/layout_caesar/component/input_methods/pin.rs b/core/embed/rust/src/ui/layout_caesar/component/input_methods/pin.rs
index 1878a771..d51291b7 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/input_methods/pin.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/input_methods/pin.rs
@@ -270,11 +270,9 @@ impl Component for PinEntry<'_> {
});
match event {
// Timeout for showing the last digit.
- Event::Timer(_) if self.timeout_timer.expire(event) => {
- if self.show_last_digit {
- self.show_last_digit = false;
- self.update(ctx)
- }
+ Event::Timer(_) if self.timeout_timer.expire(event) && self.show_last_digit => {
+ self.show_last_digit = false;
+ self.update(ctx)
}
// Other timers are ignored.
Event::Timer(_) => {}
diff --git a/core/embed/rust/src/ui/layout_caesar/component/loader.rs b/core/embed/rust/src/ui/layout_caesar/component/loader.rs
index 05ddbead..5f7d5cb8 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/loader.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/loader.rs
@@ -178,7 +178,7 @@ impl Loader {
let split_point = (((width as i32 + 1) * done) / (display::LOADER_MAX as i32)) as i16;
let (r_left, r_right) = self.area.split_left(split_point);
let parts = [(r_left, true), (r_right, false)];
- parts.map(|(r, invert)| {
+ parts.iter().for_each(|&(r, invert)| {
target.in_clip(r, &|target| {
if invert {
shape::Bar::new(self.area)
diff --git a/core/embed/rust/src/ui/layout_caesar/component/title.rs b/core/embed/rust/src/ui/layout_caesar/component/title.rs
index 9cbfaf1e..35e54822 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/title.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/title.rs
@@ -33,7 +33,7 @@ impl Title {
self
}
- pub fn get_text(&self) -> TString {
+ pub fn get_text(&self) -> TString<'_> {
self.title
}
diff --git a/core/embed/rust/src/ui/layout_delizia/component/button.rs b/core/embed/rust/src/ui/layout_delizia/component/button.rs
index f594d0f8..94c8e800 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/button.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/button.rs
@@ -194,10 +194,10 @@ impl Button {
style: &ButtonStyle,
alpha: u8,
) {
- if self.radius.is_some() {
+ if let Some(r) = self.radius {
shape::Bar::new(self.area)
.with_bg(style.background_color)
- .with_radius(self.radius.unwrap() as i16)
+ .with_radius(r.into())
.with_thickness(2)
.with_fg(style.button_color)
.with_alpha(alpha)
diff --git a/core/embed/rust/src/ui/layout_delizia/component/coinjoin_progress.rs b/core/embed/rust/src/ui/layout_delizia/component/coinjoin_progress.rs
index 7920dd46..9e970336 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/coinjoin_progress.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/coinjoin_progress.rs
@@ -95,10 +95,10 @@ where
ctx.request_anim_frame();
ctx.request_paint();
}
- Event::Progress(new_value, _new_description) => {
- if mem::replace(&mut self.value, new_value) != new_value {
- ctx.request_paint();
- }
+ Event::Progress(new_value, _new_description)
+ if mem::replace(&mut self.value, new_value) != new_value =>
+ {
+ ctx.request_paint();
}
_ => {}
}
diff --git a/core/embed/rust/src/ui/layout_delizia/component/hold_to_confirm.rs b/core/embed/rust/src/ui/layout_delizia/component/hold_to_confirm.rs
index 26056f09..f1c5d3d0 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/hold_to_confirm.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/hold_to_confirm.rs
@@ -217,23 +217,19 @@ impl Component for HoldToConfirm {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
let btn_msg = self.button.event(ctx, event);
match btn_msg {
- Some(ButtonMsg::Pressed) => {
- if !self.anim.is_locked() {
- self.anim.start();
- ctx.request_anim_frame();
- ctx.request_paint();
- ctx.disable_swipe();
- self.finalizing = false;
- }
+ Some(ButtonMsg::Pressed) if !self.anim.is_locked() => {
+ self.anim.start();
+ ctx.request_anim_frame();
+ ctx.request_paint();
+ ctx.disable_swipe();
+ self.finalizing = false;
}
- Some(ButtonMsg::Released) => {
- if !self.anim.is_locked() {
- self.anim.reset();
- ctx.request_anim_frame();
- ctx.request_paint();
- ctx.enable_swipe();
- self.finalizing = false;
- }
+ Some(ButtonMsg::Released) if !self.anim.is_locked() => {
+ self.anim.reset();
+ ctx.request_anim_frame();
+ ctx.request_paint();
+ ctx.enable_swipe();
+ self.finalizing = false;
}
Some(ButtonMsg::Clicked) => {
if animation_disabled() {
diff --git a/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs b/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs
index ce0e9444..3476c143 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs
@@ -797,14 +797,12 @@ impl LockscreenAnim {
ctx.request_anim_frame();
}
}
- Event::Timer(EventCtx::ANIM_FRAME_TIMER) => {
- if !animation_disabled() {
- if !self.timer.is_running() {
- self.timer.start();
- }
- ctx.request_anim_frame();
- ctx.request_paint();
+ Event::Timer(EventCtx::ANIM_FRAME_TIMER) if !animation_disabled() => {
+ if !self.timer.is_running() {
+ self.timer.start();
}
+ ctx.request_anim_frame();
+ ctx.request_paint();
}
_ => {}
}
diff --git a/core/embed/rust/src/ui/layout_delizia/component/swipe_content.rs b/core/embed/rust/src/ui/layout_delizia/component/swipe_content.rs
index cd8e147e..9faa83d2 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/swipe_content.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/swipe_content.rs
@@ -222,11 +222,9 @@ impl SwipeContext {
if let Event::Swipe(SwipeEvent::Move(dir, progress)) = event {
match dir {
- Direction::Up | Direction::Down => {
- if animate {
- self.dir = dir;
- self.progress = progress;
- }
+ Direction::Up | Direction::Down if animate => {
+ self.dir = dir;
+ self.progress = progress;
}
_ => {}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/bootloader/bld_text_screen.rs b/core/embed/rust/src/ui/layout_eckhart/bootloader/bld_text_screen.rs
index 96736ca7..d968b795 100644
--- a/core/embed/rust/src/ui/layout_eckhart/bootloader/bld_text_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/bootloader/bld_text_screen.rs
@@ -149,11 +149,9 @@ impl<'a> Component for BldTextScreen<'a> {
match self.header.event(ctx, event) {
// FIXME: This is a hack for `screen_install_confirm` which expects `2` for the Menu
Some(BldHeaderMsg::Menu) => return Some(BldTextScreenMsg::Cancelled),
- Some(BldHeaderMsg::Info) => {
- if !self.more_info_showing {
- self.more_info_showing = true;
- return None;
- }
+ Some(BldHeaderMsg::Info) if !self.more_info_showing => {
+ self.more_info_showing = true;
+ return None;
}
_ => (),
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/component/button.rs b/core/embed/rust/src/ui/layout_eckhart/component/button.rs
index e8167777..b3ce05a5 100644
--- a/core/embed/rust/src/ui/layout_eckhart/component/button.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/component/button.rs
@@ -408,7 +408,7 @@ impl Button {
self.style().font.line_height()
} else if break_words {
if self.stylesheet.normal.font.text_width(text) <= width {
- return self.style().font.line_height();
+ self.style().font.line_height()
} else {
self.style().font.line_height() * 2 - constant::LINE_SPACE
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs
index 885158b1..a27f2ccd 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs
@@ -653,11 +653,10 @@ impl ShowLabelAnimation {
pub fn process_event(&mut self, ctx: &mut EventCtx, event: Event) {
match event {
- Event::Attach(_) => {
- if !self.hidden {
+ Event::Attach(_)
+ if !self.hidden => {
self.timer.start(ctx, Self::HIDE_AFTER);
}
- }
Event::Timer(EventCtx::ANIM_FRAME_TIMER) => {
if self.is_active() {
ctx.request_anim_frame();
@@ -685,9 +684,9 @@ impl ShowLabelAnimation {
ctx.request_paint();
}
}
- Event::Touch(TouchEvent::TouchStart(point)) => {
+ Event::Touch(TouchEvent::TouchStart(point))
// Only trigger animation at the top of the screen
- if point.y <= SCREEN.height() / 2 {
+ if point.y <= SCREEN.height() / 2 => {
if self.animated {
if !self.animating {
if self.hidden {
@@ -715,7 +714,6 @@ impl ShowLabelAnimation {
}
}
}
- }
_ => {}
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs
index 90619984..680e57c0 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs
@@ -195,12 +195,11 @@ where
self.on_input_change(ctx);
return None;
}
- Some(KeypadMsg::Back) => {
+ Some(KeypadMsg::Back)
// Back button will cause going back to the previous word when allowed.
- if self.can_go_back {
+ if self.can_go_back => {
return Some(MnemonicKeyboardMsg::Previous);
}
- }
Some(KeypadMsg::EraseShort) => {
self.input.on_backspace_click(ctx);
self.on_input_change(ctx);
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs
index c48056aa..26d2ebe4 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs
@@ -121,7 +121,10 @@ impl PassphraseInput {
let visible_icons = visible_len - last_char as usize;
// Jiggle when overflowed.
- if pp_len > visible_len && pp_len % 2 == 0 && self.display_style != DisplayStyle::Shown {
+ if pp_len > visible_len
+ && pp_len.is_multiple_of(2)
+ && self.display_style != DisplayStyle::Shown
+ {
cursor.x += Self::TWITCH;
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/pin.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/pin.rs
index f02f4228..4e25d984 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/pin.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/pin.rs
@@ -410,7 +410,10 @@ impl PinInput {
let visible_icons = visible_len - last_digit as usize;
// Jiggle when overflowed.
- if pin_len > visible_len && pin_len % 2 == 0 && self.display_style != DisplayStyle::Shown {
+ if pin_len > visible_len
+ && pin_len.is_multiple_of(2)
+ && self.display_style != DisplayStyle::Shown
+ {
cursor.x += Self::TWITCH;
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/string.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/string.rs
index f183b1c8..0e5e6a12 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/string.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/string.rs
@@ -119,8 +119,7 @@ impl<I: StringInput> StringKeyboard<I> {
let layout = self.active_layout as usize;
let styles = Self::key_style(self.active_layout);
- for idx in 0..KEY_COUNT {
- let text = KEYBOARD[layout][idx];
+ for (idx, text) in KEYBOARD[layout].iter().enumerate() {
let content = Self::key_content(text);
self.keypad.set_key_content(idx, content);
self.keypad
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
index 4196d08f..1711f542 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
@@ -194,7 +194,7 @@ impl ValueKeypad {
let vertical_spacing = (self.area.height() - Self::BUTTON_SIZE.y * Self::ROWS as i16)
/ (Self::ROWS as i16 - 1);
- if idx % Self::ROWS == 0 {
+ if idx.is_multiple_of(Self::ROWS) {
Insets::bottom(vertical_spacing / 2)
} else if idx % Self::ROWS == Self::ROWS - 1 {
Insets::top(vertical_spacing / 2)
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/progress_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/progress_screen.rs
index d8fea1ca..97ee90d5 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/progress_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/progress_screen.rs
@@ -121,15 +121,15 @@ impl Component for ProgressScreen {
ctx.request_anim_frame();
ctx.request_paint();
}
- Event::Progress(new_value, new_description) => {
- if mem::replace(&mut self.value, new_value) != new_value {
- if !animation_disabled() {
- ctx.request_paint();
- }
- if self.description.text() != &new_description {
- self.description.set_text(new_description);
- ctx.request_paint();
- }
+ Event::Progress(new_value, new_description)
+ if mem::replace(&mut self.value, new_value) != new_value =>
+ {
+ if !animation_disabled() {
+ ctx.request_paint();
+ }
+ if self.description.text() != &new_description {
+ self.description.set_text(new_description);
+ ctx.request_paint();
}
}
_ => {}
diff --git a/core/embed/rust/src/ui/shape/base.rs b/core/embed/rust/src/ui/shape/base.rs
index f8cbb9aa..b5daf6ba 100644
--- a/core/embed/rust/src/ui/shape/base.rs
+++ b/core/embed/rust/src/ui/shape/base.rs
@@ -46,6 +46,7 @@ pub trait ShapeClone<'s> {
///
/// The method is used by `ProgressiveRenderer` to store shape objects for
/// deferred drawing.
+ #[allow(clippy::mut_from_ref)]
fn clone_at_bump<T>(self, bump: &'s T) -> Option<&'s mut dyn Shape<'s>>
where
T: LocalAllocLeakExt<'s>;
diff --git a/core/embed/rust/src/ui/shape/bitmap.rs b/core/embed/rust/src/ui/shape/bitmap.rs
index d5c2c790..ec6190c2 100644
--- a/core/embed/rust/src/ui/shape/bitmap.rs
+++ b/core/embed/rust/src/ui/shape/bitmap.rs
@@ -87,13 +87,9 @@ impl<'a> Bitmap<'a> {
assert!(stride >= min_stride);
assert!(buff.as_ptr().align_offset(alignment) == 0);
- assert!(stride % alignment == 0);
+ assert!(stride.is_multiple_of(alignment));
- let max_height = if stride == 0 {
- size.y as usize
- } else {
- buff.len() / stride
- };
+ let max_height = buff.len().checked_div(stride).unwrap_or(size.y as usize);
if size.y as usize > max_height {
if let Some(min_height) = min_height {
@@ -164,7 +160,7 @@ impl<'a> Bitmap<'a> {
self.format
}
- pub fn view(&self) -> BitmapView {
+ pub fn view(&self) -> BitmapView<'_> {
BitmapView::new(self)
}
@@ -178,7 +174,7 @@ impl<'a> Bitmap<'a> {
let offset = row as usize * (self.stride / core::mem::size_of::<T>());
- if offset % core::mem::align_of::<T>() != 0 {
+ if !offset.is_multiple_of(core::mem::align_of::<T>()) {
return None;
}
@@ -210,7 +206,7 @@ impl<'a> Bitmap<'a> {
let offset = row as usize * (self.stride / core::mem::size_of::<T>());
- if offset % core::mem::align_of::<T>() != 0 {
+ if !offset.is_multiple_of(core::mem::align_of::<T>()) {
return None;
}
@@ -243,7 +239,7 @@ impl<'a> Bitmap<'a> {
let offset = self.stride * row as usize;
- if offset % core::mem::align_of::<T>() != 0 {
+ if !offset.is_multiple_of(core::mem::align_of::<T>()) {
return None;
}
diff --git a/core/embed/rust/src/ui/shape/cache/drawing_cache.rs b/core/embed/rust/src/ui/shape/cache/drawing_cache.rs
index 516f3d7d..242879f0 100644
--- a/core/embed/rust/src/ui/shape/cache/drawing_cache.rs
+++ b/core/embed/rust/src/ui/shape/cache/drawing_cache.rs
@@ -99,19 +99,19 @@ impl<'a> DrawingCache<'a> {
}
/// Returns an object for decompression of TOIF images
- pub fn zlib(&self) -> RefMut<ZlibCache<'a>> {
+ pub fn zlib(&self) -> RefMut<'_, ZlibCache<'a>> {
self.zlib_cache.borrow_mut()
}
/// Returns an object for decompression of JPEG images
#[cfg(all(feature = "ui_jpeg", not(feature = "hw_jpeg_decoder")))]
- pub fn jpeg(&self) -> RefMut<JpegCache<'a>> {
+ pub fn jpeg(&self) -> RefMut<'_, JpegCache<'a>> {
self.jpeg_cache.borrow_mut()
}
/// Returns an object providing blurring algorithm
#[cfg(feature = "ui_blurring")]
- pub fn blur(&self) -> RefMut<BlurCache<'a>> {
+ pub fn blur(&self) -> RefMut<'_, BlurCache<'a>> {
self.blur_cache.borrow_mut()
}
diff --git a/core/embed/rust/src/ui/shape/canvas/common.rs b/core/embed/rust/src/ui/shape/canvas/common.rs
index 1502b2d7..70db7a08 100644
--- a/core/embed/rust/src/ui/shape/canvas/common.rs
+++ b/core/embed/rust/src/ui/shape/canvas/common.rs
@@ -83,7 +83,7 @@ pub trait CanvasBuilder<'a> {
pub trait Canvas: BasicCanvas {
/// Returns a non-mutable view of the underlying bitmap.
- fn view(&self) -> BitmapView;
+ fn view(&self) -> BitmapView<'_>;
/// Draw a pixel at specified coordinates.
fn draw_pixel(&mut self, pt: Point, color: Color);
diff --git a/core/embed/rust/src/ui/shape/canvas/mono8.rs b/core/embed/rust/src/ui/shape/canvas/mono8.rs
index d6f60c50..51a5c6e1 100644
--- a/core/embed/rust/src/ui/shape/canvas/mono8.rs
+++ b/core/embed/rust/src/ui/shape/canvas/mono8.rs
@@ -88,7 +88,7 @@ impl<'a> CanvasBuilder<'a> for Mono8Canvas<'a> {
}
impl<'a> Canvas for Mono8Canvas<'a> {
- fn view(&self) -> BitmapView {
+ fn view(&self) -> BitmapView<'_> {
BitmapView::new(&self.bitmap)
}
diff --git a/core/embed/rust/src/ui/shape/canvas/rgb565.rs b/core/embed/rust/src/ui/shape/canvas/rgb565.rs
index a74b5aa1..0fa0f464 100644
--- a/core/embed/rust/src/ui/shape/canvas/rgb565.rs
+++ b/core/embed/rust/src/ui/shape/canvas/rgb565.rs
@@ -88,7 +88,7 @@ impl<'a> CanvasBuilder<'a> for Rgb565Canvas<'a> {
}
impl<'a> Canvas for Rgb565Canvas<'a> {
- fn view(&self) -> BitmapView {
+ fn view(&self) -> BitmapView<'_> {
BitmapView::new(&self.bitmap)
}
diff --git a/core/embed/rust/src/ui/shape/canvas/rgba8888.rs b/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
index 2b7248e3..031645e0 100644
--- a/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
+++ b/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
@@ -88,7 +88,7 @@ impl<'a> CanvasBuilder<'a> for Rgba8888Canvas<'a> {
}
impl<'a> Canvas for Rgba8888Canvas<'a> {
- fn view(&self) -> BitmapView {
+ fn view(&self) -> BitmapView<'_> {
BitmapView::new(&self.bitmap)
}
diff --git a/core/embed/rust/src/ui/shape/utils/imagebuf.rs b/core/embed/rust/src/ui/shape/utils/imagebuf.rs
index a5c34cb6..5326c2ac 100644
--- a/core/embed/rust/src/ui/shape/utils/imagebuf.rs
+++ b/core/embed/rust/src/ui/shape/utils/imagebuf.rs
@@ -80,7 +80,7 @@ where
}
/// Returns the immutable view of the bitmap in the image buffer.
- pub fn view(&self) -> BitmapView {
+ pub fn view(&self) -> BitmapView<'_> {
self.canvas.view()
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.