mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-22 16:08:59 +00:00
chore(core/rust): use clippy for all features
This commit is contained in:
parent
11cb171e1a
commit
feb96c84b0
@ -121,7 +121,7 @@ pyright:
|
|||||||
python ../tools/pyright_tool.py
|
python ../tools/pyright_tool.py
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
cd embed/rust ; cargo clippy
|
cd embed/rust ; cargo clippy --all-features
|
||||||
|
|
||||||
## code generation:
|
## code generation:
|
||||||
|
|
||||||
|
@ -8,11 +8,14 @@ build = "build.rs"
|
|||||||
[features]
|
[features]
|
||||||
default = ["model_tt"]
|
default = ["model_tt"]
|
||||||
bitcoin_only = []
|
bitcoin_only = []
|
||||||
model_tt = []
|
model_tt = ["touch"]
|
||||||
model_t1 = []
|
model_t1 = ["buttons"]
|
||||||
model_tr = []
|
model_tr = ["buttons"]
|
||||||
ui = []
|
ui = []
|
||||||
ui_debug = []
|
ui_debug = []
|
||||||
|
buttons = []
|
||||||
|
touch = []
|
||||||
|
clippy = []
|
||||||
test = ["cc", "glob"]
|
test = ["cc", "glob"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -19,7 +19,7 @@ pub mod ui;
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[cfg(not(feature = "test"))]
|
#[cfg(any(not(feature = "test"), feature = "clippy"))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
use cstr_core::CStr;
|
use cstr_core::CStr;
|
||||||
|
@ -7,9 +7,9 @@ use crate::{
|
|||||||
ui::{component::Map, geometry::Rect},
|
ui::{component::Map, geometry::Rect},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "model_t1", feature = "model_tr"))]
|
#[cfg(feature = "buttons")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(feature = "touch")]
|
||||||
use crate::ui::event::TouchEvent;
|
use crate::ui::event::TouchEvent;
|
||||||
|
|
||||||
/// Type used by components that do not return any messages.
|
/// Type used by components that do not return any messages.
|
||||||
@ -219,9 +219,9 @@ where
|
|||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
#[cfg(any(feature = "model_t1", feature = "model_tr"))]
|
#[cfg(feature = "buttons")]
|
||||||
Button(ButtonEvent),
|
Button(ButtonEvent),
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(feature = "touch")]
|
||||||
Touch(TouchEvent),
|
Touch(TouchEvent),
|
||||||
/// Previously requested timer was triggered. This invalidates the timer
|
/// Previously requested timer was triggered. This invalidates the timer
|
||||||
/// token (another timer has to be requested).
|
/// token (another timer has to be requested).
|
||||||
|
13
core/embed/rust/src/ui/constant.rs
Normal file
13
core/embed/rust/src/ui/constant.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//! Reexporting the `constant` module according to the
|
||||||
|
//! current feature (Trezor model)
|
||||||
|
|
||||||
|
#[cfg(feature = "model_t1")]
|
||||||
|
pub use super::model_t1::constant::*;
|
||||||
|
#[cfg(all(feature = "model_tr", not(feature = "model_t1")))]
|
||||||
|
pub use super::model_tr::constant::*;
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "model_tt",
|
||||||
|
not(feature = "model_tr"),
|
||||||
|
not(feature = "model_t1")
|
||||||
|
))]
|
||||||
|
pub use super::model_tt::constant::*;
|
@ -1,12 +1,6 @@
|
|||||||
|
use super::constant;
|
||||||
use crate::{micropython::time, time::Duration, trezorhal::display};
|
use crate::{micropython::time, time::Duration, trezorhal::display};
|
||||||
|
|
||||||
#[cfg(feature = "model_t1")]
|
|
||||||
use crate::ui::model_t1::constant;
|
|
||||||
#[cfg(feature = "model_tr")]
|
|
||||||
use crate::ui::model_tr::constant;
|
|
||||||
#[cfg(feature = "model_tt")]
|
|
||||||
use crate::ui::model_tt::constant;
|
|
||||||
|
|
||||||
use super::geometry::{Offset, Point, Rect};
|
use super::geometry::{Offset, Point, Rect};
|
||||||
|
|
||||||
pub fn backlight() -> i32 {
|
pub fn backlight() -> i32 {
|
||||||
@ -233,7 +227,7 @@ impl Color {
|
|||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn neg(self) -> Self {
|
pub fn negate(self) -> Self {
|
||||||
Self(!self.0)
|
Self(!self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,23 +15,17 @@ use crate::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
ui::{
|
ui::{
|
||||||
component::{Child, Component, Event, EventCtx, Never, TimerToken},
|
component::{Child, Component, Event, EventCtx, Never, TimerToken},
|
||||||
|
constant,
|
||||||
geometry::Rect,
|
geometry::Rect,
|
||||||
},
|
},
|
||||||
util,
|
util,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "model_t1", feature = "model_tr"))]
|
#[cfg(feature = "buttons")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(feature = "touch")]
|
||||||
use crate::ui::event::TouchEvent;
|
use crate::ui::event::TouchEvent;
|
||||||
|
|
||||||
#[cfg(feature = "model_t1")]
|
|
||||||
use crate::ui::model_t1::constant;
|
|
||||||
#[cfg(feature = "model_tr")]
|
|
||||||
use crate::ui::model_tr::constant;
|
|
||||||
#[cfg(feature = "model_tt")]
|
|
||||||
use crate::ui::model_tt::constant;
|
|
||||||
|
|
||||||
/// Conversion trait implemented by components that know how to convert their
|
/// Conversion trait implemented by components that know how to convert their
|
||||||
/// message values into MicroPython `Obj`s. We can automatically implement
|
/// message values into MicroPython `Obj`s. We can automatically implement
|
||||||
/// `ComponentMsgObj` for components whose message types implement `TryInto`.
|
/// `ComponentMsgObj` for components whose message types implement `TryInto`.
|
||||||
@ -354,7 +348,7 @@ extern "C" fn ui_layout_set_timer_fn(this: Obj, timer_fn: Obj) -> Obj {
|
|||||||
unsafe { util::try_or_raise(block) }
|
unsafe { util::try_or_raise(block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(feature = "touch")]
|
||||||
extern "C" fn ui_layout_touch_event(n_args: usize, args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_touch_event(n_args: usize, args: *const Obj) -> Obj {
|
||||||
let block = |args: &[Obj], _kwargs: &Map| {
|
let block = |args: &[Obj], _kwargs: &Map| {
|
||||||
if args.len() != 4 {
|
if args.len() != 4 {
|
||||||
@ -372,12 +366,12 @@ extern "C" fn ui_layout_touch_event(n_args: usize, args: *const Obj) -> Obj {
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "model_t1", feature = "model_tr"))]
|
#[cfg(not(feature = "touch"))]
|
||||||
extern "C" fn ui_layout_touch_event(_n_args: usize, _args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_touch_event(_n_args: usize, _args: *const Obj) -> Obj {
|
||||||
Obj::const_none()
|
Obj::const_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "model_t1", feature = "model_tr"))]
|
#[cfg(feature = "buttons")]
|
||||||
extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
||||||
let block = |args: &[Obj], _kwargs: &Map| {
|
let block = |args: &[Obj], _kwargs: &Map| {
|
||||||
if args.len() != 3 {
|
if args.len() != 3 {
|
||||||
@ -391,7 +385,7 @@ extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(not(feature = "buttons"))]
|
||||||
extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj {
|
||||||
Obj::const_none()
|
Obj::const_none()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ pub mod macros;
|
|||||||
|
|
||||||
pub mod animation;
|
pub mod animation;
|
||||||
pub mod component;
|
pub mod component;
|
||||||
|
pub mod constant;
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
|
@ -92,7 +92,7 @@ impl<T: AsRef<str>> Button<T> {
|
|||||||
|
|
||||||
let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2);
|
let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2);
|
||||||
|
|
||||||
return (area, start_of_baseline);
|
(area, start_of_baseline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ where
|
|||||||
|
|
||||||
match &self.content {
|
match &self.content {
|
||||||
ButtonContent::Text(text) => {
|
ButtonContent::Text(text) => {
|
||||||
let background_color = style.text_color.neg();
|
let background_color = style.text_color.negate();
|
||||||
if style.border_horiz {
|
if style.border_horiz {
|
||||||
display::rect_fill_rounded1(self.area, background_color, theme::BG);
|
display::rect_fill_rounded1(self.area, background_color, theme::BG);
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,7 +92,7 @@ impl<T: AsRef<str>> Button<T> {
|
|||||||
|
|
||||||
let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2);
|
let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2);
|
||||||
|
|
||||||
return (area, start_of_baseline);
|
(area, start_of_baseline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ where
|
|||||||
|
|
||||||
match &self.content {
|
match &self.content {
|
||||||
ButtonContent::Text(text) => {
|
ButtonContent::Text(text) => {
|
||||||
let background_color = style.text_color.neg();
|
let background_color = style.text_color.negate();
|
||||||
if style.border_horiz {
|
if style.border_horiz {
|
||||||
display::rect_fill_rounded1(self.area, background_color, theme::BG);
|
display::rect_fill_rounded1(self.area, background_color, theme::BG);
|
||||||
} else {
|
} else {
|
||||||
|
@ -255,8 +255,8 @@ where
|
|||||||
|
|
||||||
fn paint(&mut self) {
|
fn paint(&mut self) {
|
||||||
let style = self.style();
|
let style = self.style();
|
||||||
self.paint_background(&style);
|
self.paint_background(style);
|
||||||
self.paint_content(&style);
|
self.paint_content(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
|
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
|
||||||
|
@ -25,7 +25,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn inner(&self) -> &T {
|
pub fn inner(&self) -> &T {
|
||||||
&self.content.inner()
|
self.content.inner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ impl Component for Bip39Input {
|
|||||||
let style = self.button.style();
|
let style = self.button.style();
|
||||||
|
|
||||||
// First, paint the button background.
|
// First, paint the button background.
|
||||||
self.button.paint_background(&style);
|
self.button.paint_background(style);
|
||||||
|
|
||||||
// Paint the entered content (the prefix of the suggested word).
|
// Paint the entered content (the prefix of the suggested word).
|
||||||
let text = self.textbox.content();
|
let text = self.textbox.content();
|
||||||
|
@ -115,7 +115,7 @@ impl Component for Slip39Input {
|
|||||||
let style = self.button.style();
|
let style = self.button.style();
|
||||||
|
|
||||||
// First, paint the button background.
|
// First, paint the button background.
|
||||||
self.button.paint_background(&style);
|
self.button.paint_background(style);
|
||||||
|
|
||||||
// Content starts in the left-center point, offset by 16px to the right and 8px
|
// Content starts in the left-center point, offset by 16px to the right and 8px
|
||||||
// to the bottom.
|
// to the bottom.
|
||||||
|
Loading…
Reference in New Issue
Block a user