style(core/rust): fix clippy::cast_lossless where possible
What changed, and why it matters
This is a code-style cleanup commit in the Trezor firmware's Rust code. It replaces plain `as` type casts with explicit conversion methods like `u32::from(...)`, `i16::from(...)`, and `f32::from(...)` to satisfy the Rust Clippy lint `cast_lossless`. These changes do not alter program behavior; they only make the code clearer and avoid compiler warnings. There is no security fix or functional change here.
No security action required. This is a routine style/lint cleanup. Reviewers can treat it as non-functional and focus verification on CI passing (clippy clean) and no regressions in affected modules.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit applies the clippy::cast_lossless lint across ~80 Rust files in core/embed/rust/. The lint flags lossless as casts between numeric types (e.g., u8 as u32, i16 as f32) and recommends using From-trait methods (u32::from(x), f32::from(x), .into(), etc.) instead. All modified sites are semantically equivalent: the source values fit losslessly in the target type. The diff touches UI rendering, protobuf encoding, CRC/base64 utilities, and trace/debug output, but none of the changes affect control flow, bounds checks, or cryptographic logic.
Changed components
core/embed/rust/src/crypto/crc32.rscore/embed/rust/src/io.rscore/embed/rust/src/micropython/buffer.rscore/embed/rust/src/micropython/obj.rscore/embed/rust/src/protobuf/encode.rscore/embed/rust/src/smp/base64.rscore/embed/rust/src/smp/crc16.rscore/embed/rust/src/smp/mod.rscore/embed/rust/src/strutil.rscore/embed/rust/src/trezorhal/ble/mod.rscore/embed/rust/src/trezorhal/uzlib.rscore/embed/rust/src/ui/component/*core/embed/rust/src/ui/display/*core/embed/rust/src/ui/layout_bolt/*core/embed/rust/src/ui/layout_caesar/*core/embed/rust/src/ui/layout_delizia/*core/embed/rust/src/ui/layout_eckhart/*core/embed/rust/src/ui/lerp.rscore/embed/rust/src/ui/shape/canvas/*core/embed/rust/src/ui/shape/qrcode.rscore/embed/rust/src/ui/shape/utils/*Inspect captured patch +191 / −183
diff --git a/core/embed/rust/src/crypto/crc32.rs b/core/embed/rust/src/crypto/crc32.rs
index 74ada0b8..d1990640 100644
--- a/core/embed/rust/src/crypto/crc32.rs
+++ b/core/embed/rust/src/crypto/crc32.rs
@@ -14,7 +14,7 @@ impl Crc32 {
pub fn update(mut self, data: &[u8]) -> Self {
for b in data {
- self.value ^= *b as u32;
+ self.value ^= u32::from(*b);
self.value = CRC32TAB[(self.value & 0x0f) as usize] ^ (self.value >> 4);
self.value = CRC32TAB[(self.value & 0x0f) as usize] ^ (self.value >> 4);
}
diff --git a/core/embed/rust/src/io.rs b/core/embed/rust/src/io.rs
index 89ca5f66..e5bb3f4f 100644
--- a/core/embed/rust/src/io.rs
+++ b/core/embed/rust/src/io.rs
@@ -63,7 +63,7 @@ impl<'a> InputStream<'a> {
let mut shift = 0;
loop {
let byte = self.read_byte()?;
- uint += (byte as u64 & 0x7F) << shift;
+ uint += (u64::from(byte) & 0x7F) << shift;
shift += 7;
if byte & 0x80 == 0 {
break;
diff --git a/core/embed/rust/src/micropython/buffer.rs b/core/embed/rust/src/micropython/buffer.rs
index 9c807041..ecde85a0 100644
--- a/core/embed/rust/src/micropython/buffer.rs
+++ b/core/embed/rust/src/micropython/buffer.rs
@@ -200,7 +200,7 @@ fn get_buffer_info(obj: Obj, flags: u32) -> Result<ffi::mp_buffer_info_t, Error>
// `bufinfo.buf` contains a pointer to data of `bufinfo.len` bytes.
// EXCEPTION: Does not raise for Micropython's builtin types, and we don't
// implement custom buffer protocols.
- if unsafe { ffi::mp_get_buffer(obj, &mut bufinfo, flags as _) } {
+ if unsafe { ffi::mp_get_buffer(obj, &mut bufinfo, flags.into()) } {
Ok(bufinfo)
} else {
Err(Error::TypeError)
diff --git a/core/embed/rust/src/micropython/obj.rs b/core/embed/rust/src/micropython/obj.rs
index 99e488a3..dc391edb 100644
--- a/core/embed/rust/src/micropython/obj.rs
+++ b/core/embed/rust/src/micropython/obj.rs
@@ -348,7 +348,7 @@ impl TryFrom<(Obj, Obj, Obj)> for Obj {
impl From<u8> for Obj {
fn from(val: u8) -> Self {
// `u8` will fit into smallint so no error should happen here.
- Obj::small_int(val as u16)
+ Obj::small_int(u16::from(val))
}
}
diff --git a/core/embed/rust/src/protobuf/encode.rs b/core/embed/rust/src/protobuf/encode.rs
index 187a419f..cfc43a43 100644
--- a/core/embed/rust/src/protobuf/encode.rs
+++ b/core/embed/rust/src/protobuf/encode.rs
@@ -64,8 +64,8 @@ impl Encoder {
let field_key = {
let prim_type = field.get_type().primitive_type();
- let prim_type = prim_type as u64;
- let field_tag = field.tag as u64;
+ let prim_type = u64::from(prim_type);
+ let field_tag = u64::from(field.tag);
field_tag << 3 | prim_type
};
diff --git a/core/embed/rust/src/smp/base64.rs b/core/embed/rust/src/smp/base64.rs
index ad2f7f3c..fefcfe8f 100644
--- a/core/embed/rust/src/smp/base64.rs
+++ b/core/embed/rust/src/smp/base64.rs
@@ -35,7 +35,7 @@ pub fn base64_encode(input: &[u8], output: &mut [u8]) -> Result<usize, Base64Err
let c = if i + 2 < len { input[i + 2] } else { 0 };
i += 3;
- let triple = ((a as u32) << 16) | ((b as u32) << 8) | (c as u32);
+ let triple = (u32::from(a) << 16) | (u32::from(b) << 8) | u32::from(c);
output[j] = B64_TABLE[((triple >> 18) & 0x3F) as usize];
output[j + 1] = B64_TABLE[((triple >> 12) & 0x3F) as usize];
output[j + 2] = B64_TABLE[((triple >> 6) & 0x3F) as usize];
@@ -90,17 +90,17 @@ pub fn base64_decode(input: &[u8], output: &mut [u8]) -> Result<usize, Base64Err
let mut i = 0;
let mut j = 0;
while i < len {
- let v1 = base64_char_value(input[i]).ok_or(Base64Error::InvalidCharacter)? as u32;
- let v2 = base64_char_value(input[i + 1]).ok_or(Base64Error::InvalidCharacter)? as u32;
+ let v1 = u32::from(base64_char_value(input[i]).ok_or(Base64Error::InvalidCharacter)?);
+ let v2 = u32::from(base64_char_value(input[i + 1]).ok_or(Base64Error::InvalidCharacter)?);
let v3 = if input[i + 2] == b'=' {
0
} else {
- base64_char_value(input[i + 2]).ok_or(Base64Error::InvalidCharacter)? as u32
+ u32::from(base64_char_value(input[i + 2]).ok_or(Base64Error::InvalidCharacter)?)
};
let v4 = if input[i + 3] == b'=' {
0
} else {
- base64_char_value(input[i + 3]).ok_or(Base64Error::InvalidCharacter)? as u32
+ u32::from(base64_char_value(input[i + 3]).ok_or(Base64Error::InvalidCharacter)?)
};
i += 4;
diff --git a/core/embed/rust/src/smp/crc16.rs b/core/embed/rust/src/smp/crc16.rs
index beffeb66..ccee5be6 100644
--- a/core/embed/rust/src/smp/crc16.rs
+++ b/core/embed/rust/src/smp/crc16.rs
@@ -4,7 +4,7 @@ pub fn crc16_itu_t(mut seed: u16, data: &[u8]) -> u16 {
// swap high/low byte:
seed = seed.rotate_left(8);
// mix in next input byte
- seed ^= byte as u16;
+ seed ^= u16::from(byte);
// apply the ITU-T polynomial bitwise mix
seed ^= (seed & 0x00FF) >> 4;
seed ^= seed << 12;
diff --git a/core/embed/rust/src/smp/mod.rs b/core/embed/rust/src/smp/mod.rs
index cb8dc42e..697c239b 100644
--- a/core/embed/rust/src/smp/mod.rs
+++ b/core/embed/rust/src/smp/mod.rs
@@ -306,7 +306,7 @@ impl SmpReceiver {
let received_len = self.rx_msg_len + len;
// the first two bytes of rx_msg are the length field
- let msg_len = ((self.rx_msg[0] as u16) << 8) | (self.rx_msg[1] as u16);
+ let msg_len = (u16::from(self.rx_msg[0]) << 8) | u16::from(self.rx_msg[1]);
// too long? (received_len - 2) > msg_len
if received_len.saturating_sub(2) > msg_len as usize {
diff --git a/core/embed/rust/src/strutil.rs b/core/embed/rust/src/strutil.rs
index 616ba4df..5895129e 100644
--- a/core/embed/rust/src/strutil.rs
+++ b/core/embed/rust/src/strutil.rs
@@ -60,7 +60,7 @@ pub fn format_i64(num: i64, buffer: &mut [u8]) -> Option<&str> {
/// Example: code=123, width=6 produces "0 0 0 1 2 3"
pub fn format_pairing_code(code: u32, width: usize) -> ShortString {
let mut buf = [0; 20];
- let code_str = unwrap!(format_i64(code as _, &mut buf));
+ let code_str = unwrap!(format_i64(code.into(), &mut buf));
let mut formatted_code = ShortString::new();
let padding = width.saturating_sub(code_str.len());
diff --git a/core/embed/rust/src/trezorhal/ble/mod.rs b/core/embed/rust/src/trezorhal/ble/mod.rs
index 46bc9c63..c9b87038 100644
--- a/core/embed/rust/src/trezorhal/ble/mod.rs
+++ b/core/embed/rust/src/trezorhal/ble/mod.rs
@@ -41,7 +41,7 @@ pub fn ble_parse_event(event: ffi::ble_event_t) -> BLEEvent {
.iter()
.take(6)
.map(|&b| b - b'0')
- .fold(0, |acc, d| acc * 10 + d as u32);
+ .fold(0, |acc, d| acc * 10 + u32::from(d));
BLEEvent::PairingRequest(code)
}
ffi::ble_event_type_t_BLE_PAIRING_CANCELLED => BLEEvent::PairingCanceled,
diff --git a/core/embed/rust/src/trezorhal/uzlib.rs b/core/embed/rust/src/trezorhal/uzlib.rs
index 5ff7f7b4..f3ae8af6 100644
--- a/core/embed/rust/src/trezorhal/uzlib.rs
+++ b/core/embed/rust/src/trezorhal/uzlib.rs
@@ -236,7 +236,7 @@ unsafe extern "C" fn zlib_reader_callback(uncomp: *mut ffi::uzlib_uncomp) -> i32
let mut ctx = unwrap!(unsafe { ctx.as_ref() }).borrow_mut();
match ctx.reader_callback(uncomp) {
- Some(byte) => byte as i32,
+ Some(byte) => i32::from(byte),
None => -1, // EOF
}
}
diff --git a/core/embed/rust/src/ui/component/qr_code.rs b/core/embed/rust/src/ui/component/qr_code.rs
index cff45aef..6d173636 100644
--- a/core/embed/rust/src/ui/component/qr_code.rs
+++ b/core/embed/rust/src/ui/component/qr_code.rs
@@ -114,7 +114,7 @@ impl Component for Qr {
if self.border > 0 {
shape::Bar::new(qr_area.expand(self.border))
.with_bg(LIGHT)
- .with_radius(CORNER_RADIUS as i16 + 1)
+ .with_radius(i16::from(CORNER_RADIUS) + 1)
.render(target);
}
diff --git a/core/embed/rust/src/ui/component/swipe.rs b/core/embed/rust/src/ui/component/swipe.rs
index b50f06f3..87d95762 100644
--- a/core/embed/rust/src/ui/component/swipe.rs
+++ b/core/embed/rust/src/ui/component/swipe.rs
@@ -63,7 +63,7 @@ impl Swipe {
}
fn ratio(&self, dist: i16) -> f32 {
- (dist as f32 / Self::DISTANCE as f32).min(1.0)
+ (f32::from(dist) / Self::DISTANCE as f32).min(1.0)
}
}
diff --git a/core/embed/rust/src/ui/component/swipe_detect.rs b/core/embed/rust/src/ui/component/swipe_detect.rs
index b2e2aa20..0a6ebada 100644
--- a/core/embed/rust/src/ui/component/swipe_detect.rs
+++ b/core/embed/rust/src/ui/component/swipe_detect.rs
@@ -219,7 +219,7 @@ impl SwipeDetect {
}
fn progress(&self, val: u16) -> i16 {
- ((val as f32 / Self::DISTANCE as f32) * Self::PROGRESS_MAX as f32) as i16
+ ((f32::from(val) / f32::from(Self::DISTANCE)) * f32::from(Self::PROGRESS_MAX)) as i16
}
fn eval_anim_frame(&mut self, ctx: &mut EventCtx) -> Option<SwipeEvent> {
@@ -372,7 +372,7 @@ impl SwipeDetect {
ctx.request_paint();
if !animation_disabled() {
- let done = self.moved as f32 / Self::PROGRESS_MAX as f32;
+ let done = f32::from(self.moved) / f32::from(Self::PROGRESS_MAX);
let ratio = if final_value == 0 { done } else { 1.0 - done };
let duration = config
diff --git a/core/embed/rust/src/ui/component/timeout.rs b/core/embed/rust/src/ui/component/timeout.rs
index 77da02b0..625f2c12 100644
--- a/core/embed/rust/src/ui/component/timeout.rs
+++ b/core/embed/rust/src/ui/component/timeout.rs
@@ -42,6 +42,6 @@ impl Component for Timeout {
impl crate::trace::Trace for Timeout {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("Timeout");
- t.int("time_ms", self.time_ms as i64);
+ t.int("time_ms", i64::from(self.time_ms));
}
}
diff --git a/core/embed/rust/src/ui/display/color.rs b/core/embed/rust/src/ui/display/color.rs
index 0bf42bf1..6e3501c5 100644
--- a/core/embed/rust/src/ui/display/color.rs
+++ b/core/embed/rust/src/ui/display/color.rs
@@ -102,13 +102,13 @@ impl Color {
#[cfg(feature = "ui_color_32bit")]
pub fn to_u16(self) -> u16 {
- (((self.r() & 0xF8) as u16) << 8)
- | (((self.g() & 0xFC) as u16) << 3)
- | ((self.b() & 0xF8) as u16 >> 3)
+ (u16::from(self.r() & 0xF8) << 8)
+ | (u16::from(self.g() & 0xFC) << 3)
+ | (u16::from(self.b() & 0xF8) >> 3)
}
pub fn to_u32(self) -> u32 {
- ((self.r() as u32) << 16) | ((self.g() as u32) << 8) | (self.b() as u32) | 0xff000000
+ (u32::from(self.r()) << 16) | (u32::from(self.g()) << 8) | u32::from(self.b()) | 0xff000000
}
pub fn hi_byte(self) -> u8 {
@@ -147,11 +147,11 @@ impl Color {
/// If `alpha` equals 0, the background color (`self`) is used.
/// If `alpha` equals 255, the foreground color (`fg`) is used.
pub fn blend(self, fg: Color, alpha: u8) -> Color {
- let fg_mul = alpha as u16;
- let bg_mul = (255 - alpha) as u16;
- let r = (fg.r() as u16) * fg_mul + (self.r() as u16) * bg_mul;
- let g = (fg.g() as u16) * fg_mul + (self.g() as u16) * bg_mul;
- let b = (fg.b() as u16) * fg_mul + (self.b() as u16) * bg_mul;
+ let fg_mul = u16::from(alpha);
+ let bg_mul = u16::from(255 - alpha);
+ let r = u16::from(fg.r()) * fg_mul + u16::from(self.r()) * bg_mul;
+ let g = u16::from(fg.g()) * fg_mul + u16::from(self.g()) * bg_mul;
+ let b = u16::from(fg.b()) * fg_mul + u16::from(self.b()) * bg_mul;
Color::rgb((r / 255) as u8, (g / 255) as u8, (b / 255) as u8)
}
}
diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs
index 73919dc0..b6569195 100644
--- a/core/embed/rust/src/ui/display/font.rs
+++ b/core/embed/rust/src/ui/display/font.rs
@@ -92,8 +92,8 @@ impl<'a> Glyph<'a> {
/// - 4: y-bearing
/// - 5...: bitmap data, packed according to FONT_BPP (bits per pixel)
pub fn load(data: &'a [u8]) -> Self {
- let width = data[0] as i16;
- let height = data[1] as i16;
+ let width = i16::from(data[0]);
+ let height = i16::from(data[1]);
let size = calculate_glyph_size(data);
// This should check for equality but due to a previous bug in font generator,
@@ -102,9 +102,9 @@ impl<'a> Glyph<'a> {
Glyph {
width,
height,
- adv: data[2] as i16,
- bearing_x: data[3] as i16,
- bearing_y: data[4] as i16,
+ adv: i16::from(data[2]),
+ bearing_x: i16::from(data[3]),
+ bearing_y: i16::from(data[4]),
data: &data[5..],
}
}
@@ -227,8 +227,8 @@ impl GlyphData {
}
fn calculate_glyph_size(header: &[u8]) -> usize {
- let width = header[0] as i16;
- let height = header[1] as i16;
+ let width = i16::from(header[0]);
+ let height = i16::from(header[1]);
let data_bytes = match constant::FONT_BPP {
1 => (width * height + 7) / 8, // packed bits
diff --git a/core/embed/rust/src/ui/display/image.rs b/core/embed/rust/src/ui/display/image.rs
index 7c8161bf..34e0ef5d 100644
--- a/core/embed/rust/src/ui/display/image.rs
+++ b/core/embed/rust/src/ui/display/image.rs
@@ -168,7 +168,7 @@ impl JpegInfo {
if (c1 != 0x11) && (c1 != 0x21) & (c1 != 0x22) {
return None;
};
- let mcu_height = (8 * (c1 & 15)) as i16;
+ let mcu_height = i16::from(8 * (c1 & 15));
// We now have all the information we need, but
// we will not exit the loop yet until we find the
diff --git a/core/embed/rust/src/ui/layout_bolt/bootloader/menu.rs b/core/embed/rust/src/ui/layout_bolt/bootloader/menu.rs
index 538608f6..5c8f3fe1 100644
--- a/core/embed/rust/src/ui/layout_bolt/bootloader/menu.rs
+++ b/core/embed/rust/src/ui/layout_bolt/bootloader/menu.rs
@@ -67,11 +67,13 @@ impl Menu {
Rect::new(
Point::new(
CONTENT_PADDING,
- BUTTON_AREA_START + i as i16 * (BUTTON_HEIGHT + BUTTON_SPACING),
+ BUTTON_AREA_START + i16::from(i) * (BUTTON_HEIGHT + BUTTON_SPACING),
),
Point::new(
WIDTH - CONTENT_PADDING,
- BUTTON_AREA_START + (i + 1) as i16 * BUTTON_HEIGHT + i as i16 * BUTTON_SPACING,
+ BUTTON_AREA_START
+ + i16::from(i + 1) * BUTTON_HEIGHT
+ + i16::from(i) * BUTTON_SPACING,
),
)
}
diff --git a/core/embed/rust/src/ui/layout_bolt/bootloader/mod.rs b/core/embed/rust/src/ui/layout_bolt/bootloader/mod.rs
index 8b69e3d5..e642e4a9 100644
--- a/core/embed/rust/src/ui/layout_bolt/bootloader/mod.rs
+++ b/core/embed/rust/src/ui/layout_bolt/bootloader/mod.rs
@@ -88,7 +88,7 @@ impl UIBolt {
let center = SCREEN.center() + Offset::y(-20);
let inactive_color = bg_color.blend(fg_color, 85);
- let end = 360.0 * progress as f32 / 1000.0;
+ let end = 360.0 * f32::from(progress) / 1000.0;
render_loader(
center,
diff --git a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs
index 2d312ea2..dfda7582 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs
@@ -122,7 +122,11 @@ impl AddressDetails {
fn total_pages(&self) -> u16 {
// Base pages (QR and details) plus sum of all xpub pages
- 2 + self.xpub_page_count.iter().map(|&x| x as u16).sum::<u16>()
+ 2 + self
+ .xpub_page_count
+ .iter()
+ .map(|&x| u16::from(x))
+ .sum::<u16>()
}
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/button.rs b/core/embed/rust/src/ui/layout_bolt/component/button.rs
index e1820cc3..71a09a07 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/button.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/button.rs
@@ -185,7 +185,7 @@ impl Button {
.with_bg(style.button_color)
.with_fg(style.border_color)
.with_thickness(style.border_width)
- .with_radius(style.border_radius as i16)
+ .with_radius(i16::from(style.border_radius))
.render(target),
}
}
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 fa5a134b..22843dec 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
@@ -120,8 +120,8 @@ where
let start = (self.value as i16 - 100) % 1000;
let end = (self.value as i16 + 100) % 1000;
- let start = 360.0 * start as f32 / 1000.0;
- let end = 360.0 * end as f32 / 1000.0;
+ let start = 360.0 * f32::from(start) / 1000.0;
+ let end = 360.0 * f32::from(end) / 1000.0;
shape::Circle::new(center, LOADER_OUTER)
.with_bg(inactive_color)
diff --git a/core/embed/rust/src/ui/layout_bolt/component/confirm_pairing.rs b/core/embed/rust/src/ui/layout_bolt/component/confirm_pairing.rs
index 41bcf7c0..c6c1617a 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/confirm_pairing.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/confirm_pairing.rs
@@ -115,7 +115,7 @@ impl Component for ConfirmPairing<'_> {
self.title.render(target);
let mut buf = [0; 20];
- let text = unwrap!(format_i64(self.code as _, &mut buf));
+ let text = unwrap!(format_i64(self.code.into(), &mut buf));
shape::Text::new(CONTENT_AREA.left_center(), text, fonts::FONT_BOLD_UPPER)
.with_fg(WHITE)
diff --git a/core/embed/rust/src/ui/layout_bolt/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/layout_bolt/component/keyboard/passphrase.rs
index b7128d48..982953bd 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/keyboard/passphrase.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/keyboard/passphrase.rs
@@ -445,7 +445,7 @@ impl Input {
Bar::new(self.shown_area)
.with_bg(theme::GREY_DARK)
- .with_radius(theme::RADIUS as i16)
+ .with_radius(theme::RADIUS.into())
.render(target);
TextLayout::new(Self::STYLE)
@@ -472,7 +472,7 @@ impl Input {
let asterisk_width = style.text_font.char_width('*').max(1);
let max_visible = (available_width / asterisk_width).max(1) as usize;
let visible_count = pp_len.min(max_visible);
- let asterisk_count = visible_count.saturating_sub(last_char_visible as usize);
+ let asterisk_count = visible_count.saturating_sub(last_char_visible.into());
// Build asterisks string
let mut asterisks = ShortString::new();
diff --git a/core/embed/rust/src/ui/layout_bolt/component/keyboard/pin.rs b/core/embed/rust/src/ui/layout_bolt/component/keyboard/pin.rs
index 5f323035..de74fc42 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/keyboard/pin.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/keyboard/pin.rs
@@ -383,7 +383,7 @@ impl PinInput {
// Number of visible icons + characters
let visible_len = pin_len.min(MAX_SHOWN_LEN);
// Number of visible icons
- let visible_icons = visible_len - last_digit as usize;
+ let visible_icons = visible_len - usize::from(last_digit);
// Jiggle when overflowed.
if pin_len > visible_len && pin_len % 2 == 1 && self.display_style != DisplayStyle::Shown {
diff --git a/core/embed/rust/src/ui/layout_bolt/component/loader.rs b/core/embed/rust/src/ui/layout_bolt/component/loader.rs
index a440a187..36cee28f 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/loader.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/loader.rs
@@ -191,8 +191,8 @@ impl Component for Loader {
use crate::ui::lerp::Lerp;
if matches!(self.state, State::Growing(_)) {
- let progress =
- self.progress(now).unwrap() as f32 / display::LOADER_MAX as f32;
+ let progress = f32::from(self.progress(now).unwrap())
+ / f32::from(display::LOADER_MAX);
let ampl = i16::lerp(0, HAPTIC_AMPLITUDE_MAX_PCT, progress);
haptic::play_custom(ampl as i8, HAPTIC_AMPLITUDE_DURATION_MS);
}
@@ -240,7 +240,7 @@ impl Component for Loader {
active_color
};
- let end = 360.0 * progress as f32 / 1000.0;
+ let end = 360.0 * f32::from(progress) / 1000.0;
let start = 0.0;
render_loader(
diff --git a/core/embed/rust/src/ui/layout_bolt/component/number_input.rs b/core/embed/rust/src/ui/layout_bolt/component/number_input.rs
index 4fc0423c..b34e80ff 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/number_input.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/number_input.rs
@@ -201,7 +201,7 @@ impl Component for NumberInput {
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
let mut buf = [0u8; 10];
- if let Some(text) = strutil::format_i64(self.value as i64, &mut buf) {
+ if let Some(text) = strutil::format_i64(i64::from(self.value), &mut buf) {
let digit_font = fonts::FONT_DEMIBOLD;
let y_offset = digit_font.text_height() / 2 + Button::BASELINE_OFFSET;
@@ -221,6 +221,6 @@ impl Component for NumberInput {
impl crate::trace::Trace for NumberInput {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("NumberInput");
- t.int("value", self.value as i64);
+ t.int("value", i64::from(self.value));
}
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/number_input_slider.rs b/core/embed/rust/src/ui/layout_bolt/component/number_input_slider.rs
index 7b40a4b0..7e9a0a00 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/number_input_slider.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/number_input_slider.rs
@@ -114,7 +114,7 @@ impl NumberInputSlider {
let filled = pos.x - self.area.x0;
let filled = filled.clamp(0, self.area.width());
let val_pct = (filled as u16 * 100) / self.area.width() as u16;
- let val = ((val_pct * (self.max - self.min) as u16) / 100) as u8 + self.min;
+ let val = ((val_pct * u16::from(self.max - self.min)) / 100) as u8 + self.min;
if val != self.value {
self.value = val;
@@ -147,7 +147,7 @@ impl Component for NumberInputSlider {
}
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
- let val_pct = (100 * (self.value - self.min) as u16) / (self.max - self.min) as u16;
+ let val_pct = (100 * u16::from(self.value - self.min)) / u16::from(self.max - self.min);
shape::Bar::new(self.area)
.with_radius(2)
@@ -173,6 +173,6 @@ impl Component for NumberInputSlider {
impl crate::trace::Trace for NumberInputSlider {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("NumberInputSlider");
- t.int("value", self.value as i64);
+ t.int("value", i64::from(self.value));
}
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/page.rs b/core/embed/rust/src/ui/layout_bolt/component/page.rs
index 013141eb..e857fde5 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/page.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/page.rs
@@ -412,8 +412,8 @@ where
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ButtonPage");
- t.int("active_page", self.scrollbar.pager().current() as i64);
- t.int("page_count", self.scrollbar.pager().total() as i64);
+ t.int("active_page", i64::from(self.scrollbar.pager().current()));
+ t.int("page_count", i64::from(self.scrollbar.pager().total()));
t.bool("hold", self.loader.is_some());
t.child("content", &self.content);
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/progress.rs b/core/embed/rust/src/ui/layout_bolt/component/progress.rs
index caa8abbe..d5c7c7d6 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/progress.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/progress.rs
@@ -105,11 +105,11 @@ impl Component for Progress {
let range = if self.indeterminate {
let start = (self.value as i16 - 100) % 1000;
let end = (self.value as i16 + 100) % 1000;
- let start = 360.0 * start as f32 / 1000.0;
- let end = 360.0 * end as f32 / 1000.0;
+ let start = 360.0 * f32::from(start) / 1000.0;
+ let end = 360.0 * f32::from(end) / 1000.0;
LoaderRange::FromTo(start, end)
} else {
- let end = 360.0 * self.value as f32 / 1000.0;
+ let end = 360.0 * f32::from(self.value) / 1000.0;
if self.value >= LOADER_MAX {
LoaderRange::Full
} else {
diff --git a/core/embed/rust/src/ui/layout_bolt/component/simple_page.rs b/core/embed/rust/src/ui/layout_bolt/component/simple_page.rs
index 396f047e..2d15871d 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/simple_page.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/simple_page.rs
@@ -160,8 +160,8 @@ where
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("SimplePage");
- t.int("active_page", self.scrollbar.pager().current() as i64);
- t.int("page_count", self.scrollbar.pager().total() as i64);
+ t.int("active_page", i64::from(self.scrollbar.pager().current()));
+ t.int("page_count", i64::from(self.scrollbar.pager().total()));
t.child("content", &self.content);
}
}
diff --git a/core/embed/rust/src/ui/layout_bolt/component/swipe.rs b/core/embed/rust/src/ui/layout_bolt/component/swipe.rs
index 9d444565..37807afc 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/swipe.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/swipe.rs
@@ -76,12 +76,12 @@ impl Swipe {
}
fn ratio(&self, dist: i16) -> f32 {
- (dist as f32 / Self::DISTANCE as f32).min(1.0)
+ (f32::from(dist) / Self::DISTANCE as f32).min(1.0)
}
fn backlight(&self, ratio: f32) {
- let start = self.backlight_start as f32;
- let end = self.backlight_end as f32;
+ let start = f32::from(self.backlight_start);
+ let end = f32::from(self.backlight_end);
let value = start + ratio * (end - start);
display::set_backlight(value as u8);
}
diff --git a/core/embed/rust/src/ui/layout_bolt/prodtest/welcome.rs b/core/embed/rust/src/ui/layout_bolt/prodtest/welcome.rs
index 785c084a..0d6a9069 100644
--- a/core/embed/rust/src/ui/layout_bolt/prodtest/welcome.rs
+++ b/core/embed/rust/src/ui/layout_bolt/prodtest/welcome.rs
@@ -84,7 +84,7 @@ impl Component for Welcome {
#[cfg(feature = "power_manager")]
{
let mut buf = [0; 20];
- let text = unwrap!(format_i64(soc() as _, &mut buf));
+ let text = unwrap!(format_i64(soc().into(), &mut buf));
shape::Text::new(screen().center(), text, fonts::FONT_BOLD_UPPER)
.with_fg(WHITE)
diff --git a/core/embed/rust/src/ui/layout_caesar/component/button.rs b/core/embed/rust/src/ui/layout_caesar/component/button.rs
index 7ac89e1c..e44ed0bd 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/button.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/button.rs
@@ -919,7 +919,7 @@ impl crate::trace::Trace for ButtonDetails {
}
}
if let Some(duration) = &self.duration {
- t.int("hold_to_confirm", duration.to_millis() as i64);
+ t.int("hold_to_confirm", i64::from(duration.to_millis()));
}
}
}
diff --git a/core/embed/rust/src/ui/layout_caesar/component/flow_pages.rs b/core/embed/rust/src/ui/layout_caesar/component/flow_pages.rs
index 60170e2e..52b3e92d 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/flow_pages.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/flow_pages.rs
@@ -192,8 +192,8 @@ impl crate::trace::Trace for Page {
// Not calling it "title" as that is already traced by FlowPage
t.string("page_title", *title);
}
- t.int("active_page", self.pager().current() as i64);
- t.int("page_count", self.pager().total() as i64);
+ t.int("active_page", i64::from(self.pager().current()));
+ t.int("page_count", i64::from(self.pager().total()));
t.in_list("text", &|l| {
let result = self.formatted.trace_lines_as_list(l);
fit.set(Some(result));
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 5f7d5cb8..582c6263 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/loader.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/loader.rs
@@ -175,7 +175,7 @@ impl Loader {
) {
let width = self.area.width();
// NOTE: need to calculate this in `i32`, it would overflow using `i16`
- let split_point = (((width as i32 + 1) * done) / (display::LOADER_MAX as i32)) as i16;
+ let split_point = (((i32::from(width) + 1) * done) / i32::from(display::LOADER_MAX)) as i16;
let (r_left, r_right) = self.area.split_left(split_point);
let parts = [(r_left, true), (r_right, false)];
parts.iter().for_each(|&(r, invert)| {
@@ -259,11 +259,11 @@ impl Component for Loader {
if let State::Initial = self.state {
self.render_loader(target, self.styles.normal, 0);
} else if let State::Grown = self.state {
- self.render_loader(target, self.styles.normal, display::LOADER_MAX as i32);
+ self.render_loader(target, self.styles.normal, i32::from(display::LOADER_MAX));
} else {
let progress = self.progress(now);
if let Some(done) = progress {
- self.render_loader(target, self.styles.normal, done as i32);
+ self.render_loader(target, self.styles.normal, i32::from(done));
} else {
self.render_loader(target, self.styles.normal, 0);
}
@@ -353,7 +353,7 @@ impl Component for ProgressLoader {
if self.is_animating() {
let now = Instant::now();
let percentage = self.percentage(now);
- let new_loader_value = (percentage * LOADER_MAX as u32) / 100;
+ let new_loader_value = (percentage * u32::from(LOADER_MAX)) / 100;
self.loader
.event(ctx, Event::Progress(new_loader_value as u16, "".into()));
// Returning only after the loader was fully painted
@@ -378,6 +378,6 @@ impl crate::trace::Trace for Loader {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("Loader");
t.string("text", self.get_text());
- t.int("duration", self.get_duration().to_millis() as i64);
+ t.int("duration", i64::from(self.get_duration().to_millis()));
}
}
diff --git a/core/embed/rust/src/ui/layout_caesar/component/page.rs b/core/embed/rust/src/ui/layout_caesar/component/page.rs
index 21f6c016..69f566ae 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/page.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/page.rs
@@ -209,8 +209,8 @@ where
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ButtonPage");
- t.int("active_page", self.pager().current() as i64);
- t.int("page_count", self.pager().total() as i64);
+ t.int("active_page", i64::from(self.pager().current()));
+ t.int("page_count", i64::from(self.pager().total()));
t.child("buttons", &self.buttons);
t.child("content", &self.content);
t.bool("has_menu", self.has_menu && self.pager().is_last());
diff --git a/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs b/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs
index 45416d7f..cc75d305 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs
@@ -236,7 +236,7 @@ impl Paginate for ScrollBar {
impl crate::trace::Trace for ScrollBar {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ScrollBar");
- t.int("scrollbar_page_count", self.pager.total() as i64);
- t.int("scrollbar_active_page", self.pager.current() as i64);
+ t.int("scrollbar_page_count", i64::from(self.pager.total()));
+ t.int("scrollbar_active_page", i64::from(self.pager.current()));
}
}
diff --git a/core/embed/rust/src/ui/layout_caesar/cshape/dotted_line.rs b/core/embed/rust/src/ui/layout_caesar/cshape/dotted_line.rs
index db7dc569..500f7f98 100644
--- a/core/embed/rust/src/ui/layout_caesar/cshape/dotted_line.rs
+++ b/core/embed/rust/src/ui/layout_caesar/cshape/dotted_line.rs
@@ -50,7 +50,7 @@ impl HorizontalLine {
impl<'s> Shape<'s> for HorizontalLine {
fn bounds(&self) -> Rect {
- let size = Offset::new(self.length, self.thickness as i16);
+ let size = Offset::new(self.length, i16::from(self.thickness));
Rect::from_top_left_and_size(self.pos, size)
}
@@ -59,12 +59,12 @@ impl<'s> Shape<'s> for HorizontalLine {
fn draw(&mut self, canvas: &mut dyn Canvas, _cache: &DrawingCache) {
if self.step <= self.thickness {
// Solid line
- let size = Offset::new(self.length, self.thickness as i16);
+ let size = Offset::new(self.length, i16::from(self.thickness));
let r = Rect::from_top_left_and_size(self.pos, size);
canvas.fill_rect(r, self.color, 255);
} else {
// Dotted line
- let thickness = self.thickness as i16;
+ let thickness = i16::from(self.thickness);
for x in (0..self.length - thickness).step_by(self.step as usize) {
let r = Rect::from_top_left_and_size(
self.pos + Offset::x(x),
diff --git a/core/embed/rust/src/ui/layout_delizia/bootloader/mod.rs b/core/embed/rust/src/ui/layout_delizia/bootloader/mod.rs
index 6e16adcb..faa26292 100644
--- a/core/embed/rust/src/ui/layout_delizia/bootloader/mod.rs
+++ b/core/embed/rust/src/ui/layout_delizia/bootloader/mod.rs
@@ -83,7 +83,7 @@ impl UIDelizia {
let center_text_offset: i16 = 10;
let center = SCREEN.center() + Offset::y(loader_offset);
let inactive_color = bg_color.blend(fg_color, 85);
- let end = 360.0 * progress as f32 / 1000.0;
+ let end = 360.0 * f32::from(progress) / 1000.0;
render_loader(
center,
@@ -157,7 +157,7 @@ impl BootloaderUI for UIDelizia {
// in practice, restart_seconds is 5 or less so this is fine
let seconds_char = b'0' + restart_seconds % 10;
unwrap!(reboot_msg.push(seconds_char as char));
- let progress = (5 - (restart_seconds as u16)).clamp(0, 5) * 200;
+ let progress = (5 - u16::from(restart_seconds)).clamp(0, 5) * 200;
Self::screen_progress(
"Restarting device",
diff --git a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs
index 1f285a20..b120d43f 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs
@@ -99,7 +99,7 @@ impl AddressDetails {
let mut xpub_index = 0;
let mut xpub_page = scrollbar_page;
for page_count in self.xpub_page_count.iter() {
- let page_count = *page_count as u16;
+ let page_count = u16::from(*page_count);
if page_count <= xpub_page {
xpub_page -= page_count;
xpub_index += 1;
@@ -114,7 +114,7 @@ impl AddressDetails {
impl Paginate for AddressDetails {
fn pager(&self) -> Pager {
let total_xpub_pages: u8 = self.xpub_page_count.iter().copied().sum();
- Pager::new(total_xpub_pages as u16 + 1).with_current(self.current_page)
+ Pager::new(u16::from(total_xpub_pages) + 1).with_current(self.current_page)
}
fn change_page(&mut self, to_page: u16) {
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 70de15b5..3129361a 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
@@ -115,8 +115,8 @@ where
let start = (self.value as i16 - 100) % 1000;
let end = (self.value as i16 + 100) % 1000;
- let start = 360.0 * start as f32 / 1000.0;
- let end = 360.0 * end as f32 / 1000.0;
+ let start = 360.0 * f32::from(start) / 1000.0;
+ let end = 360.0 * f32::from(end) / 1000.0;
shape::Circle::new(center, LOADER_OUTER)
.with_bg(inactive_color)
diff --git a/core/embed/rust/src/ui/layout_delizia/component/footer.rs b/core/embed/rust/src/ui/layout_delizia/component/footer.rs
index 7ec0bf57..9016b479 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/footer.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/footer.rs
@@ -196,7 +196,7 @@ impl<'a> Component for Footer<'a> {
}
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
- let progress = self.progress as f32 / 1000.0;
+ let progress = f32::from(self.progress) / 1000.0;
let shift = pareen::constant(0.0).seq_ease_out(
0.0,
diff --git a/core/embed/rust/src/ui/layout_delizia/component/frame.rs b/core/embed/rust/src/ui/layout_delizia/component/frame.rs
index e406b85e..eda85833 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/frame.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/frame.rs
@@ -68,7 +68,7 @@ impl HorizontalSwipe {
let p = Point::lerp(
bounds.top_right(),
bounds.top_left(),
- shift.eval(self.progress as f32 / SwipeDetect::PROGRESS_MAX as f32),
+ shift.eval(f32::from(self.progress) / f32::from(SwipeDetect::PROGRESS_MAX)),
);
shape::Bar::new(Rect::new(p, bounds.bottom_right()))
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 3476c143..5193f00c 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/homescreen.rs
@@ -265,7 +265,7 @@ impl AttachAnimation {
}
}
Event::Attach(AttachType::Resume) => {
- let start_opacity = resume.opacity as f32 / 255.0;
+ let start_opacity = f32::from(resume.opacity) / 255.0;
let duration = start_opacity * Self::DURATION_MS as f32;
self.start_opacity = start_opacity;
self.duration = Duration::from_millis(duration as u32);
diff --git a/core/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rs
index 76b3dbcf..42817c86 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rs
@@ -550,7 +550,7 @@ impl Input {
}
let visible_len = pp_len.min(max_dots);
- let visible_icons = visible_len - last_char as usize;
+ let visible_icons = visible_len - usize::from(last_char);
// Jiggle when overflowed
if pp_len > visible_len && pp_len % 2 == 1 && self.display_style != DisplayStyle::Shown {
diff --git a/core/embed/rust/src/ui/layout_delizia/component/keyboard/pin.rs b/core/embed/rust/src/ui/layout_delizia/component/keyboard/pin.rs
index d0fffbc1..ca1f0ab1 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/keyboard/pin.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/keyboard/pin.rs
@@ -625,7 +625,7 @@ impl PinDots {
// Number of visible icons + characters
let visible_len = pin_len.min(MAX_SHOWN_LEN);
// Number of visible icons
- let visible_icons = visible_len - last_digit as usize;
+ let visible_icons = visible_len - usize::from(last_digit);
// Jiggle when overflowed.
if pin_len > visible_len && pin_len % 2 == 1 && self.display_style != DisplayStyle::Shown {
diff --git a/core/embed/rust/src/ui/layout_delizia/component/loader.rs b/core/embed/rust/src/ui/layout_delizia/component/loader.rs
index 87958222..e629d3ff 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/loader.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/loader.rs
@@ -217,7 +217,7 @@ impl Component for Loader {
let active_color = style.active;
let background_color = style.background_color;
- let end = 360.0 * progress as f32 / 1000.0;
+ let end = 360.0 * f32::from(progress) / 1000.0;
let start = 0.0;
render_loader(
diff --git a/core/embed/rust/src/ui/layout_delizia/component/number_input.rs b/core/embed/rust/src/ui/layout_delizia/component/number_input.rs
index 17a42822..6ca9c404 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/number_input.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/number_input.rs
@@ -158,7 +158,7 @@ impl Component for NumberInput {
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
let mut buf = [0u8; 10];
- if let Some(text) = strutil::format_i64(self.value as i64, &mut buf) {
+ if let Some(text) = strutil::format_i64(i64::from(self.value), &mut buf) {
let digit_font = FONT_DEMIBOLD;
let y_offset = digit_font.text_height() / 2;
@@ -178,6 +178,6 @@ impl Component for NumberInput {
impl crate::trace::Trace for NumberInput {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("NumberInput");
- t.int("value", self.value as i64);
+ t.int("value", i64::from(self.value));
}
}
diff --git a/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs b/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs
index 5b4e30b6..7f0d78b9 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs
@@ -217,6 +217,6 @@ impl Component for NumberInputSlider {
impl crate::trace::Trace for NumberInputSlider {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("NumberInputSlider");
- t.int("value", self.value as i64);
+ t.int("value", i64::from(self.value));
}
}
diff --git a/core/embed/rust/src/ui/layout_delizia/component/progress.rs b/core/embed/rust/src/ui/layout_delizia/component/progress.rs
index b43ac720..e53a87c4 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/progress.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/progress.rs
@@ -97,11 +97,11 @@ impl Component for Progress {
let range = if self.indeterminate {
let start = (self.value as i16 - 100) % 1000;
let end = (self.value as i16 + 100) % 1000;
- let start = 360.0 * start as f32 / 1000.0;
- let end = 360.0 * end as f32 / 1000.0;
+ let start = 360.0 * f32::from(start) / 1000.0;
+ let end = 360.0 * f32::from(end) / 1000.0;
LoaderRange::FromTo(start, end)
} else {
- let end = 360.0 * self.value as f32 / 1000.0;
+ let end = 360.0 * f32::from(self.value) / 1000.0;
if self.value >= LOADER_MAX {
LoaderRange::Full
} else {
diff --git a/core/embed/rust/src/ui/layout_delizia/component/share_words.rs b/core/embed/rust/src/ui/layout_delizia/component/share_words.rs
index 59f40523..5cf2039a 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/share_words.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/share_words.rs
@@ -217,7 +217,7 @@ impl<'a> Component for ShareWords<'a> {
target.in_clip(self.area_word, &|target| {
let bounds = target.viewport().clip;
let full_offset = dir.as_offset(bounds.size());
- let current_offset = full_offset * (self.progress as f32 / 1000.0);
+ let current_offset = full_offset * (f32::from(self.progress) / 1000.0);
target.with_origin(current_offset, &|target| {
self.render_word(self.page_index, target, target.viewport().clip)
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 9faa83d2..c3b7b862 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
@@ -166,7 +166,7 @@ impl SwipeContext {
}
fn get_params(&self, bounds: Rect) -> (Offset, Rect, u8) {
- let progress = self.progress as f32 / 1000.0;
+ let progress = f32::from(self.progress) / 1000.0;
let shift = pareen::constant(0.0).seq_ease_out(
0.0,
diff --git a/core/embed/rust/src/ui/layout_delizia/component/vertical_menu.rs b/core/embed/rust/src/ui/layout_delizia/component/vertical_menu.rs
index 08f0d491..1849c613 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/vertical_menu.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/vertical_menu.rs
@@ -575,7 +575,7 @@ impl<F: Fn(u16) -> TString<'static>> crate::trace::Trace for PagedVerticalMenu<F
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("PagedVerticalMenu");
t.child("inner", &self.inner);
- t.int("page", self.page as _);
+ t.int("page", self.page.into());
t.int("item_count", self.item_count as _);
}
}
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/request_number.rs b/core/embed/rust/src/ui/layout_delizia/flow/request_number.rs
index a483aeca..c155e551 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/request_number.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/request_number.rs
@@ -70,7 +70,7 @@ pub fn new_request_number(
// wrap the closure for obtaining MoreInfo text and call it with NUM_DISPLAYED
let info_closure = move || {
let curr_number = NUM_DISPLAYED.load(Ordering::Relaxed);
- info_closure(curr_number as u32)
+ info_closure(u32::from(curr_number))
};
let number_input_dialog = NumberInputDialog::new(
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 b3ce05a5..88576c22 100644
--- a/core/embed/rust/src/ui/layout_eckhart/component/button.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/component/button.rs
@@ -493,7 +493,7 @@ impl Button {
shape::Bar::new(self.area)
.with_bg(style.button_color)
.with_fg(style.button_color)
- .with_radius(radius as i16)
+ .with_radius(i16::from(radius))
.with_thickness(2)
.with_alpha(alpha)
.render(target);
diff --git a/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs b/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs
index eeb67495..eb13f05a 100644
--- a/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs
@@ -255,7 +255,7 @@ impl Component for FuelGauge {
impl crate::trace::Trace for FuelGauge {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("FuelGauge");
- t.int("soc", self.soc as i64);
+ t.int("soc", i64::from(self.soc));
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/cshape/loader.rs b/core/embed/rust/src/ui/layout_eckhart/cshape/loader.rs
index 3b224737..a36fd3f6 100644
--- a/core/embed/rust/src/ui/layout_eckhart/cshape/loader.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/cshape/loader.rs
@@ -49,7 +49,7 @@ pub fn render_loader_indeterminate<'s>(
fn progress_to_ratio(progress: u16) -> f32 {
// convert to ratio from 0.0 to 1.0
- (progress as f32 / 1000.0).clamp(0.0, 1.0)
+ (f32::from(progress) / 1000.0).clamp(0.0, 1.0)
}
fn get_clips_indeterminate(progress_ratio: f32) -> (Rect, Rect) {
@@ -133,7 +133,7 @@ fn get_progress_covers(progress_ratio: f32) -> impl Iterator<Item = Rect> {
const PROGRESS_START: f32 = 0.0;
const FULL_WIDTH: i16 = 190;
let progress = ((progress_ratio - PROGRESS_START) / PROGRESS_PORTION).clamp(0.0, 1.0);
- let width = ((1.0 - progress) * FULL_WIDTH as f32) as i16;
+ let width = ((1.0 - progress) * f32::from(FULL_WIDTH)) as i16;
Rect::snap(
SCREEN.top_right(),
Offset::new(width, ScreenBorder::TOP_ARC_HEIGHT),
@@ -146,7 +146,7 @@ fn get_progress_covers(progress_ratio: f32) -> impl Iterator<Item = Rect> {
const PROGRESS_START: f32 = 0.11;
const FULL_HEIGHT: i16 = SCREEN.height() - ScreenBorder::TOP_ARC_HEIGHT;
let progress = ((progress_ratio - PROGRESS_START) / PROGRESS_PORTION).clamp(0.0, 1.0);
- let height = ((1.0 - progress) * FULL_HEIGHT as f32) as i16;
+ let height = ((1.0 - progress) * f32::from(FULL_HEIGHT)) as i16;
Rect::snap(
SCREEN.bottom_right(),
Offset::new(ICON_BORDER_BR.toif.width(), height),
@@ -160,7 +160,7 @@ fn get_progress_covers(progress_ratio: f32) -> impl Iterator<Item = Rect> {
const FULL_WIDTH: i16 =
SCREEN.width() - ICON_BORDER_BL.toif.width() - ICON_BORDER_BR.toif.width();
let progress = ((progress_ratio - PROGRESS_START) / PROGRESS_PORTION).clamp(0.0, 1.0);
- let width = ((1.0 - progress) * FULL_WIDTH as f32) as i16;
+ let width = ((1.0 - progress) * f32::from(FULL_WIDTH)) as i16;
Rect::snap(
SCREEN.bottom_left() + Offset::x(ICON_BORDER_BL.toif.width()),
Offset::new(width, ScreenBorder::WIDTH),
@@ -173,7 +173,7 @@ fn get_progress_covers(progress_ratio: f32) -> impl Iterator<Item = Rect> {
const PROGRESS_START: f32 = 0.59;
const FULL_HEIGHT: i16 = SCREEN.height() - ScreenBorder::TOP_ARC_HEIGHT;
let progress = ((progress_ratio - PROGRESS_START) / PROGRESS_PORTION).clamp(0.0, 1.0);
- let height = ((1.0 - progress) * FULL_HEIGHT as f32) as i16;
+ let height = ((1.0 - progress) * f32::from(FULL_HEIGHT)) as i16;
Rect::snap(
SCREEN.top_left() + Offset::y(ScreenBorder::TOP_ARC_HEIGHT),
Offset::new(ICON_BORDER_BL.toif.width(), height),
@@ -186,7 +186,7 @@ fn get_progress_covers(progress_ratio: f32) -> impl Iterator<Item = Rect> {
const PROGRESS_START: f32 = 0.89;
const FULL_WIDTH: i16 = 190;
let progress = ((progress_ratio - PROGRESS_START) / PROGRESS_PORTION).clamp(0.0, 1.0);
- let width = ((1.0 - progress) * FULL_WIDTH as f32) as i16;
+ let width = ((1.0 - progress) * f32::from(FULL_WIDTH)) as i16;
Rect::snap(
SCREEN.top_center(),
Offset::new(width, ScreenBorder::TOP_ARC_HEIGHT),
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/brightness_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/brightness_screen.rs
index 371111f1..a5809459 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/brightness_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/brightness_screen.rs
@@ -128,7 +128,7 @@ impl VerticalSlider {
let filled = (proportional_area.y1 - pos.y).clamp(0, proportional_area.height());
let val_pct = (filled as u16 * 100) / proportional_area.height() as u16;
- let val = ((val_pct * (self.max - self.min) as u16) / 100) as u8 + self.min;
+ let val = ((val_pct * u16::from(self.max - self.min)) / 100) as u8 + self.min;
if val != self.value {
ctx.request_paint();
@@ -176,8 +176,8 @@ impl Component for VerticalSlider {
}
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
- let val_pct =
- ((100 * (self.value - self.min) as u16) / (self.max - self.min) as u16).clamp(0, 100);
+ let val_pct = ((100 * u16::from(self.value - self.min)) / u16::from(self.max - self.min))
+ .clamp(0, 100);
// Square area for the slider
let (_, small_area) = self.area.split_bottom(Self::SLIDER_WIDTH);
@@ -208,7 +208,7 @@ impl Component for VerticalSlider {
impl crate::trace::Trace for VerticalSlider {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("VerticalSlider");
- t.int("value", self.value as i64);
+ t.int("value", i64::from(self.value));
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs
index b1f4a2bb..17686c66 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs
@@ -304,7 +304,7 @@ impl HoldToConfirmAnim {
fn get_top_gap_rollback(&self, elapsed: Duration) -> Rect {
let progress = (elapsed / self.rollback_duration()).clamp(0.0, 1.0);
- let clip_width = (progress * SCREEN.width() as f32) as i16;
+ let clip_width = (progress * f32::from(SCREEN.width())) as i16;
Rect::from_center_and_size(
SCREEN.top_center().ofs(Offset::y(ScreenBorder::WIDTH / 2)),
Offset::new(clip_width, ScreenBorder::WIDTH),
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 d61001a9..0b2651b6 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
@@ -117,7 +117,7 @@ impl PassphraseInput {
// Number of visible icons + characters
let visible_len = pp_len.min(Self::MAX_SHOWN_LEN);
// Number of visible icons
- let visible_icons = visible_len - last_char as usize;
+ let visible_icons = visible_len - usize::from(last_char);
// Jiggle when overflowed.
if pp_len > visible_len
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 4e25d984..fa6a90a0 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
@@ -407,7 +407,7 @@ impl PinInput {
// Number of visible icons + characters
let visible_len = pin_len.min(Self::MAX_SHOWN_LEN);
// Number of visible icons
- let visible_icons = visible_len - last_digit as usize;
+ let visible_icons = visible_len - usize::from(last_digit);
// Jiggle when overflowed.
if pin_len > visible_len
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/slip39.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/slip39.rs
index 16e3a3d8..1da02165 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/slip39.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/slip39.rs
@@ -159,7 +159,7 @@ impl Component for Slip39Input {
// Initial position for drawing the icons
let mut cursor = area.center().ofs(Offset::x(-self.width() / 2));
- let visible_icons = input_len.saturating_sub(last.is_some() as usize);
+ let visible_icons = input_len.saturating_sub(usize::from(last.is_some()));
for _ in 0..visible_icons {
ToifImage::new(cursor, Self::ICON.toif)
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/regulatory_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/regulatory_screen.rs
index d5467163..8ea2d1b2 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/regulatory_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/regulatory_screen.rs
@@ -144,7 +144,7 @@ impl crate::trace::Trace for RegulatoryScreen {
t.child("Header", &self.header);
t.child("Content", &self.content);
t.child("ActionBar", &self.action_bar);
- t.int("page_count", self.content.pager().total() as i64);
+ t.int("page_count", i64::from(self.content.pager().total()));
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs
index ca9559ea..02c4dc41 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs
@@ -400,9 +400,9 @@ where
t.child("ActionBar", ab);
}
if let Some(page_limit) = self.page_limit {
- t.int("page_limit", page_limit as i64);
+ t.int("page_limit", i64::from(page_limit));
}
- t.int("page_count", self.content.pager().total() as i64);
+ t.int("page_count", i64::from(self.content.pager().total()));
debug_assert!(!(self.external_menu && self.has_flow_menu));
t.bool("has_menu", self.external_menu);
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/tutorial_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/tutorial_screen.rs
index 16544d47..e3bf9885 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/tutorial_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/tutorial_screen.rs
@@ -135,7 +135,7 @@ impl Component for TutorialWelcomeScreen {
if loader_running {
let progress = self.stopwatch.elapsed() / LOADER_DURATION;
- let loader_val = (progress * LOADER_MAX_VAL as f32) as u16;
+ let loader_val = (progress * f32::from(LOADER_MAX_VAL)) as u16;
render_loader_indeterminate(loader_val, &self.border, target);
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/value_input_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/value_input_screen.rs
index f4897dfc..fdf9c870 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/value_input_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/value_input_screen.rs
@@ -288,7 +288,7 @@ impl<T: ValueInput> ValueInputDialog<T> {
let (num, label) = self.value_input.repr();
- if let Some(num_str) = strutil::format_i64(num as i64, &mut buf) {
+ if let Some(num_str) = strutil::format_i64(i64::from(num), &mut buf) {
let num_font = fonts::FONT_SATOSHI_EXTRALIGHT_72;
let label_font = fonts::FONT_SATOSHI_REGULAR_22;
@@ -408,7 +408,7 @@ impl<T: ValueInput> Component for ValueInputDialog<T> {
impl<T: ValueInput> crate::trace::Trace for ValueInputDialog<T> {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ValueInput");
- t.int("value", self.value_input.num() as i64);
+ t.int("value", i64::from(self.value_input.num()));
}
}
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
index 4a6a9a32..6a318c7c 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
@@ -165,8 +165,9 @@ impl<T: MenuItems> VerticalMenuScreen<T> {
if let Some(displacement) = self.inertia.advance(ctx) {
let current = self.menu.get_offset();
// Perform addition in a wider type and clamp to the valid offset range
- let new_offset_i32 = current as i32 + displacement as i32;
- let new_offset = new_offset_i32.clamp(i16::MIN as i32, i16::MAX as i32) as i16;
+ let new_offset_i32 = i32::from(current) + i32::from(displacement);
+ let new_offset =
+ new_offset_i32.clamp(i32::from(i16::MIN), i32::from(i16::MAX)) as i16;
self.menu.set_offset(new_offset);
// If we hit a boundary, stop coasting
@@ -378,7 +379,7 @@ impl InertiaState {
if let Some(prev_time) = self.last_move_time {
let dt_ms = now.saturating_duration_since(prev_time).to_millis() as f32;
if dt_ms > 0.0 {
- let delta = (offset - self.last_offset) as f32;
+ let delta = f32::from(offset - self.last_offset);
let instant_velocity = delta / dt_ms;
// Exponential moving average
self.velocity = self.velocity * (1.0 - Self::VELOCITY_SMOOTHING)
@@ -429,10 +430,10 @@ impl InertiaState {
// Apply velocity to get fractional displacement
let displacement = self.velocity * dt_ms + self.remainder;
// Clamp to i16 range before truncation to avoid saturating cast surprises
- let displacement = displacement.clamp(i16::MIN as f32, i16::MAX as f32);
+ let displacement = displacement.clamp(f32::from(i16::MIN), f32::from(i16::MAX));
// Split into integer part (to apply) and fractional remainder (to accumulate)
let int_displacement = displacement as i16;
- self.remainder = displacement - int_displacement as f32;
+ self.remainder = displacement - f32::from(int_displacement);
// Apply friction: v *= friction^dt
// First-order Taylor: a^dt ≈ 1 + dt*ln(a)
diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/request_number.rs b/core/embed/rust/src/ui/layout_eckhart/flow/request_number.rs
index 2d27df2e..2e9d5aed 100644
--- a/core/embed/rust/src/ui/layout_eckhart/flow/request_number.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/flow/request_number.rs
@@ -69,7 +69,7 @@ pub fn new_request_number(
// wrap the closure for obtaining MoreInfo text and call it with NUM_DISPLAYED
let info_closure = move || {
let curr_number = NUM_DISPLAYED.load(Ordering::Relaxed);
- info_closure(curr_number as u32)
+ info_closure(u32::from(curr_number))
};
let content_input =
diff --git a/core/embed/rust/src/ui/layout_eckhart/prodtest/welcome.rs b/core/embed/rust/src/ui/layout_eckhart/prodtest/welcome.rs
index 9aa05972..23fe6737 100644
--- a/core/embed/rust/src/ui/layout_eckhart/prodtest/welcome.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/prodtest/welcome.rs
@@ -218,7 +218,7 @@ impl Component for Welcome {
self.screen_border.render(u8::MAX, target);
let mut buf = [0; 20];
- let text = unwrap!(format_i64(soc() as _, &mut buf));
+ let text = unwrap!(format_i64(soc().into(), &mut buf));
shape::Text::new(
screen().center(),
diff --git a/core/embed/rust/src/ui/layout_eckhart/theme/gradient.rs b/core/embed/rust/src/ui/layout_eckhart/theme/gradient.rs
index d38ee6b1..8314814e 100644
--- a/core/embed/rust/src/ui/layout_eckhart/theme/gradient.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/theme/gradient.rs
@@ -187,8 +187,8 @@ fn render_led_simulation<'a>(
// Calculate distance from center as a normalized factor (0 at center, 1 at
// edges)
let x_mid = area.center().x;
- let x_half_width = (area.width() / 2) as f32;
- let dist_from_mid = (slice.x0 - x_mid).abs() as f32 / x_half_width;
+ let x_half_width = f32::from(area.width() / 2);
+ let dist_from_mid = f32::from((slice.x0 - x_mid).abs()) / x_half_width;
shape::Bar::new(slice)
.with_bg(theme::BG)
@@ -206,9 +206,9 @@ fn render_edge_fade<'s>(
// Render horizontal distance-from-mid gradient
// Black at edges, color_mid at center with minimal opacity
let x_mid = area.center().x;
- let half_width = (area.width() / 2) as f32;
+ let half_width = f32::from(area.width() / 2);
for (slice, _) in iter_slices(area, Axis::Horizontal, step_size) {
- let dist_from_mid = (slice.x0 - x_mid).abs() as f32 / half_width;
+ let dist_from_mid = f32::from((slice.x0 - x_mid).abs()) / half_width;
let alpha = u8::lerp(u8::MIN, u8::MAX, dist_from_mid);
let color = Color::lerp(color_mid, theme::BLACK, dist_from_mid);
shape::Bar::new(slice)
@@ -227,9 +227,9 @@ fn render_alert_horizontal<'s>(
// Render horizontal distance-from-mid gradient
// Black at edges, color_mid at center with full opacity
let x_mid = area.center().x;
- let half_width = (area.width() / 2) as f32;
+ let half_width = f32::from(area.width() / 2);
for (slice, _) in iter_slices(area, Axis::Horizontal, step_size) {
- let dist_from_mid = (slice.x0 - x_mid).abs() as f32 / half_width;
+ let dist_from_mid = f32::from((slice.x0 - x_mid).abs()) / half_width;
let color = Color::lerp(color_mid, theme::BLACK, dist_from_mid);
shape::Bar::new(slice)
.with_bg(color)
@@ -277,7 +277,7 @@ fn iter_slices(area: Rect, axis: Axis, step_size: u16) -> impl Iterator<Item = (
// Calculate factor based on the center of the slice for better visual accuracy
let slice_center = pos + slice_size / 2;
- let factor = (slice_center - start) as f32 / total_length as f32;
+ let factor = f32::from(slice_center - start) / f32::from(total_length);
(slice, factor)
})
}
diff --git a/core/embed/rust/src/ui/lerp.rs b/core/embed/rust/src/ui/lerp.rs
index ea79b958..0fcece22 100644
--- a/core/embed/rust/src/ui/lerp.rs
+++ b/core/embed/rust/src/ui/lerp.rs
@@ -29,13 +29,13 @@ macro_rules! impl_lerp_for_signed {
($int: ident) => {
impl Lerp for $int {
fn lerp(a: Self, b: Self, t: f32) -> Self {
- (a as f32 + t * (b - a) as f32) as Self
+ (f32::from(a) + t * f32::from(b - a)) as Self
}
}
impl InvLerp for $int {
fn inv_lerp(min: Self, max: Self, value: Self) -> f32 {
- (value - min) as f32 / (max - min) as f32
+ f32::from(value - min) / f32::from(max - min)
}
}
};
@@ -46,9 +46,9 @@ macro_rules! impl_lerp_for_unsigned {
impl Lerp for $uint {
fn lerp(a: Self, b: Self, t: f32) -> Self {
if a <= b {
- (a as f32 + t * (b - a) as f32) as Self
+ (f32::from(a) + t * f32::from(b - a)) as Self
} else {
- (a as f32 - t * (a - b) as f32) as Self
+ (f32::from(a) - t * f32::from(a - b)) as Self
}
}
}
@@ -56,9 +56,9 @@ macro_rules! impl_lerp_for_unsigned {
impl InvLerp for $uint {
fn inv_lerp(min: Self, max: Self, value: Self) -> f32 {
if min <= max {
- (value - min) as f32 / (max - min) as f32
+ f32::from(value - min) / f32::from(max - min)
} else {
- (value - max) as f32 / (min - max) as f32
+ f32::from(value - max) / f32::from(min - max)
}
}
}
diff --git a/core/embed/rust/src/ui/shape/canvas/common.rs b/core/embed/rust/src/ui/shape/canvas/common.rs
index 70db7a08..3ba94202 100644
--- a/core/embed/rust/src/ui/shape/canvas/common.rs
+++ b/core/embed/rust/src/ui/shape/canvas/common.rs
@@ -289,7 +289,7 @@ pub trait Canvas: BasicCanvas {
..r
};
- let alpha_mul = |a: u8| -> u8 { ((a as u16 * alpha as u16) / 255) as u8 };
+ let alpha_mul = |a: u8| -> u8 { ((u16::from(a) * u16::from(alpha)) / 255) as u8 };
if self.viewport().contains(b) {
for p in circle_points(radius) {
@@ -514,7 +514,7 @@ pub trait Canvas: BasicCanvas {
let split = unwrap!(circle_points(radius).last()).v;
- let alpha_mul = |a: u8| -> u8 { ((a as u16 * alpha as u16) / 255) as u8 };
+ let alpha_mul = |a: u8| -> u8 { ((u16::from(a) * u16::from(alpha)) / 255) as u8 };
let r = Rect::new(
Point::new(center.x - radius, center.y - radius),
@@ -610,7 +610,7 @@ pub trait Canvas: BasicCanvas {
end = (360.0 + end % 360.0) % 360.0;
let alpha = 255;
- let alpha_mul = |a: u8| -> u8 { ((a as u16 * alpha as u16) / 255) as u8 };
+ let alpha_mul = |a: u8| -> u8 { ((u16::from(a) * u16::from(alpha)) / 255) as u8 };
if start != end {
// The algorithm fills everything except the middle point ;-)
@@ -620,11 +620,11 @@ pub trait Canvas: BasicCanvas {
const PI4: f32 = 45.0;
for octant in 0..8 {
- let angle = PI4 * octant as f32;
+ let angle = PI4 * f32::from(octant);
// Function for calculation of 'u' coordinate inside the circle octant
// radius * sin(angle)
- let sin = |angle: f32| -> i16 { (sin_f32(angle) * radius as f32 + 0.5) as i16 };
+ let sin = |angle: f32| -> i16 { (sin_f32(angle) * f32::from(radius) + 0.5) as i16 };
// Calculate the octant's bounding rectangle
let p = Point::new(sin(PI4) + 1, -radius - 1).rot(octant);
diff --git a/core/embed/rust/src/ui/shape/canvas/mono8.rs b/core/embed/rust/src/ui/shape/canvas/mono8.rs
index 51a5c6e1..2d9894c0 100644
--- a/core/embed/rust/src/ui/shape/canvas/mono8.rs
+++ b/core/embed/rust/src/ui/shape/canvas/mono8.rs
@@ -107,8 +107,9 @@ impl<'a> Canvas for Mono8Canvas<'a> {
if let Some(row) = self.row_mut(pt.y) {
let pixel = &mut row[pt.x as usize];
let fg_color = color.luminance() as u16;
- let bg_color = *pixel as u16;
- *pixel = ((fg_color * alpha as u16 + bg_color * (255 - alpha) as u16) / 255) as u8;
+ let bg_color = u16::from(*pixel);
+ *pixel =
+ ((fg_color * u16::from(alpha) + bg_color * u16::from(255 - alpha)) / 255) as u8;
}
}
}
diff --git a/core/embed/rust/src/ui/shape/canvas/rgba8888.rs b/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
index 031645e0..d8740249 100644
--- a/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
+++ b/core/embed/rust/src/ui/shape/canvas/rgba8888.rs
@@ -111,16 +111,16 @@ impl<'a> Canvas for Rgba8888Canvas<'a> {
let bg_g = ((bg & 0x0000FF00) >> 8) as u16;
let bg_b = (bg & 0x000000FF) as u16;
- let fg_r = color.r() as u16;
- let fg_g = color.g() as u16;
- let fg_b = color.b() as u16;
+ let fg_r = u16::from(color.r());
+ let fg_g = u16::from(color.g());
+ let fg_b = u16::from(color.b());
- let fg_mul = alpha as u16;
- let bg_mul = (255 - alpha) as u16;
+ let fg_mul = u16::from(alpha);
+ let bg_mul = u16::from(255 - alpha);
- let r = ((fg_r * fg_mul + bg_r * bg_mul) / 255) as u32;
- let g = ((fg_g * fg_mul + bg_g * bg_mul) / 255) as u32;
- let b = ((fg_b * fg_mul + bg_b * bg_mul) / 255) as u32;
+ let r = u32::from((fg_r * fg_mul + bg_r * bg_mul) / 255);
+ let g = u32::from((fg_g * fg_mul + bg_g * bg_mul) / 255);
+ let b = u32::from((fg_b * fg_mul + bg_b * bg_mul) / 255);
row[pt.x as usize] = (0xFF << 24) | (r << 16) | (g << 8) | b;
}
diff --git a/core/embed/rust/src/ui/shape/qrcode.rs b/core/embed/rust/src/ui/shape/qrcode.rs
index 1a0249e2..9fe7dd61 100644
--- a/core/embed/rust/src/ui/shape/qrcode.rs
+++ b/core/embed/rust/src/ui/shape/qrcode.rs
@@ -44,7 +44,7 @@ impl QrImage {
// Copy content of QR code to the qrmodules buffer
for y in 0..result.qr_size {
for x in 0..result.qr_size {
- result.set_module(x, y, qrcode.get_module(x as i32, y as i32));
+ result.set_module(x, y, qrcode.get_module(i32::from(x), i32::from(y)));
}
}
diff --git a/core/embed/rust/src/ui/shape/utils/blur.rs b/core/embed/rust/src/ui/shape/utils/blur.rs
index 5c7d246b..0645f53d 100644
--- a/core/embed/rust/src/ui/shape/utils/blur.rs
+++ b/core/embed/rust/src/ui/shape/utils/blur.rs
@@ -57,9 +57,9 @@ impl Rgb<u16> {
#[inline(always)]
fn mulshift(&self, multiplier: u32, shift: u8) -> Rgb<u8> {
Rgb::<u8> {
- r: ((self.r as u32 * multiplier) >> shift) as u8,
- g: ((self.g as u32 * multiplier) >> shift) as u8,
- b: ((self.b as u32 * multiplier) >> shift) as u8,
+ r: ((u32::from(self.r) * multiplier) >> shift) as u8,
+ g: ((u32::from(self.g) * multiplier) >> shift) as u8,
+ b: ((u32::from(self.b) * multiplier) >> shift) as u8,
}
}
}
@@ -139,9 +139,9 @@ impl core::ops::SubAssign for Rgb<u16> {
impl From<Rgb<u8>> for u16 {
#[inline(always)]
fn from(value: Rgb<u8>) -> u16 {
- let r = (value.r as u16 & 0xF8) << 8;
- let g = (value.g as u16 & 0xFC) << 3;
- let b = (value.b as u16 & 0xF8) >> 3;
+ let r = (u16::from(value.r) & 0xF8) << 8;
+ let g = (u16::from(value.g) & 0xFC) << 3;
+ let b = (u16::from(value.b) & 0xF8) >> 3;
r | g | b
}
}
@@ -149,9 +149,9 @@ impl From<Rgb<u8>> for u16 {
impl From<Rgb<u8>> for u32 {
#[inline(always)]
fn from(value: Rgb<u8>) -> u32 {
- let r = (value.r as u32) << 16;
- let g = (value.g as u32) << 8;
- let b = value.b as u32;
+ let r = u32::from(value.r) << 16;
+ let g = u32::from(value.g) << 8;
+ let b = u32::from(value.b);
let alpha = 0xFF000000;
alpha | r | g | b
}
@@ -171,18 +171,18 @@ impl From<Rgb<u16>> for Rgb<u8> {
impl core::ops::AddAssign<Rgb<u8>> for Rgb<u16> {
#[inline(always)]
fn add_assign(&mut self, rhs: Rgb<u8>) {
- self.r += rhs.r as u16;
- self.g += rhs.g as u16;
- self.b += rhs.b as u16;
+ self.r += u16::from(rhs.r);
+ self.g += u16::from(rhs.g);
+ self.b += u16::from(rhs.b);
}
}
impl core::ops::SubAssign<Rgb<u8>> for Rgb<u16> {
#[inline(always)]
fn sub_assign(&mut self, rhs: Rgb<u8>) {
- self.r -= rhs.r as u16;
- self.g -= rhs.g as u16;
- self.b -= rhs.b as u16;
+ self.r -= u16::from(rhs.r);
+ self.g -= u16::from(rhs.g);
+ self.b -= u16::from(rhs.b);
}
}
@@ -256,7 +256,7 @@ impl<'a> BlurAlgorithm<'a> {
let divisor = (radius * 2 + 1) as u16;
let shift = 10;
- let multiplier = (1 << shift) as u32 / divisor as u32;
+ let multiplier = (1 << shift) as u32 / u32::from(divisor);
// Prepare before averaging
for i in 0..radius {
@@ -379,7 +379,7 @@ impl<'a> BlurAlgorithm<'a> {
let divisor = match dim {
Some(dim) => {
if dim > 0 {
- (self.box_side() as u16 * 255) / dim as u16
+ (self.box_side() as u16 * 255) / u16::from(dim)
} else {
65535u16
}
@@ -388,7 +388,7 @@ impl<'a> BlurAlgorithm<'a> {
};
let shift = 10;
- let multiplier = (1 << shift) as u32 / divisor as u32;
+ let multiplier = (1 << shift) as u32 / u32::from(divisor);
for (i, item) in output.iter_mut().enumerate() {
*item = self.totals[i].mulshift(multiplier, shift).into();
diff --git a/core/embed/rust/src/ui/shape/utils/circle.rs b/core/embed/rust/src/ui/shape/utils/circle.rs
index f385f151..10240e3f 100644
--- a/core/embed/rust/src/ui/shape/utils/circle.rs
+++ b/core/embed/rust/src/ui/shape/utils/circle.rs
@@ -51,7 +51,7 @@ impl Iterator for CirclePoints {
let mut item = CirclePointsItem {
u: self.u,
v: self.v,
- frac: 255 - ((self.t1 as i32 * 255) / self.radius as i32) as u8,
+ frac: 255 - ((i32::from(self.t1) * 255) / i32::from(self.radius)) as u8,
first: self.first,
last: false,
};
diff --git a/core/embed/rust/src/ui/shape/utils/line.rs b/core/embed/rust/src/ui/shape/utils/line.rs
index 15378693..9fba5b68 100644
--- a/core/embed/rust/src/ui/shape/utils/line.rs
+++ b/core/embed/rust/src/ui/shape/utils/line.rs
@@ -62,7 +62,7 @@ impl Iterator for LinePoints {
fn next(&mut self) -> Option<Self::Item> {
if self.u < self.du {
let frac = if self.dv < self.du {
- 255 - ((self.d + 2 * self.dv - 1) as i32 * 255 / (2 * self.du - 1) as i32) as u8
+ 255 - (i32::from(self.d + 2 * self.dv - 1) * 255 / i32::from(2 * self.du - 1)) as u8
} else {
0
};
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.