Skip to content

Commit d772089

Browse files
committed
refactor: use format_args_capture
Updates format strings to use the implicit named arguments (`format_args_capture`) introduced in [RFC2795][1] whenever possible. | Before | After | | -------------------- | -------------------------------- | | `xxx!("{}", self.x)` | `xxx!("{}", self.x)` (no change) | | `xxx!("{}", x)` | `xxx!("{x}")` | [1]: rust-lang/rfcs#2795
1 parent 510f5c7 commit d772089

File tree

26 files changed

+55
-70
lines changed

26 files changed

+55
-70
lines changed

examples/basic_gr_peach/src/main.rs

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+2-3
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

+2-2
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

+2-2
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

+2-2
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

+4-4
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
}

src/r3_kernel/src/wait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<Traits: KernelTraits> fmt::Debug for WaitPayload<Traits> {
568568
.field("orig_bits", orig_bits)
569569
.finish(),
570570
Self::Semaphore => f.write_str("Semaphore"),
571-
Self::Mutex(mutex) => write!(f, "Mutex({:p})", mutex),
571+
Self::Mutex(mutex) => write!(f, "Mutex({mutex:p})"),
572572
Self::Park => f.write_str("Park"),
573573
Self::Sleep => f.write_str("Sleep"),
574574
Self::__Nonexhaustive => unreachable!(),

src/r3_port_arm_m_test_driver/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::env;
33
fn main() {
44
println!("cargo:rerun-if-env-changed=R3_TEST_DRIVER_LINK_SEARCH");
55
if let Ok(link_search) = env::var("R3_TEST_DRIVER_LINK_SEARCH") {
6-
println!("cargo:rustc-link-search={}", link_search);
6+
println!("cargo:rustc-link-search={link_search}");
77
}
88

99
// Use the linker script `device.x` at the crate root

src/r3_port_arm_m_test_driver/src/board_rp2040.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn panic(info: &PanicInfo) -> ! {
2222
// Disable IRQ
2323
cortex_m::interrupt::disable();
2424

25-
r3_support_rp2040::sprintln!("{}{}", mux::BEGIN_MAIN, info);
25+
r3_support_rp2040::sprintln!("{}{info}", mux::BEGIN_MAIN);
2626

2727
enter_poll_loop();
2828
}

src/r3_port_arm_test_driver/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ use std::env;
33
fn main() {
44
println!("cargo:rerun-if-env-changed=R3_TEST_DRIVER_LINK_SEARCH");
55
if let Ok(link_search) = env::var("R3_TEST_DRIVER_LINK_SEARCH") {
6-
println!("cargo:rustc-link-search={}", link_search);
6+
println!("cargo:rustc-link-search={link_search}");
77
}
88
}

src/r3_port_arm_test_driver/src/panic_semihosting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ fn panic(info: &PanicInfo) -> ! {
2121
// with a single semihosting call.
2222
let buffer = unsafe { &mut BUFFER };
2323
buffer.clear();
24-
let _ = writeln!(buffer, "{}", info);
24+
let _ = writeln!(buffer, "{info}");
2525

26-
let _ = write!(hstdout, "{}", buffer);
26+
let _ = write!(hstdout, "{buffer}");
2727
}
2828
debug::exit(EXIT_FAILURE);
2929

src/r3_port_riscv_test_driver/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66

77
println!("cargo:rerun-if-env-changed=R3_TEST_DRIVER_LINK_SEARCH");
88
if let Ok(link_search) = env::var("R3_TEST_DRIVER_LINK_SEARCH") {
9-
println!("cargo:rustc-link-search={}", link_search);
9+
println!("cargo:rustc-link-search={link_search}");
1010
}
1111

1212
let mut generated_code = String::new();

src/r3_port_riscv_test_driver/src/panic_uart.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn panic(info: &PanicInfo) -> ! {
55
// Disable interrupts
66
unsafe { riscv::register::mstatus::clear_mie() };
77

8-
crate::uart::stdout_write_fmt(format_args!("{}\n", info));
8+
crate::uart::stdout_write_fmt(format_args!("{info}\n"));
99

1010
loop {}
1111
}

src/r3_test_runner/src/driverinterface.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,19 @@ impl TestDriver {
214214
);
215215
}
216216

217-
write!(rustflags, " {}", additional_rustflags).unwrap();
217+
write!(rustflags, " {additional_rustflags}").unwrap();
218218

219219
for name in linker_scripts.inputs.iter() {
220-
write!(rustflags, " -C link-arg=-T{}", name).unwrap();
220+
write!(rustflags, " -C link-arg=-T{name}").unwrap();
221221
}
222222

223223
let target_features = &target_arch_opt.target_features;
224-
log::debug!("target_features = {:?}", target_features);
224+
log::debug!("target_features = {target_features:?}");
225225
if !target_features.is_empty() {
226-
write!(rustflags, " -C target-feature={}", target_features).unwrap();
226+
write!(rustflags, " -C target-feature={target_features}").unwrap();
227227
};
228228

229-
log::debug!("rustflags = {:?}", rustflags);
229+
log::debug!("rustflags = {rustflags:?}");
230230

231231
Ok(Self {
232232
rustflags,
@@ -342,7 +342,7 @@ impl TestDriver {
342342
target
343343
.cargo_features()
344344
.iter()
345-
.map(|f| format!("--features={}", f)),
345+
.map(|f| format!("--features={f}")),
346346
)
347347
.args(if test_run.cpu_lock_by_basepri {
348348
Some("--features=cpu-lock-by-basepri")

src/r3_test_runner/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn main_inner() -> anyhow::Result<()> {
129129
if opt.help_targets {
130130
println!("Supported targets:");
131131
for (name, target) in targets::TARGETS {
132-
println!(" {:30}{}", name, target.target_arch());
132+
println!(" {name:30}{}", target.target_arch());
133133
}
134134
return Ok(());
135135
}

src/r3_test_runner/src/selection.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ impl fmt::Display for TestRun<'_> {
4444
impl fmt::Display for TestCase<'_> {
4545
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4646
match self {
47-
Self::KernelTest(name) => write!(f, "kernel_tests::{}", name),
48-
Self::DriverKernelTest(name) => write!(f, "kernel_tests::{}", name),
49-
Self::KernelBenchmark(name) => write!(f, "kernel_benchmarks::{}", name),
47+
Self::KernelTest(name) => write!(f, "kernel_tests::{name}"),
48+
Self::DriverKernelTest(name) => write!(f, "kernel_tests::{name}"),
49+
Self::KernelBenchmark(name) => write!(f, "kernel_benchmarks::{name}"),
5050
}
5151
}
5252
}

src/r3_test_runner/src/subprocess.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ impl fmt::Display for ShellEscape<'_> {
284284
break;
285285
}
286286
}
287-
write!(f, "{}\"", utf8)
287+
write!(f, "{utf8}\"")
288288
} else if bytes.iter().any(|b| special_chars.contains(b)) {
289289
// Enclose in single quotes
290-
write!(f, "'{}'", utf8)
290+
write!(f, "'{utf8}'")
291291
} else {
292-
write!(f, "{}", utf8)
292+
write!(f, "{utf8}")
293293
}
294294
} else {
295295
// Some bytes are unprintable.

src/r3_test_runner/src/targets/jlink.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl DebugProbe for Fe310JLinkDebugProbe {
100100
let tempdir = TempDir::new("r3_test_runner").map_err(RunError::CreateTempDir)?;
101101
let section_files: Vec<_> = (0..regions.len())
102102
.map(|i| {
103-
let name = format!("{}.bin", i);
103+
let name = format!("{i}.bin");
104104
tempdir.path().join(&name)
105105
})
106106
.collect();

src/r3_test_runner/src/targets/openocd.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,10 @@ impl DebugProbe for GrPeachOpenOcdDebugProbe {
119119
tokio::fs::write(
120120
&cmd_file,
121121
format!(
122-
"{}
123-
{}
122+
"{GR_PEACH_INIT}
123+
{GR_PEACH_RESET}
124124
load_image \"{}\"
125125
shutdown",
126-
GR_PEACH_INIT,
127-
GR_PEACH_RESET,
128126
exe.display(),
129127
),
130128
)
@@ -143,10 +141,9 @@ impl DebugProbe for GrPeachOpenOcdDebugProbe {
143141
tokio::fs::write(
144142
&cmd_file,
145143
format!(
146-
"{}
144+
"{GR_PEACH_INIT}
147145
arm semihosting enable
148-
resume 0x{:x}",
149-
GR_PEACH_INIT, entry,
146+
resume {entry:#x}",
150147
),
151148
)
152149
.await

src/r3_test_runner/src/targets/rp_pico.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,7 @@ fn open_picoboot() -> Result<PicobootInterface> {
371371
// Locate the USB PICOBOOT interface
372372
log::debug!("Looking for the USB PICOBOOT interface");
373373
let config_desc = device.active_config_descriptor().with_context(|| {
374-
format!(
375-
"Failed to get the active config descriptor of the device '{:?}'.",
376-
device
377-
)
374+
format!("Failed to get the active config descriptor of the device '{device:?}'.")
378375
})?;
379376
let interface = config_desc
380377
.interfaces()
@@ -438,16 +435,13 @@ fn open_picoboot() -> Result<PicobootInterface> {
438435
// Open the device
439436
let mut device_handle = device
440437
.open()
441-
.with_context(|| format!("Failed to open the device '{:?}'.", device))?;
438+
.with_context(|| format!("Failed to open the device '{device:?}'."))?;
442439

443440
// Claim the interface
444441
device_handle
445442
.claim_interface(interface_i)
446443
.with_context(|| {
447-
format!(
448-
"Failed to claim the PICOBOOT interface (number {}).",
449-
interface_i
450-
)
444+
format!("Failed to claim the PICOBOOT interface (number {interface_i}).")
451445
})?;
452446

453447
// Reset the PICOBOOT interface
@@ -461,12 +455,7 @@ fn open_picoboot() -> Result<PicobootInterface> {
461455
log::debug!("Sending INTERFACE_RESET");
462456
device_handle
463457
.write_control(0x41, 0x41, 0x0000, interface_i as u16, &[], DEFAULE_TIMEOUT)
464-
.with_context(|| {
465-
format!(
466-
"Failed to send INTERFACE_RESET to the device '{:?}'.",
467-
device
468-
)
469-
})?;
458+
.with_context(|| format!("Failed to send INTERFACE_RESET to the device '{device:?}'."))?;
470459

471460
Ok(PicobootInterface {
472461
device_handle,

src/r3_test_runner/src/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ where
1010
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1111
let mut it = self.0.clone().into_iter();
1212
if let Some(e) = it.next() {
13-
write!(f, "{}", e)?;
13+
write!(f, "{e}")?;
1414
drop(e);
1515
for e in it {
16-
write!(f, ",{}", e)?;
16+
write!(f, ",{e}")?;
1717
}
1818
}
1919
Ok(())
@@ -29,10 +29,10 @@ where
2929
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3030
let mut it = self.0.clone().into_iter();
3131
if let Some(e) = it.next() {
32-
write!(f, "{}", e)?;
32+
write!(f, "{e}")?;
3333
drop(e);
3434
for e in it {
35-
write!(f, ", {}", e)?;
35+
write!(f, ", {e}")?;
3636
}
3737
}
3838
Ok(())

0 commit comments

Comments
 (0)