Skip to content

Commit f05480c

Browse files
committed
Merge branch '♻️-format' into 🦆
2 parents 510f5c7 + dc45afb commit f05480c

File tree

36 files changed

+135
-154
lines changed

36 files changed

+135
-154
lines changed

examples/basic_gr_peach/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
9999
}
100100

101101
fn task1_body() {
102-
support_rza1::sprintln!("COTTAGE = {:?}", COTTAGE);
102+
support_rza1::sprintln!("COTTAGE = {COTTAGE:?}");
103103

104104
COTTAGE.task2.activate().unwrap();
105105
}

examples/basic_gr_peach/src/panic_serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn panic(info: &PanicInfo) -> ! {
88
// Disable IRQ
99
unsafe { asm!("cpsid i") };
1010

11-
sprintln!("{}", info);
11+
sprintln!("{info}");
1212

1313
loop {}
1414
}

examples/basic_nucleo_f401re/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
7272
}
7373

7474
fn task1_body() {
75-
rtt_target::rprintln!("COTTAGE = {:?}", COTTAGE);
75+
rtt_target::rprintln!("COTTAGE = {COTTAGE:?}");
7676

7777
COTTAGE.task2.activate().unwrap();
7878
}

examples/basic_rp_pico/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl support_rp2040::usbstdio::Options for SystemTraits {
5252

5353
// echo the input with brackets
5454
if let Ok(s) = core::str::from_utf8(s) {
55-
support_rp2040::sprint!("[{}]", s);
55+
support_rp2040::sprint!("[{s}]");
5656
} else {
5757
support_rp2040::sprint!("[<not UTF-8>]");
5858
}
@@ -152,7 +152,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
152152
}
153153

154154
fn task1_body() {
155-
support_rp2040::sprintln!("COTTAGE = {:?}", COTTAGE);
155+
support_rp2040::sprintln!("COTTAGE = {COTTAGE:?}");
156156

157157
COTTAGE.task2.activate().unwrap();
158158
}

examples/basic_rp_pico/src/panic_serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn panic(info: &PanicInfo) -> ! {
77
// Disable IRQ
88
unsafe { asm!("cpsid i") };
99

10-
r3_support_rp2040::sprintln!("{}", info);
10+
r3_support_rp2040::sprintln!("{info}");
1111

1212
loop {}
1313
}

examples/basic_wio_terminal/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,8 @@ fn button_reporter_task_body() {
500500
if (st ^ new_st) & mask != 0 {
501501
let _ = write!(
502502
Console,
503-
"{:?}: {}",
504-
b,
505-
["UP", "DOWN"][(new_st & mask != 0) as usize]
503+
"{b:?}: {dir}",
504+
dir = ["UP", "DOWN"][(new_st & mask != 0) as usize]
506505
);
507506
}
508507
}
@@ -817,7 +816,7 @@ fn panic(info: &PanicInfo) -> ! {
817816

818817
if let Some(lcd) = lcd.as_mut() {
819818
let mut msg = arrayvec::ArrayString::<256>::new();
820-
if let Err(_) = write!(msg, "panic: {}", info) {
819+
if let Err(_) = write!(msg, "panic: {info}") {
821820
msg.clear();
822821
msg.push_str("panic: (could not format the message)");
823822
}

examples/common/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() {
3333
write_image(
3434
&mut generated_code,
3535
out_dir,
36-
&format!("animation_{}", i),
36+
&format!("animation_{i}"),
3737
frame.buffer(),
3838
);
3939
}
@@ -61,7 +61,7 @@ fn write_image(out: &mut impl Write, dir: &Path, name: &str, image: &RgbaImage)
6161
.map(|image::Rgba(data)| pixelcolor::Rgb888::new(data[0], data[1], data[2]));
6262

6363
let pixels565 = pixels888.map(pixelcolor::Rgb565::from);
64-
let name565 = format!("{}_565", name);
64+
let name565 = format!("{name}_565");
6565
std::fs::write(
6666
dir.join(&name565),
6767
pixels565

examples/smp_rp_pico/src/core0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl support_rp2040::usbstdio::Options for SystemTraits {
3232

3333
// echo the input with brackets
3434
if let Ok(s) = core::str::from_utf8(s) {
35-
support_rp2040::sprint!("[{}]", s);
35+
support_rp2040::sprint!("[{s}]");
3636
} else {
3737
support_rp2040::sprint!("[<not UTF-8>]");
3838
}
@@ -137,7 +137,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
137137
}
138138

139139
fn task1_body() {
140-
support_rp2040::sprintln!("COTTAGE = {:?}", COTTAGE);
140+
support_rp2040::sprintln!("COTTAGE = {COTTAGE:?}");
141141

142142
COTTAGE.task2.activate().unwrap();
143143
}

examples/smp_rp_pico/src/panic_serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ fn panic(info: &PanicInfo) -> ! {
1313

1414
match cpuid {
1515
0 => {
16-
r3_support_rp2040::sprintln!("{}", info);
16+
r3_support_rp2040::sprintln!("{info}");
1717

1818
loop {
1919
r3_support_rp2040::usbstdio::poll::<crate::core0::SystemTraits>();
2020
}
2121
}
2222
1 => {
2323
use crate::core1;
24-
core1::write_fmt(core1::Core1::new(&p.SIO).unwrap(), format_args!("{}", info));
24+
core1::write_fmt(core1::Core1::new(&p.SIO).unwrap(), format_args!("{info}"));
2525

2626
// Halt the system
2727
loop {

src/arm_semihosting/src/macros.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ macro_rules! syscall1 {
3434
/// This macro returns a `Result<(), ()>` value
3535
#[macro_export]
3636
macro_rules! hprint {
37-
($s:expr) => {
38-
$crate::export::hstdout_str($s)
39-
};
4037
($($tt:tt)*) => {
41-
$crate::export::hstdout_fmt(format_args!($($tt)*))
38+
match ::core::format_args!($($tt)*) {
39+
args => if let ::core::option::Option::Some(s) = args.as_str() {
40+
$crate::export::hstdout_str(s)
41+
} else {
42+
$crate::export::hstdout_fmt(args)
43+
},
44+
}
4245
};
4346
}
4447

@@ -47,14 +50,11 @@ macro_rules! hprint {
4750
/// This macro returns a `Result<(), ()>` value
4851
#[macro_export]
4952
macro_rules! hprintln {
50-
() => {
51-
$crate::export::hstdout_str("\n")
52-
};
53-
($s:expr) => {
54-
$crate::export::hstdout_str(concat!($s, "\n"))
55-
};
56-
($s:expr, $($tt:tt)*) => {
57-
$crate::export::hstdout_fmt(format_args!(concat!($s, "\n"), $($tt)*))
53+
($($tt:tt)*) => {
54+
match $crate::hprint!($($tt)*) {
55+
Ok(()) => $crate::export::hstdout_str("\n"),
56+
Err(()) => Err(()),
57+
}
5858
};
5959
}
6060

@@ -63,11 +63,14 @@ macro_rules! hprintln {
6363
/// This macro returns a `Result<(), ()>` value
6464
#[macro_export]
6565
macro_rules! heprint {
66-
($s:expr) => {
67-
$crate::export::hstderr_str($s)
68-
};
6966
($($tt:tt)*) => {
70-
$crate::export::hstderr_fmt(format_args!($($tt)*))
67+
match ::core::format_args!($($tt)*) {
68+
args => if let ::core::option::Option::Some(s) = args.as_str() {
69+
$crate::export::hstderr_str(s)
70+
} else {
71+
$crate::export::hstderr_fmt(args)
72+
},
73+
}
7174
};
7275
}
7376

@@ -76,14 +79,11 @@ macro_rules! heprint {
7679
/// This macro returns a `Result<(), ()>` value
7780
#[macro_export]
7881
macro_rules! heprintln {
79-
() => {
80-
$crate::export::hstderr_str("\n")
81-
};
82-
($s:expr) => {
83-
$crate::export::hstderr_str(concat!($s, "\n"))
84-
};
85-
($s:expr, $($tt:tt)*) => {
86-
$crate::export::hstderr_fmt(format_args!(concat!($s, "\n"), $($tt)*))
82+
($($tt:tt)*) => {
83+
match $crate::heprint!($($tt)*) {
84+
Ok(()) => $crate::export::hstderr_str("\n"),
85+
Err(()) => Err(()),
86+
}
8787
};
8888
}
8989

0 commit comments

Comments
 (0)