Skip to content

Commit 45da448

Browse files
committed
refactor: use format_args_capture (Rust RFC 2795)
Updates format strings to use the implicit named arguments (`format_args_capture`) introduced in [Rust RFC 2795][1] whenever possible. | Before | After | | -------------------- | -------------------------------- | | `xxx!("{}", self.x)` | `xxx!("{}", self.x)` (no change) | | `xxx!("{}", x)` | `xxx!("{x}")` | [1]: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html
1 parent 510f5c7 commit 45da448

File tree

26 files changed

+55
-70
lines changed

26 files changed

+55
-70
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ fn button_reporter_task_body() {
500500
if (st ^ new_st) & mask != 0 {
501501
let _ = write!(
502502
Console,
503-
"{:?}: {}",
504-
b,
503+
"{b:?}: {}",
505504
["UP", "DOWN"][(new_st & mask != 0) as usize]
506505
);
507506
}
@@ -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/r3_kernel/src/utils/intrusive_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ fn basic_cell_static() {
753753
let ptr3 = push_static(El(3, Cell::new(None)));
754754
get_accessor!().push_front(ptr3).unwrap();
755755

756-
println!("{:?}", &head);
756+
println!("{head:?}");
757757

758758
let mut accessor = get_accessor!();
759759
assert!(!accessor.is_empty());
@@ -777,11 +777,11 @@ fn basic_cell_static() {
777777
assert_eq!(accessor.prev(ptr2).unwrap(), Some(ptr1));
778778

779779
accessor.remove(ptr1).unwrap();
780-
println!("{:?}", &head);
780+
println!("{head:?}");
781781
accessor.remove(ptr2).unwrap();
782-
println!("{:?}", &head);
782+
println!("{head:?}");
783783
accessor.remove(ptr3).unwrap();
784-
println!("{:?}", &head);
784+
println!("{head:?}");
785785

786786
assert!(accessor.is_empty());
787787
}

0 commit comments

Comments
 (0)