Skip to content

Conversation

@lukasoyen
Copy link
Contributor

@lukasoyen lukasoyen commented Jan 15, 2026

After #18043 introduced per-package flycheck for JSON projects, the code assumed that world.flycheck indices matched world.workspaces indices. However, not all workspaces have flycheck enabled (e.g., JSON projects without a flycheck template configured), so the flycheck vector can be shorter than the workspaces vector.

This caused an index-out-of-bounds panic when saving a file in a JSON project without flycheck configured:

thread 'Worker' panicked at notification.rs:
index out of bounds: the len is 0 but the index is 0

Fix by looking up the flycheck handle by its ID (which is the workspace index set during spawn) rather than using the workspace index directly as a vector index.

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

This comment has been minimized.

After a recent introduction of per-package flycheck for JSON projects, the code
assumed that `world.flycheck` indices matched `world.workspaces` indices.
However, not all workspaces have flycheck enabled (e.g., JSON projects
without a flycheck template configured), so the flycheck vector can be
shorter than the workspaces vector.

This caused an index-out-of-bounds panic when saving a file in a JSON
project without flycheck configured:

  thread 'Worker' panicked at notification.rs:
  index out of bounds: the len is 0 but the index is 0

Fix by looking up the flycheck handle by its ID (which is the workspace
index set during spawn) rather than using the workspace index directly
as a vector index.
@lukasoyen lukasoyen force-pushed the fix-flycheck-indexing branch from 6896afa to b912eac Compare January 15, 2026 11:56
@lukasoyen
Copy link
Contributor Author

cc @cormacrelf

@cormacrelf
Copy link
Contributor

cormacrelf commented Jan 15, 2026

18043 only added line 396 so this bug pre-dates it. In any case I would also check the use of indices in giving display strings to flychecks but I think that should be fine as it fills in gaps with empty strings.

(Edit: By that I mean, I think you can have cargo projects without flychecks too. So those would have caused errors already.)

Copy link
Member

@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

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

Even if the issue may have pre-existed, I believe the implementation in this PR is more correct. Thanks!

That said, we may want to handle workspace indices more defensively in general.

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Jan 16, 2026
Merged via the queue into rust-lang:master with commit 1cd5183 Jan 16, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 16, 2026
@lukasoyen lukasoyen deleted the fix-flycheck-indexing branch January 16, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants