Skip to content

Commit

Permalink
Set :? type hint to inner fields
Browse files Browse the repository at this point in the history
Instead of applying the Debug type hint `:?` to all inner fields.

* add test to check struct with generic type
* update test output
  • Loading branch information
justahero committed Mar 26, 2021
1 parent b9f54f5 commit 8d97af4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions firmware/qemu/src/bin/hints_inner.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
0.000005 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 20 }
0.000006 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 0x14 }
0.000007 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 0b10100 }
0.000008 INFO S1 { x: "hi", y: 42 }
0.000009 INFO S1 { x: "hi", y: 0x2a }
2 changes: 2 additions & 0 deletions firmware/qemu/src/bin/hints_inner.release.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
0.000005 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 20 }
0.000006 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 0x14 }
0.000007 INFO S2 { s: S1 { x: 0b100, y: 12 }, z: 0b10100 }
0.000008 INFO S1 { x: "hi", y: 42 }
0.000009 INFO S1 { x: "hi", y: 0x2a }
13 changes: 13 additions & 0 deletions firmware/qemu/src/bin/hints_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ fn main() -> ! {
);
}

{
#[derive(defmt::Format)]
struct S1<T> {
x: T,
y: u8,
}

// outputs: "S { x: hi, y: 42 }"
defmt::info!("{}", S1 { x: "hi", y: 42 });
// outputs: "S { x: hi, y: 0x2a }"
defmt::info!("{:x}", S1 { x: "hi", y: 42 });
}

loop {
debug::exit(debug::EXIT_SUCCESS)
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/log.out
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@
0.000110 INFO b"Hi"
0.000111 INFO b"Hi"
0.000112 INFO [45054, 49406]
0.000113 INFO [Data { name: b"Hi", value: true }]
0.000113 INFO [Data { name: [72, 105], value: true }]
0.000114 INFO true true
0.000115 INFO QEMU test finished!
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/log.release.out
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@
0.000108 INFO b"Hi"
0.000109 INFO b"Hi"
0.000110 INFO [45054, 49406]
0.000111 INFO [Data { name: b"Hi", value: true }]
0.000111 INFO [Data { name: [72, 105], value: true }]
0.000112 INFO true true
0.000113 INFO QEMU test finished!
6 changes: 1 addition & 5 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,7 @@ fn fields(
"?".to_string()
});
if let Some(ident) = f.ident.as_ref() {
if ty == "str" {
core::write!(format, "{}: {{={}:?}}", ident, ty).ok();
} else {
core::write!(format, "{}: {{={}}}", ident, ty).ok();
}
core::write!(format, "{}: {{={}:?}}", ident, ty).ok();

if ty == "?" {
list.push(quote!(f.inner.fmt(#ident, false)));
Expand Down

0 comments on commit 8d97af4

Please sign in to comment.