diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-04-30 07:11:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-30 07:11:04 +0000 |
| commit | 624572e5e12d0782a09cbab7fab56e801eba4394 (patch) | |
| tree | 5597d32c47089b6606e5c2948088896529a5d1bc | |
| parent | fedec9b79d74e7a9f755cc78dc93511b4d07c4b4 (diff) | |
| parent | 1b677ce14ff759dacadd5d4b05dd27a00bfd68c2 (diff) | |
| download | rust-624572e5e12d0782a09cbab7fab56e801eba4394.tar.gz rust-624572e5e12d0782a09cbab7fab56e801eba4394.zip | |
Merge pull request #19719 from Veykril/push-nuwnnztxrzyv
chore: Adjust panic context printing
| -rw-r--r-- | src/tools/rust-analyzer/crates/base-db/src/lib.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/tools/rust-analyzer/crates/base-db/src/lib.rs b/src/tools/rust-analyzer/crates/base-db/src/lib.rs index f7f4e024ef2..a67fbf75c02 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/lib.rs @@ -387,10 +387,8 @@ fn relevant_crates(db: &dyn RootQueryDb, file_id: FileId) -> Arc<[Crate]> { } #[must_use] -pub struct DbPanicContext { - // prevent arbitrary construction - _priv: (), -} +#[non_exhaustive] +pub struct DbPanicContext; impl Drop for DbPanicContext { fn drop(&mut self) { @@ -404,18 +402,18 @@ impl DbPanicContext { fn set_hook() { let default_hook = panic::take_hook(); 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| { if !ctx.is_empty() { - eprintln!("Panic context:"); - for frame in ctx.iter() { - eprintln!("> {frame}\n"); + eprintln!("additional context:"); + for (idx, frame) in ctx.iter().enumerate() { + 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); Self::with_ctx(|ctx| ctx.push(frame)); - DbPanicContext { _priv: () } + DbPanicContext } fn with_ctx(f: impl FnOnce(&mut Vec<String>)) { |
