Skip to content

Commit

Permalink
refactor: use format_args_capture
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yvt committed Mar 21, 2022
1 parent 510f5c7 commit d772089
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 70 deletions.
2 changes: 1 addition & 1 deletion examples/basic_gr_peach/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 99,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
}

fn task1_body() {
support_rza1::sprintln!("COTTAGE = {:?}", COTTAGE);
support_rza1::sprintln!("COTTAGE = {COTTAGE:?}");

COTTAGE.task2.activate().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_gr_peach/src/panic_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ fn panic(info: &PanicInfo) -> ! {
// Disable IRQ
unsafe { asm!("cpsid i") };

sprintln!("{}", info);
sprintln!("{info}");

loop {}
}
2 changes: 1 addition & 1 deletion examples/basic_nucleo_f401re/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 72,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
}

fn task1_body() {
rtt_target::rprintln!("COTTAGE = {:?}", COTTAGE);
rtt_target::rprintln!("COTTAGE = {COTTAGE:?}");

COTTAGE.task2.activate().unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_rp_pico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 52,7 @@ impl support_rp2040::usbstdio::Options for SystemTraits {

// echo the input with brackets
if let Ok(s) = core::str::from_utf8(s) {
support_rp2040::sprint!("[{}]", s);
support_rp2040::sprint!("[{s}]");
} else {
support_rp2040::sprint!("[<not UTF-8>]");
}
Expand Down Expand Up @@ -152,7 152,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
}

fn task1_body() {
support_rp2040::sprintln!("COTTAGE = {:?}", COTTAGE);
support_rp2040::sprintln!("COTTAGE = {COTTAGE:?}");

COTTAGE.task2.activate().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_rp_pico/src/panic_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@ fn panic(info: &PanicInfo) -> ! {
// Disable IRQ
unsafe { asm!("cpsid i") };

r3_support_rp2040::sprintln!("{}", info);
r3_support_rp2040::sprintln!("{info}");

loop {}
}
5 changes: 2 additions & 3 deletions examples/basic_wio_terminal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 500,7 @@ fn button_reporter_task_body() {
if (st ^ new_st) & mask != 0 {
let _ = write!(
Console,
"{:?}: {}",
b,
"{b:?}: {}",
["UP", "DOWN"][(new_st & mask != 0) as usize]
);
}
Expand Down Expand Up @@ -817,7 816,7 @@ fn panic(info: &PanicInfo) -> ! {

if let Some(lcd) = lcd.as_mut() {
let mut msg = arrayvec::ArrayString::<256>::new();
if let Err(_) = write!(msg, "panic: {}", info) {
if let Err(_) = write!(msg, "panic: {info}") {
msg.clear();
msg.push_str("panic: (could not format the message)");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/common/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,7 @@ fn main() {
write_image(
&mut generated_code,
out_dir,
&format!("animation_{}", i),
&format!("animation_{i}"),
frame.buffer(),
);
}
Expand Down Expand Up @@ -61,7 61,7 @@ fn write_image(out: &mut impl Write, dir: &Path, name: &str, image: &RgbaImage)
.map(|image::Rgba(data)| pixelcolor::Rgb888::new(data[0], data[1], data[2]));

let pixels565 = pixels888.map(pixelcolor::Rgb565::from);
let name565 = format!("{}_565", name);
let name565 = format!("{name}_565");
std::fs::write(
dir.join(&name565),
pixels565
Expand Down
4 changes: 2 additions & 2 deletions examples/smp_rp_pico/src/core0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,7 @@ impl support_rp2040::usbstdio::Options for SystemTraits {

// echo the input with brackets
if let Ok(s) = core::str::from_utf8(s) {
support_rp2040::sprint!("[{}]", s);
support_rp2040::sprint!("[{s}]");
} else {
support_rp2040::sprint!("[<not UTF-8>]");
}
Expand Down Expand Up @@ -137,7 137,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
}

fn task1_body() {
support_rp2040::sprintln!("COTTAGE = {:?}", COTTAGE);
support_rp2040::sprintln!("COTTAGE = {COTTAGE:?}");

COTTAGE.task2.activate().unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/smp_rp_pico/src/panic_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 13,15 @@ fn panic(info: &PanicInfo) -> ! {

match cpuid {
0 => {
r3_support_rp2040::sprintln!("{}", info);
r3_support_rp2040::sprintln!("{info}");

loop {
r3_support_rp2040::usbstdio::poll::<crate::core0::SystemTraits>();
}
}
1 => {
use crate::core1;
core1::write_fmt(core1::Core1::new(&p.SIO).unwrap(), format_args!("{}", info));
core1::write_fmt(core1::Core1::new(&p.SIO).unwrap(), format_args!("{info}"));

// Halt the system
loop {
Expand Down
8 changes: 4 additions & 4 deletions src/r3_kernel/src/utils/intrusive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 753,7 @@ fn basic_cell_static() {
let ptr3 = push_static(El(3, Cell::new(None)));
get_accessor!().push_front(ptr3).unwrap();

println!("{:?}", &head);
println!("{head:?}");

let mut accessor = get_accessor!();
assert!(!accessor.is_empty());
Expand All @@ -777,11 777,11 @@ fn basic_cell_static() {
assert_eq!(accessor.prev(ptr2).unwrap(), Some(ptr1));

accessor.remove(ptr1).unwrap();
println!("{:?}", &head);
println!("{head:?}");
accessor.remove(ptr2).unwrap();
println!("{:?}", &head);
println!("{head:?}");
accessor.remove(ptr3).unwrap();
println!("{:?}", &head);
println!("{head:?}");

assert!(accessor.is_empty());
}
2 changes: 1 addition & 1 deletion src/r3_kernel/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 568,7 @@ impl<Traits: KernelTraits> fmt::Debug for WaitPayload<Traits> {
.field("orig_bits", orig_bits)
.finish(),
Self::Semaphore => f.write_str("Semaphore"),
Self::Mutex(mutex) => write!(f, "Mutex({:p})", mutex),
Self::Mutex(mutex) => write!(f, "Mutex({mutex:p})"),
Self::Park => f.write_str("Park"),
Self::Sleep => f.write_str("Sleep"),
Self::__Nonexhaustive => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_arm_m_test_driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@ use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=R3_TEST_DRIVER_LINK_SEARCH");
if let Ok(link_search) = env::var("R3_TEST_DRIVER_LINK_SEARCH") {
println!("cargo:rustc-link-search={}", link_search);
println!("cargo:rustc-link-search={link_search}");
}

// Use the linker script `device.x` at the crate root
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_arm_m_test_driver/src/board_rp2040.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ fn panic(info: &PanicInfo) -> ! {
// Disable IRQ
cortex_m::interrupt::disable();

r3_support_rp2040::sprintln!("{}{}", mux::BEGIN_MAIN, info);
r3_support_rp2040::sprintln!("{}{info}", mux::BEGIN_MAIN);

enter_poll_loop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_arm_test_driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,6 @@ use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=R3_TEST_DRIVER_LINK_SEARCH");
if let Ok(link_search) = env::var("R3_TEST_DRIVER_LINK_SEARCH") {
println!("cargo:rustc-link-search={}", link_search);
println!("cargo:rustc-link-search={link_search}");
}
}
4 changes: 2 additions & 2 deletions src/r3_port_arm_test_driver/src/panic_semihosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 21,9 @@ fn panic(info: &PanicInfo) -> ! {
// with a single semihosting call.
let buffer = unsafe { &mut BUFFER };
buffer.clear();
let _ = writeln!(buffer, "{}", info);
let _ = writeln!(buffer, "{info}");

let _ = write!(hstdout, "{}", buffer);
let _ = write!(hstdout, "{buffer}");
}
debug::exit(EXIT_FAILURE);

Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv_test_driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@ fn main() {

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

let mut generated_code = String::new();
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv_test_driver/src/panic_uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ fn panic(info: &PanicInfo) -> ! {
// Disable interrupts
unsafe { riscv::register::mstatus::clear_mie() };

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

loop {}
}
12 changes: 6 additions & 6 deletions src/r3_test_runner/src/driverinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 214,19 @@ impl TestDriver {
);
}

write!(rustflags, " {}", additional_rustflags).unwrap();
write!(rustflags, " {additional_rustflags}").unwrap();

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

let target_features = &target_arch_opt.target_features;
log::debug!("target_features = {:?}", target_features);
log::debug!("target_features = {target_features:?}");
if !target_features.is_empty() {
write!(rustflags, " -C target-feature={}", target_features).unwrap();
write!(rustflags, " -C target-feature={target_features}").unwrap();
};

log::debug!("rustflags = {:?}", rustflags);
log::debug!("rustflags = {rustflags:?}");

Ok(Self {
rustflags,
Expand Down Expand Up @@ -342,7 342,7 @@ impl TestDriver {
target
.cargo_features()
.iter()
.map(|f| format!("--features={}", f)),
.map(|f| format!("--features={f}")),
)
.args(if test_run.cpu_lock_by_basepri {
Some("--features=cpu-lock-by-basepri")
Expand Down
2 changes: 1 addition & 1 deletion src/r3_test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 129,7 @@ async fn main_inner() -> anyhow::Result<()> {
if opt.help_targets {
println!("Supported targets:");
for (name, target) in targets::TARGETS {
println!(" {:30}{}", name, target.target_arch());
println!(" {name:30}{}", target.target_arch());
}
return Ok(());
}
Expand Down
6 changes: 3 additions & 3 deletions src/r3_test_runner/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 44,9 @@ impl fmt::Display for TestRun<'_> {
impl fmt::Display for TestCase<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::KernelTest(name) => write!(f, "kernel_tests::{}", name),
Self::DriverKernelTest(name) => write!(f, "kernel_tests::{}", name),
Self::KernelBenchmark(name) => write!(f, "kernel_benchmarks::{}", name),
Self::KernelTest(name) => write!(f, "kernel_tests::{name}"),
Self::DriverKernelTest(name) => write!(f, "kernel_tests::{name}"),
Self::KernelBenchmark(name) => write!(f, "kernel_benchmarks::{name}"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/r3_test_runner/src/subprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 284,12 @@ impl fmt::Display for ShellEscape<'_> {
break;
}
}
write!(f, "{}\"", utf8)
write!(f, "{utf8}\"")
} else if bytes.iter().any(|b| special_chars.contains(b)) {
// Enclose in single quotes
write!(f, "'{}'", utf8)
write!(f, "'{utf8}'")
} else {
write!(f, "{}", utf8)
write!(f, "{utf8}")
}
} else {
// Some bytes are unprintable.
Expand Down
2 changes: 1 addition & 1 deletion src/r3_test_runner/src/targets/jlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 100,7 @@ impl DebugProbe for Fe310JLinkDebugProbe {
let tempdir = TempDir::new("r3_test_runner").map_err(RunError::CreateTempDir)?;
let section_files: Vec<_> = (0..regions.len())
.map(|i| {
let name = format!("{}.bin", i);
let name = format!("{i}.bin");
tempdir.path().join(&name)
})
.collect();
Expand Down
11 changes: 4 additions & 7 deletions src/r3_test_runner/src/targets/openocd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 119,10 @@ impl DebugProbe for GrPeachOpenOcdDebugProbe {
tokio::fs::write(
&cmd_file,
format!(
"{}
{}
"{GR_PEACH_INIT}
{GR_PEACH_RESET}
load_image \"{}\"
shutdown",
GR_PEACH_INIT,
GR_PEACH_RESET,
exe.display(),
),
)
Expand All @@ -143,10 141,9 @@ impl DebugProbe for GrPeachOpenOcdDebugProbe {
tokio::fs::write(
&cmd_file,
format!(
"{}
"{GR_PEACH_INIT}
arm semihosting enable
resume 0x{:x}",
GR_PEACH_INIT, entry,
resume {entry:#x}",
),
)
.await
Expand Down
19 changes: 4 additions & 15 deletions src/r3_test_runner/src/targets/rp_pico.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 371,7 @@ fn open_picoboot() -> Result<PicobootInterface> {
// Locate the USB PICOBOOT interface
log::debug!("Looking for the USB PICOBOOT interface");
let config_desc = device.active_config_descriptor().with_context(|| {
format!(
"Failed to get the active config descriptor of the device '{:?}'.",
device
)
format!("Failed to get the active config descriptor of the device '{device:?}'.")
})?;
let interface = config_desc
.interfaces()
Expand Down Expand Up @@ -438,16 435,13 @@ fn open_picoboot() -> Result<PicobootInterface> {
// Open the device
let mut device_handle = device
.open()
.with_context(|| format!("Failed to open the device '{:?}'.", device))?;
.with_context(|| format!("Failed to open the device '{device:?}'."))?;

// Claim the interface
device_handle
.claim_interface(interface_i)
.with_context(|| {
format!(
"Failed to claim the PICOBOOT interface (number {}).",
interface_i
)
format!("Failed to claim the PICOBOOT interface (number {interface_i}).")
})?;

// Reset the PICOBOOT interface
Expand All @@ -461,12 455,7 @@ fn open_picoboot() -> Result<PicobootInterface> {
log::debug!("Sending INTERFACE_RESET");
device_handle
.write_control(0x41, 0x41, 0x0000, interface_i as u16, &[], DEFAULE_TIMEOUT)
.with_context(|| {
format!(
"Failed to send INTERFACE_RESET to the device '{:?}'.",
device
)
})?;
.with_context(|| format!("Failed to send INTERFACE_RESET to the device '{device:?}'."))?;

Ok(PicobootInterface {
device_handle,
Expand Down
8 changes: 4 additions & 4 deletions src/r3_test_runner/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 10,10 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut it = self.0.clone().into_iter();
if let Some(e) = it.next() {
write!(f, "{}", e)?;
write!(f, "{e}")?;
drop(e);
for e in it {
write!(f, ",{}", e)?;
write!(f, ",{e}")?;
}
}
Ok(())
Expand All @@ -29,10 29,10 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut it = self.0.clone().into_iter();
if let Some(e) = it.next() {
write!(f, "{}", e)?;
write!(f, "{e}")?;
drop(e);
for e in it {
write!(f, ", {}", e)?;
write!(f, ", {e}")?;
}
}
Ok(())
Expand Down
Loading

0 comments on commit d772089

Please sign in to comment.