refactor(core/rust): tweak MenuIntent's micropython dependency
What changed, and why it matters
This is a small internal code cleanup in the Trezor firmware's Rust UI layer. It moves some MicroPython-specific code into its own submodule and removes an unused import. There is no visible change to user-facing behavior or security-sensitive logic.
No security action required. Treat as ordinary code-quality refactor.
Security signals we found
No security-relevant behavioral change
Refactor only: code moved into feature-gated submodule
Error type switched to module-appropriate MicroPython error type
Unused import removed
Evidence from the diff
The commit refactors MenuItemIntent so that its MicroPython bindings live under a micropython submodule, gated by #[cfg(feature = "micropython")]. It also changes the TryFrom error type from the project’s crate::error::Error to crate::micropython::Error inside the MicroPython-specific code, and removes an unused MenuItemIntent import in ui_firmware.rs. The diff shows only structural/dependency changes with no functional modification to intent handling or validation.
Changed components
core/embed/rust/src/ui/api/firmware_micropython.rscore/embed/rust/src/ui/layout/menu_item_intent.rscore/embed/rust/src/ui/layout_caesar/ui_firmware.rsInspect captured patch +32 / −36
### core/embed/rust/src/ui/api/firmware_micropython.rs
@@ -18,7 +18,7 @@ use crate::ui::component::Empty;
use crate::ui::display::{fade_backlight_duration, get_backlight, set_backlight};
use crate::ui::layout::base::LAYOUT_STATE;
use crate::ui::layout::device_menu_result::DEVICE_MENU_RESULT;
-use crate::ui::layout::menu_item_intent::MENU_ITEM_INTENT_OBJ;
+use crate::ui::layout::menu_item_intent::micropython::MENU_ITEM_INTENT_OBJ;
use crate::ui::layout::obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ};
use crate::ui::layout::result::{BACK, CANCELLED, CONFIRMED, INFO};
use crate::ui::layout::util::{upy_disable_animation, RecoveryType};
### core/embed/rust/src/ui/layout/menu_item_intent.rs
@@ -1,13 +1,3 @@
-use crate::error::Error;
-#[cfg(feature = "micropython")]
-use crate::micropython::{
- macros::{obj_dict, obj_map, obj_type},
- obj::Obj,
- qstr::Qstr,
- simple_type::SimpleTypeObj,
- typ::FullType,
-};
-
/// What a menu entry means, which each model renders in its own way.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq)]
@@ -19,34 +9,41 @@ pub enum MenuItemIntent {
Danger = 1,
}
-impl TryFrom<u8> for MenuItemIntent {
- type Error = Error;
- fn try_from(value: u8) -> Result<Self, Self::Error> {
- match value {
- 0 => Ok(MenuItemIntent::Standard),
- 1 => Ok(MenuItemIntent::Danger),
- _ => Err(Error::OutOfRange),
+#[cfg(feature = "micropython")]
+pub mod micropython {
+ use super::MenuItemIntent;
+ use crate::micropython::macros::{obj_dict, obj_map, obj_type};
+ use crate::micropython::qstr::Qstr;
+ use crate::micropython::simple_type::SimpleTypeObj;
+ use crate::micropython::typ::FullType;
+ use crate::micropython::{Error, Obj};
+
+ impl TryFrom<u8> for MenuItemIntent {
+ type Error = Error;
+ fn try_from(value: u8) -> Result<Self, Self::Error> {
+ match value {
+ 0 => Ok(MenuItemIntent::Standard),
+ 1 => Ok(MenuItemIntent::Danger),
+ _ => Err(Error::OutOfRange),
+ }
}
}
-}
-#[cfg(feature = "micropython")]
-impl TryFrom<Obj> for MenuItemIntent {
- type Error = Error;
+ impl TryFrom<Obj> for MenuItemIntent {
+ type Error = Error;
- fn try_from(obj: Obj) -> Result<Self, Self::Error> {
- Self::try_from(u8::try_from(obj)?)
+ fn try_from(obj: Obj) -> Result<Self, Self::Error> {
+ Self::try_from(u8::try_from(obj)?)
+ }
}
-}
-#[cfg(feature = "micropython")]
-static MENU_ITEM_INTENT_TYPE: FullType = obj_type! {
- name: Qstr::MP_QSTR_MenuItemIntent,
- locals: &obj_dict!(obj_map! {
- Qstr::MP_QSTR_STANDARD => Obj::small_int(MenuItemIntent::Standard as u16),
- Qstr::MP_QSTR_DANGER => Obj::small_int(MenuItemIntent::Danger as u16),
- }),
-};
+ static MENU_ITEM_INTENT_TYPE: FullType = obj_type! {
+ name: Qstr::MP_QSTR_MenuItemIntent,
+ locals: &obj_dict!(obj_map! {
+ Qstr::MP_QSTR_STANDARD => Obj::small_int(MenuItemIntent::Standard as u16),
+ Qstr::MP_QSTR_DANGER => Obj::small_int(MenuItemIntent::Danger as u16),
+ }),
+ };
-#[cfg(feature = "micropython")]
-pub static MENU_ITEM_INTENT_OBJ: SimpleTypeObj = SimpleTypeObj::new(&MENU_ITEM_INTENT_TYPE);
+ pub static MENU_ITEM_INTENT_OBJ: SimpleTypeObj = SimpleTypeObj::new(&MENU_ITEM_INTENT_TYPE);
+}
### core/embed/rust/src/ui/layout_caesar/ui_firmware.rs
@@ -26,7 +26,6 @@ use crate::ui::component::text::TextStyle;
use crate::ui::component::{
Component, ComponentExt, Empty, FormattedText, Label, LineBreaking, Paginate, Timeout,
};
-use crate::ui::layout::menu_item_intent::MenuItemIntent;
use crate::ui::layout::obj::{LayoutMaybeTrace, LayoutObj, RootComponent};
use crate::ui::layout::util::{ConfirmValueParams, PropsList, RecoveryType};
use crate::ui::notification::Notification;Why this scored 12/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.