Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/embed/rust/src/crypto/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(not(test), no_std)]
#![deny(clippy::all)]
#![deny(clippy::cast_lossless)]
#![allow(clippy::new_without_default)]
#![allow(clippy::ptr_offset_with_cast)] // workaround https://github.com/rust-lang/rust-bindgen/issues/3053
#![deny(unsafe_op_in_unsafe_fn)]
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/micropython/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/micropython/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/protobuf/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
10 changes: 5 additions & 5 deletions core/embed/rust/src/smp/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/smp/crc16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/smp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/strutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/trezorhal/ble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/src/trezorhal/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#![allow(unnecessary_transmutes)]
#![allow(clippy::transmute_int_to_bool)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::cast_lossless)]

include!(concat!(env!("OUT_DIR"), "/trezorhal.rs"));
2 changes: 1 addition & 1 deletion core/embed/rust/src/trezorhal/uzlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/qr_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/swipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/component/swipe_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
18 changes: 9 additions & 9 deletions core/embed/rust/src/ui/display/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
14 changes: 7 additions & 7 deletions core/embed/rust/src/ui/display/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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..],
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/display/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/embed/rust/src/ui/layout_bolt/bootloader/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)
}
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/layout_bolt/bootloader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/layout_bolt/component/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions core/embed/rust/src/ui/layout_bolt/component/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
}
Loading