Unnamed repository; edit this file 'description' to name the repository.
Guard against empty flycheck list in once invocation strategy
The InvocationStrategy::Once path indexed world.flycheck[0] directly. The always!() above only logs in release builds, so when the list was empty it fell through and panicked with index out of bounds. Use first() and skip the restart when there is no handle.
Fixes rust-lang/rust-analyzer#21638
| -rw-r--r-- | crates/rust-analyzer/src/handlers/notification.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 09b6794e4f..ddef716c51 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -336,7 +336,9 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool { "should have exactly one flycheck handle when invocation strategy is once" ); let saved_file = vfs_path.as_path().map(ToOwned::to_owned); - world.flycheck[0].restart_workspace(saved_file); + if let Some(flycheck) = world.flycheck.first() { + flycheck.restart_workspace(saved_file); + } Ok(()) }) } |