chore(core): derive `Debug` only for tests
What changed, and why it matters
This commit removes automatic Debug printing support from several Rust data structures in the Trezor firmware's production builds, keeping it only for unit tests. It is a code hygiene or size-reduction change with no visible security relevance.
No security action required. Treat as a normal maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit changes #[derive(Debug)] to #[cfg_attr(test, derive(Debug))] on StrBuffer, Base64Error, SmpError, TString, TranslatedString, and DotType. This means the Debug trait is no longer implemented for these types in non-test builds. The change is purely a build-time/development tooling adjustment and does not alter runtime behavior, memory safety, or cryptographic logic.
Changed components
core/embed/rust/src/micropython/buffer.rscore/embed/rust/src/smp/base64.rscore/embed/rust/src/smp/mod.rscore/embed/rust/src/strutil.rscore/embed/rust/src/translations/generated/translated_string.rscore/embed/rust/src/translations/generated/translated_string.rs.makocore/embed/rust/src/ui/layout_caesar/component/scrollbar.rsInspect captured patch +7 / −3
diff --git a/core/embed/rust/src/micropython/buffer.rs b/core/embed/rust/src/micropython/buffer.rs
index 456d131f..131aa7b4 100644
--- a/core/embed/rust/src/micropython/buffer.rs
+++ b/core/embed/rust/src/micropython/buffer.rs
@@ -21,6 +21,7 @@ use super::ffi;
/// substring slices while keeping the head pointer as required by GC.
#[repr(C)]
#[derive(Copy, Clone)]
+#[cfg_attr(test, derive(Debug))]
pub struct StrBuffer {
ptr: *const u8,
len: u16,
diff --git a/core/embed/rust/src/smp/base64.rs b/core/embed/rust/src/smp/base64.rs
index 1f2375d4..86cb0220 100644
--- a/core/embed/rust/src/smp/base64.rs
+++ b/core/embed/rust/src/smp/base64.rs
@@ -5,7 +5,7 @@
/// - `InvalidLength` if the input length is not a multiple of 4 for decoding.
/// - `InvalidCharacter` if an invalid Base64 character is encountered during
/// decoding.
-#[derive(Debug)]
+#[cfg_attr(test, derive(Debug))]
pub enum Base64Error {
OutputBufferTooSmall,
InvalidLength,
diff --git a/core/embed/rust/src/smp/mod.rs b/core/embed/rust/src/smp/mod.rs
index d725aab3..471e254c 100644
--- a/core/embed/rust/src/smp/mod.rs
+++ b/core/embed/rust/src/smp/mod.rs
@@ -61,7 +61,7 @@ static SMP_RECEIVER: ReceiverStorage = ReceiverStorage(UnsafeCell::new(None));
/// SMP_RECEIVER without locking IRQ, data races could occur.
unsafe impl Sync for ReceiverStorage {}
-#[derive(Debug)]
+#[cfg_attr(test, derive(Debug))]
pub enum SmpError {
Timeout,
WrongMessage,
diff --git a/core/embed/rust/src/strutil.rs b/core/embed/rust/src/strutil.rs
index fe7a2cc8..616ba4df 100644
--- a/core/embed/rust/src/strutil.rs
+++ b/core/embed/rust/src/strutil.rs
@@ -141,6 +141,7 @@ pub fn plural_form(template: &str, count: u32) -> ShortString {
}
#[derive(Copy, Clone)]
+#[cfg_attr(test, derive(Debug))]
pub enum TString<'a> {
#[cfg(feature = "micropython")]
Allocated(StrBuffer),
diff --git a/core/embed/rust/src/translations/generated/translated_string.rs b/core/embed/rust/src/translations/generated/translated_string.rs
index 4e166ac8..b168fda1 100644
--- a/core/embed/rust/src/translations/generated/translated_string.rs
+++ b/core/embed/rust/src/translations/generated/translated_string.rs
@@ -8,6 +8,7 @@ use crate::micropython::qstr::Qstr;
#[derive(Copy, Clone, FromPrimitive, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
+#[cfg_attr(test, derive(Debug))]
#[repr(u16)]
#[allow(non_camel_case_types)]
pub enum TranslatedString {
diff --git a/core/embed/rust/src/translations/generated/translated_string.rs.mako b/core/embed/rust/src/translations/generated/translated_string.rs.mako
index de482241..ba2f37bb 100644
--- a/core/embed/rust/src/translations/generated/translated_string.rs.mako
+++ b/core/embed/rust/src/translations/generated/translated_string.rs.mako
@@ -38,6 +38,7 @@ use crate::micropython::qstr::Qstr;
#[derive(Copy, Clone, FromPrimitive, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
+#[cfg_attr(test, derive(Debug))]
#[repr(u16)]
#[allow(non_camel_case_types)]
pub enum TranslatedString {
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 9fd90532..dd1ee52b 100644
--- a/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs
+++ b/core/embed/rust/src/ui/layout_caesar/component/scrollbar.rs
@@ -16,7 +16,7 @@ pub struct ScrollBar {
}
/// Carrying the appearance of the scrollbar dot.
-#[derive(Debug)]
+#[cfg_attr(test, derive(Debug))]
enum DotType {
BigFull, // *
Big, // O
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.