Skip to content

Commit

Permalink
Merge branch '🎨-format-string' into 🦆
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Jan 14, 2023
2 parents 1e93844 + 2344f90 commit 9e89389
Show file tree
Hide file tree
Showing 48 changed files with 188 additions and 277 deletions.
2 changes: 1 addition & 1 deletion examples/basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<'_, SystemTraits>) -> Objects {
}

fn task1_body() {
log::trace!("COTTAGE = {:#?}", COTTAGE);
log::trace!("COTTAGE = {COTTAGE:#?}");
log::trace!("KENREL = {:#?}", System::debug());

COTTAGE.task2.activate().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_wio_terminal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,10 @@ fn panic(info: &PanicInfo) -> ! {

#[cortex_m_rt::exception]
fn DefaultHandler(x: i16) -> ! {
panic!("unhandled exception {}", x);
panic!("unhandled exception {x}");
}

#[cortex_m_rt::exception]
fn HardFault(fr: &cortex_m_rt::ExceptionFrame) -> ! {
panic!("hard fault: {:?}", fr);
panic!("hard fault: {fr:?}");
}
12 changes: 3 additions & 9 deletions examples/common/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
w!("pub static ANIMATION_FRAMES_565: &[fn() -> \
ImageRaw<'static, Rgb565, LittleEndian>] = &[\n");
for i in 0..frames.len() {
w!(" animation_{}_565,\n", i);
w!(" animation_{i}_565,\n");
}
w!("];\n");

Expand Down Expand Up @@ -69,14 +69,8 @@ fn write_image(out: &mut impl Write, dir: &Path, name: &str, image: &RgbaImage)
.collect::<Vec<u8>>(),
)
.unwrap();
w!(
"pub fn {}() -> ImageRaw<'static, Rgb565, LittleEndian> {{\n",
name565
);
w!(
" static IMAGE: &[u8] = include_bytes!(\"{}\");\n",
name565
);
w!("pub fn {name565}() -> ImageRaw<'static, Rgb565, LittleEndian> {{\n");
w!(" static IMAGE: &[u8] = include_bytes!(\"{name565}\");\n");
w!(" ImageRaw::new(IMAGE, {})\n", image.width());
w!("}}\n");
}
2 changes: 1 addition & 1 deletion src/r3_core/src/kernel/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ define_object! {
/// Err(LockMutexError::Abandoned) => {
/// app.mutex.mark_consistent().unwrap();
/// }
/// Err(e) => panic!("failed to lock the mutex: {:?}", e),
/// Err(e) => panic!("failed to lock the mutex: {e:?}"),
/// }
/// app.mutex.unlock().unwrap();
/// }
Expand Down
24 changes: 12 additions & 12 deletions src/r3_core/src/utils/binary_heap/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ fn test_inner<T: BinaryHeap + Default + super::VecLike<Element = usize> + std::f
let mut subject = T::default();
let mut reference = Vec::new();

log::debug!("max_len = {}, bytecode len = {}", max_len, bytecode.len());
log::debug!("max_len = {max_len}, bytecode len = {}", bytecode.len());

for cmd in interpret(&bytecode, max_len) {
log::trace!(" {:?}", cmd);
log::trace!(" {cmd:?}");
match cmd {
Cmd::Insert(value) => {
let i = subject.heap_push(value, Ctx);
log::trace!(" → {}", i);
log::trace!(" → {i}");

let i = reference.binary_search(&value).unwrap_or_else(|x| x);
reference.insert(i, value);
}
Cmd::Remove(i) => {
let out_subject = subject.heap_remove(i, Ctx).unwrap();
log::trace!(" → {}", out_subject);
log::trace!(" → {out_subject}");

let i_ref = reference.binary_search(&out_subject).unwrap();
reference.remove(i_ref);
}
}
log::trace!("[sorted: {:?}]", reference);
log::trace!("[subject: {:?}]", subject);
log::trace!("[sorted: {reference:?}]");
log::trace!("[subject: {subject:?}]");
if subject.len() > 0 {
assert_eq!(subject[0], reference[0]);
}
Expand Down Expand Up @@ -120,7 +120,7 @@ impl BinaryHeapCtx<El> for TrackingCtx<'_> {

fn on_move(&mut self, e: &mut El, new_index: usize) {
self.el_position[e.id] = Some(new_index);
log::trace!(" on_move{:?}", (e, new_index));
log::trace!(" on_move({e:?}, {new_index})");
}
}

Expand All @@ -135,29 +135,29 @@ fn position_tracking(bytecode: Vec<u8>) {
log::debug!("bytecode len = {}", bytecode.len());

for cmd in interpret(&bytecode, usize::MAX) {
log::trace!(" {:?}", cmd);
log::trace!(" {cmd:?}");
match cmd {
Cmd::Insert(value) => {
let id = el_position.len();
el_position.push(None);
let i = subject.heap_push(El { value, id }, TrackingCtx { el_position });
log::trace!(" → {}", i);
log::trace!(" → {i}");

// `on_move` should have reported the position for the
// newly-inserted element
assert_eq!(el_position[id], Some(i));
}
Cmd::Remove(i) => {
let out_subject = subject.heap_remove(i, TrackingCtx { el_position }).unwrap();
log::trace!(" → {:?}", out_subject);
log::trace!(" → {out_subject:?}");

// For a removed element, we must modify `el_position` manually
el_position[out_subject.id] = None;
}
}

log::trace!("[subject: {:?}]", subject);
log::trace!("[el_position: {:?}]", el_position);
log::trace!("[subject: {subject:?}]");
log::trace!("[el_position: {el_position:?}]");

// Check if `el_position` correctly represents
// the current state of `subject`
Expand Down
22 changes: 6 additions & 16 deletions src/r3_core/src/utils/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
fn lower_bound(mut values: Vec<u32>, arbitrary_value: u32) {
values.sort();

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

for (i, &e) in values.iter().enumerate() {
let mut expected = i;
Expand All @@ -54,12 +54,7 @@ mod tests {
}

let got = lower_bound!(values.len(), |i| values[i] < e);
log::debug!(
" lower_bound(values[{}]) = {} (expected {})",
i,
got,
expected
);
log::debug!(" lower_bound(values[{i}]) = {got} (expected {expected})");

assert_eq!(got, expected);
}
Expand All @@ -70,29 +65,24 @@ mod tests {
}
let mid = win[0] + (win[1] - win[0]) / 2;
let got = lower_bound!(values.len(), |i| values[i] < mid);
log::debug!(
" lower_bound(mean(values[{}] + values[{} + 1])) = {}",
i,
i,
got
);
log::debug!(" lower_bound(mean(values[{i}] + values[{i} + 1])) = {got}");
assert_eq!(got, i + 1);
}

if values.is_empty() {
let got = lower_bound!(values.len(), |i| values[i] < arbitrary_value);
log::debug!(" lower_bound({}) = {}", arbitrary_value, got);
log::debug!(" lower_bound({arbitrary_value}) = {got}");
assert_eq!(got, 0);
} else {
if *values.first().unwrap() > 0 {
#[allow(unused_comparisons)]
let got = lower_bound!(values.len(), |i| values[i] < 0);
log::debug!(" lower_bound(0) = {}", got);
log::debug!(" lower_bound(0) = {got}");
assert_eq!(got, 0);
}
if *values.last().unwrap() < u32::MAX {
let got = lower_bound!(values.len(), |i| values[i] < u32::MAX);
log::debug!(" lower_bound({}) = {}", u32::MAX, got);
log::debug!(" lower_bound({}) = {got}", u32::MAX);
assert_eq!(got, values.len());
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/r3_kernel/src/utils/ctz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ mod tests {

assert_eq!(
expected, got,
"func({}) = {}, expected = {}",
in_value, got, expected,
"func({in_value}) = {got}, expected = {expected}",
);
}

Expand All @@ -323,8 +322,7 @@ mod tests {

assert_eq!(
expected, got,
"func({}) = {}, expected = {}",
in_value, got, expected,
"func({in_value}) = {got}, expected = {expected}",
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/r3_kernel/src/utils/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ mod tests {

let got_set_bits: Vec<u32> = i.one_digits().collect();

log::trace!("i = 0x{:x}", i);
log::trace!(" got = {:?}", got_set_bits);
log::trace!(" expected = {:?}", set_bits);
log::trace!("i = {i:#x}");
log::trace!(" got = {got_set_bits:?}");
log::trace!(" expected = {set_bits:?}");

got_set_bits == set_bits
}
Expand Down
4 changes: 2 additions & 2 deletions src/r3_kernel/src/utils/prio_bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ mod tests {
let mut subject = T::INIT;
let mut reference = BTreePrioBitmap::new();

log::info!("size = {}", size);
log::info!("size = {size}");

for cmd in interpret(&bytecode, size) {
log::trace!(" {:?}", cmd);
log::trace!(" {cmd:?}");
match cmd {
Cmd::Insert(bit) => {
subject.set(bit);
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv/src/threading/imp/instemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ unsafe fn panic_on_unhandled_exception(fl_state: *mut usize, mcause: usize) -> !
// Read the original PC from the first-level state
let pc = unsafe { *fl_state.offset(16) };

panic!("unhandled exception {} at 0x{:08x}", mcause, pc);
panic!("unhandled exception {mcause} at {pc:#08x}");
}

#[cfg(not(feature = "emulate-lr-sc"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ unsafe fn do_test<System: traits::KernelBase>() {
let expected = unsafe { &*ST2.as_ptr() };
assert_eq!(
*got, *expected,
"reached an incorrect final state after executing '{}'",
code
"reached an incorrect final state after executing '{code}'",
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv_test_driver/src/panic_rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn panic(info: &PanicInfo) -> ! {
if let Some(mut channel) = unsafe { UpChannel::conjure(0) } {
channel.set_mode(ChannelMode::BlockIfFull);

writeln!(channel, "{}", info).ok();
writeln!(channel, "{info}").ok();
}

loop {}
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_std/benches/test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn main() {
.init();

for (name, entry) in KERNEL_BENCHMARKS {
log::info!("--- kernel benchmark '{}' ---", name);
log::info!("--- kernel benchmark '{name}' ---");
entry();
}
}
Loading

0 comments on commit 9e89389

Please sign in to comment.