Skip to content

Commit

Permalink
panic: Refactor
Browse files Browse the repository at this point in the history
The `unreachable!` previously acted as a safeguard in case the
translation of C's "no return" indicator would not work, ensuring the
code path is not followed any further -- but the linter didn't like the
(currently) unreachable code. Instead, we now implicitly assert that the
panic function does not return by not explicitly having a return in that
branch.
  • Loading branch information
chrysn committed Oct 13, 2023
1 parent 24d8f02 commit 09ce8e6
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,45 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
};
unreachable!()
}

// I *guess* it's OK for a panic to simply make a thread into a zombie -- this does allow other
// threads (including spawned Rust threads) to continue, but my layman's understanding of
// panicking is that that's OK because whatever we were just mutating can simply never be used
// by someone else ever again.
} else {
// I *guess* it's OK for a panic to simply make a thread into a zombie -- this does allow other
// threads (including spawned Rust threads) to continue, but my layman's understanding of
// panicking is that that's OK because whatever we were just mutating can simply never be used
// by someone else ever again.

let me = thread::get_pid();
let me = thread::get_pid();

if cfg!(feature = "panic_handler_format") {
use crate::stdio::println;
if cfg!(feature = "panic_handler_format") {
use crate::stdio::println;

println!(
"Error in thread {:?} ({}):",
me,
me.get_name().unwrap_or("unnamed")
);
println!("{}", info);
} else {
let mut stdio = crate::stdio::Stdio {};
use core::fmt::Write;
let _ = stdio.write_str("Panic in thread ");
let _ = stdio.write_str(me.get_name().unwrap_or("unnamed"));
let _ = stdio.write_str("!\n");
}
println!(
"Error in thread {:?} ({}):",
me,
me.get_name().unwrap_or("unnamed")
);
println!("{}", info);
} else {
let mut stdio = crate::stdio::Stdio {};
use core::fmt::Write;
let _ = stdio.write_str("Panic in thread ");
let _ = stdio.write_str(me.get_name().unwrap_or("unnamed"));
let _ = stdio.write_str("!\n");
}

if cfg!(feature = "panic_handler_crash") {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
if cfg!(feature = "panic_handler_crash") {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
}
}
}

// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
// holds are just held indefinitely rather than throwing poison errors.
loop {
thread::sleep();
// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
// holds are just held indefinitely rather than throwing poison errors.
loop {
thread::sleep();
}
}
}

Expand Down

0 comments on commit 09ce8e6

Please sign in to comment.