Avoid index panic when flycheck list is empty#22634
Conversation
This comment has been minimized.
This comment has been minimized.
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#21638
093862b to
35f4602
Compare
| @@ -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" | |||
| ); | |||
There was a problem hiding this comment.
Is not having any flycheck handle supposed to be a valid state? If so, shouldn't this always!() be removed? If not, ending up without any flycheck handle is still a separate bug that needs to be fixed rather than just worked around by the change in this PR.
|
The issue is that without a toolchain we fail to discover any project which means we never populate the flychecks. I'd say this fix is fine, the entire state management is so convoluted in r-a that fixing this proper would entail cleaning all of that mess up imo. But yea, we should remove the always assert there then |
|
Sorry for the delay. Removed the always!(), an empty flycheck list is valid (no toolchain means no project, so flychecks stay empty), and the first() guard covers it. Thanks! @Veykril |
Fixes #21638.
The
InvocationStrategy::Oncepath innotification.rsindexedworld.flycheck[0]directly. Thealways!()above it only logs in release builds, so when the flycheck list is empty it fell through and panicked with index out of bounds (the crash in #21638). This guards the access withfirst()and skips the restart when there's no handle.changelog fix Avoid a panic when restarting flycheck with an empty handle list