Skip to content

Avoid index panic when flycheck list is empty#22634

Open
UnknownHacker1 wants to merge 1 commit into
rust-lang:masterfrom
UnknownHacker1:fix/21638-flycheck-index-panic
Open

Avoid index panic when flycheck list is empty#22634
UnknownHacker1 wants to merge 1 commit into
rust-lang:masterfrom
UnknownHacker1:fix/21638-flycheck-index-panic

Conversation

@UnknownHacker1

@UnknownHacker1 UnknownHacker1 commented Jun 23, 2026

Copy link
Copy Markdown

Fixes #21638.

The InvocationStrategy::Once path in notification.rs indexed world.flycheck[0] directly. The always!() 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 with first() and skips the restart when there's no handle.

changelog fix Avoid a panic when restarting flycheck with an empty handle list

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
@rustbot

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
@UnknownHacker1 UnknownHacker1 force-pushed the fix/21638-flycheck-index-panic branch from 093862b to 35f4602 Compare June 23, 2026 23:17

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veykril Veykril added this pull request to the merge queue Jun 24, 2026
@@ -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"
);

@bjorn3 bjorn3 Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

@Veykril Veykril removed this pull request from the merge queue due to a manual request Jun 24, 2026
@Veykril

Veykril commented Jun 24, 2026

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

4 participants