Skip to content

Commit

Permalink
clippy & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKruckenberg committed Feb 21, 2025
1 parent 324f4ee commit 9eaff41
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions kernel/src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Backtrace<'a, const MAX_FRAMES: usize> {
pub frames_omitted: usize,
}

impl<'a, const MAX_FRAMES: usize> Backtrace<'a, MAX_FRAMES> {
impl<const MAX_FRAMES: usize> Backtrace<'_, MAX_FRAMES> {
/// Captures a backtrace at the callsite of this function, returning an owned representation.
///
/// The returned object is almost entirely self-contained. It can be cloned, or send to other threads.
Expand Down Expand Up @@ -104,6 +104,7 @@ impl<'a, const MAX_FRAMES: usize> Backtrace<'a, MAX_FRAMES> {
}
}

#[expect(tail_expr_drop_order, reason = "")]
Ok(Self {
symbolize_ctx: SYMBOLIZE_CONTEXT.as_ref(),
frames,
Expand All @@ -116,8 +117,7 @@ impl<const MAX_FRAMES: usize> fmt::Display for Backtrace<'_, MAX_FRAMES> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
writeln!(f, "stack backtrace:")?;

let mut frame_idx: i32 = 0;
for ip in &self.frames {
for (frame_idx, ip) in self.frames.iter().enumerate() {
// if the symbolication state isn't setup, yet we can't print symbols the addresses will have
// to suffice...
if let Some(symbolize_ctx) = self.symbolize_ctx {
Expand Down Expand Up @@ -147,12 +147,13 @@ impl<const MAX_FRAMES: usize> fmt::Display for Backtrace<'_, MAX_FRAMES> {
} else {
writeln!(f, "{frame_idx}: {address:#x}", address = ip)?;
}

frame_idx += 1i32;
}

if self.symbolize_ctx.is_none() {
let _ = writeln!(f, "note: backtrace subsystem wasn't initialized, no symbols were printed.");
let _ = writeln!(
f,
"note: backtrace subsystem wasn't initialized, no symbols were printed."
);
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/backtrace/symbolize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl<'a> SymbolizeContext<'a> {
})?;
let addr2line = addr2line::Context::from_dwarf(dwarf)?;

#[expect(tail_expr_drop_order, reason = "")]
Ok(Self {
addr2line,
elf,
Expand Down Expand Up @@ -225,6 +226,7 @@ impl<'a> SymbolizeContext<'a> {
})
.unwrap();

#[expect(tail_expr_drop_order, reason = "")]
Ok(SymbolsIter {
addr: probe,
elf: &self.elf,
Expand Down
5 changes: 2 additions & 3 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern crate alloc;

mod allocator;
mod arch;
mod backtrace;
mod cmdline;
mod cpu_local;
mod device_tree;
Expand All @@ -46,7 +47,6 @@ mod traps;
mod util;
mod vm;
mod wasm;
mod backtrace;

use crate::device_tree::device_tree;
use crate::error::Error;
Expand All @@ -62,7 +62,6 @@ use cpu_local::cpu_local;
use loader_api::{BootInfo, LoaderConfig, MemoryRegionKind};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use backtrace::Backtrace;
use sync::Once;
use vm::frame_alloc;
use vm::PhysicalAddress;
Expand Down Expand Up @@ -149,7 +148,7 @@ fn kmain(cpuid: usize, boot_info: &'static BootInfo, boot_ticks: u64) {

// fully initialize the tracing subsystem now that we can allocate
tracing::init(cmdline.log);

// perform global, architecture-specific initialization
arch::init_early();

Expand Down
12 changes: 6 additions & 6 deletions kernel/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::{arch, backtrace};
use crate::backtrace::Backtrace;
use crate::panic::panic_count::MustAbort;
use crate::{arch, backtrace};
use alloc::boxed::Box;
use alloc::string::String;
use core::any::Any;
use core::panic::{PanicPayload, UnwindSafe};
use core::{fmt, mem, slice};
use loader_api::BootInfo;
use sync::{LazyLock, OnceLock};
use core::{fmt, mem};

/// Determines whether the current thread is unwinding because of panic.
#[inline]
Expand All @@ -31,6 +29,7 @@ pub fn catch_unwind<F, R>(f: F) -> Result<R, Box<dyn Any + Send + 'static>>
where
F: FnOnce() -> R + UnwindSafe,
{
#[expect(tail_expr_drop_order, reason = "")]
unwind2::catch_unwind(f).inspect_err(|_| {
panic_count::decrease(); // decrease the panic count, since we caught it
})
Expand Down Expand Up @@ -76,7 +75,7 @@ fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {

let backtrace = Backtrace::<MAX_BACKTRACE_FRAMES>::capture().unwrap();
tracing::error!("{backtrace}");

if backtrace.frames_omitted > 0 {
let total_frames = backtrace.frames.len() + backtrace.frames_omitted;
let omitted_frames = backtrace.frames_omitted;
Expand All @@ -93,6 +92,7 @@ fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
arch::abort("cpu caused non-unwinding panic. aborting.");
}

#[expect(tail_expr_drop_order, reason = "")]
rust_panic(construct_panic_payload(info))
})
}
Expand Down Expand Up @@ -127,7 +127,7 @@ fn construct_panic_payload(info: &core::panic::PanicInfo) -> Box<dyn Any + Send>
// Lazily, the first time this gets called, run the actual string formatting.
self.string.get_or_insert_with(|| {
let mut s = String::new();
let mut fmt = fmt::Formatter::new(&mut s, fmt::FormattingOptions::new());
let mut fmt = fmt::Formatter::new(&mut s);
let _err = fmt::Display::fmt(&inner, &mut fmt);
s
})
Expand Down

0 comments on commit 9eaff41

Please sign in to comment.