mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge pull request #19719 from Veykril/push-nuwnnztxrzyv
chore: Adjust panic context printing
This commit is contained in:
commit
afc7486440
@ -387,10 +387,8 @@ fn relevant_crates(db: &dyn RootQueryDb, file_id: FileId) -> Arc<[Crate]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct DbPanicContext {
|
#[non_exhaustive]
|
||||||
// prevent arbitrary construction
|
pub struct DbPanicContext;
|
||||||
_priv: (),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for DbPanicContext {
|
impl Drop for DbPanicContext {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
@ -404,18 +402,18 @@ impl DbPanicContext {
|
|||||||
fn set_hook() {
|
fn set_hook() {
|
||||||
let default_hook = panic::take_hook();
|
let default_hook = panic::take_hook();
|
||||||
panic::set_hook(Box::new(move |panic_info| {
|
panic::set_hook(Box::new(move |panic_info| {
|
||||||
|
default_hook(panic_info);
|
||||||
|
if let Some(backtrace) = salsa::Backtrace::capture() {
|
||||||
|
eprintln!("{backtrace:#}");
|
||||||
|
}
|
||||||
DbPanicContext::with_ctx(|ctx| {
|
DbPanicContext::with_ctx(|ctx| {
|
||||||
if !ctx.is_empty() {
|
if !ctx.is_empty() {
|
||||||
eprintln!("Panic context:");
|
eprintln!("additional context:");
|
||||||
for frame in ctx.iter() {
|
for (idx, frame) in ctx.iter().enumerate() {
|
||||||
eprintln!("> {frame}\n");
|
eprintln!("{idx:>4}: {frame}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if let Some(backtrace) = salsa::Backtrace::capture() {
|
|
||||||
eprintln!("{backtrace}");
|
|
||||||
}
|
|
||||||
default_hook(panic_info);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +421,7 @@ impl DbPanicContext {
|
|||||||
SET_HOOK.call_once(set_hook);
|
SET_HOOK.call_once(set_hook);
|
||||||
|
|
||||||
Self::with_ctx(|ctx| ctx.push(frame));
|
Self::with_ctx(|ctx| ctx.push(frame));
|
||||||
DbPanicContext { _priv: () }
|
DbPanicContext
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_ctx(f: impl FnOnce(&mut Vec<String>)) {
|
fn with_ctx(f: impl FnOnce(&mut Vec<String>)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user