Skip to content

Commit 56fde6e

Browse files
committed
Auto merge of rust-lang#18065 - Veykril:catchy-diagnostics, r=Veykril
fix: Catch panics from diagnostics computation
2 parents ecd835d + 7e5a0e5 commit 56fde6e

File tree

1 file changed

+23
-12
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src

1 file changed

+23
-12
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::{
55
fmt,
66
ops::Div as _,
7+
panic::AssertUnwindSafe,
78
time::{Duration, Instant},
89
};
910

@@ -552,23 +553,33 @@ impl GlobalState {
552553
let fetch_semantic =
553554
self.vfs_done && self.fetch_workspaces_queue.last_op_result().is_some();
554555
move |sender| {
555-
let diags = fetch_native_diagnostics(
556-
&snapshot,
557-
subscriptions.clone(),
558-
slice.clone(),
559-
NativeDiagnosticsFetchKind::Syntax,
560-
);
556+
// We aren't observing the semantics token cache here
557+
let snapshot = AssertUnwindSafe(&snapshot);
558+
let Ok(diags) = std::panic::catch_unwind(|| {
559+
fetch_native_diagnostics(
560+
&snapshot,
561+
subscriptions.clone(),
562+
slice.clone(),
563+
NativeDiagnosticsFetchKind::Syntax,
564+
)
565+
}) else {
566+
return;
567+
};
561568
sender
562569
.send(Task::Diagnostics(DiagnosticsTaskKind::Syntax(generation, diags)))
563570
.unwrap();
564571

565572
if fetch_semantic {
566-
let diags = fetch_native_diagnostics(
567-
&snapshot,
568-
subscriptions,
569-
slice,
570-
NativeDiagnosticsFetchKind::Semantic,
571-
);
573+
let Ok(diags) = std::panic::catch_unwind(|| {
574+
fetch_native_diagnostics(
575+
&snapshot,
576+
subscriptions.clone(),
577+
slice.clone(),
578+
NativeDiagnosticsFetchKind::Semantic,
579+
)
580+
}) else {
581+
return;
582+
};
572583
sender
573584
.send(Task::Diagnostics(DiagnosticsTaskKind::Semantic(
574585
generation, diags,

0 commit comments

Comments
 (0)