Skip to content

Stop suggesting missing semicolon with multiline indexing - #161207

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
hu-jeff:fix-comma-indexing-expression
Nov 3, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
hu-jeff:fix-comma-indexing-expression

Conversation

@hu-jeff

@hu-jeff hu-jeff commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Making a change so that when the open bracket is on the same line as the thing being indexed, we don't suggest a semicolon. This does change some existing behaviour though:

foo[
  1,
  2]

Before, this example would recommend foo;[ and it will now suggest foo![ which is probably what was intended.

r? @kpreid

Closes #161147

@rustbot

rustbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 17, 2026
@rustbot

rustbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Failed to set assignee to kpreid: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot

rustbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @kpreid (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@kpreid kpreid left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change seems like an improvement to me. I think ideally we would go farther by not making the semicolon suggestion when the expression is parenthesized or otherwise cannot be replaced by two statements, but that’s more work.

r? compiler

View changes since this review

Comment thread compiler/rustc_parse/src/parser/expr.rs Resolved
@fmease
fmease force-pushed the fix-comma-indexing-expression branch from 56927f3 to 1971ad0 Compare November 2, 2026 19:16

@fmease fmease 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.

Thanks, that's definitely an improvement!

I'm not a fan of this (preexisting) diagnostic / error recovery since it's so assertive despite having so many false positives.

This change seems like an improvement to me. I think ideally we would go farther by not making the semicolon suggestion when the expression is parenthesized or otherwise cannot be replaced by two statements, but that’s more work.

Agreed. I've pushed some FIXME comments to the branch (plus a bit of cleanup) outlining some of its issues.

@bors rollup
@bors r+ force

View changes since this review

@rust-bors

rust-bors Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1971ad0 has been approved by fmease

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 2, 2026
…ion, r=fmease

Stop suggesting missing semicolon with multiline indexing

Making a change so that when the open bracket is on the same line as the thing being indexed, we don't suggest a semicolon. This does change some existing behaviour though:
```
foo[
  1,
  2]
```
Before, this example would recommend `foo;[` and it will now suggest `foo![` which is probably what was intended.

r? @kpreid

Closes rust-lang#161147
rust-bors Bot pushed a commit that referenced this pull request Nov 3, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #165331 (miri subtree update)
 - #165356 (portable-simd subtree update)
 - #162916 (rustdoc: Improve `ItemKind`)
 - #161035 (Tweak error for stmt macro expansion in expression context)
 - #163762 (Tweak "value not found" error to show more context when items with the same name are found)
 - #164155 (Implement `Vec::retain_unstable` ACP)
 - #164786 (Add regression test for issue 156423)
 - #165103 (add TrySendError::into_inner)
 - #157584 (Misc. `fmt_type` cleanups)
 - #161207 (Stop suggesting missing semicolon with multiline indexing)
 - #162070 (Add regression test for associated const equality param out of range ICE)
 - #162537 (Remove outdated windows-gnu test ignores)
 - #162978 (add regression test for #142717)
 - #163333 (va_arg: force right-adjust on `aarch64_be`)
 - #163377 (Avoid ICE when checking casts from function items)
 - #163399 (Support `cfg_version` in `doc_cfg`)
 - #165015 (Autolabel library modules)
 - #165181 (Implement `Duration::display_seconds`)
 - #165185 (Add codegen test for enumerate index bounds check elimination)
 - #165193 (Do attribute target checking on parameters with the new system)
 - #165292 (DropGuard: remove leading newlines from examples)
@rust-bors
rust-bors Bot merged commit 8fa788c into rust-lang:main Nov 3, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Nov 3, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 3, 2026
Rollup merge of #161207 - hu-jeff:fix-comma-indexing-expression, r=fmease

Stop suggesting missing semicolon with multiline indexing

Making a change so that when the open bracket is on the same line as the thing being indexed, we don't suggest a semicolon. This does change some existing behaviour though:
```
foo[
  1,
  2]
```
Before, this example would recommend `foo;[` and it will now suggest `foo![` which is probably what was intended.

r? @kpreid

Closes #161147
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 4, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - rust-lang/rust#165331 (miri subtree update)
 - rust-lang/rust#165356 (portable-simd subtree update)
 - rust-lang/rust#162916 (rustdoc: Improve `ItemKind`)
 - rust-lang/rust#161035 (Tweak error for stmt macro expansion in expression context)
 - rust-lang/rust#163762 (Tweak "value not found" error to show more context when items with the same name are found)
 - rust-lang/rust#164155 (Implement `Vec::retain_unstable` ACP)
 - rust-lang/rust#164786 (Add regression test for issue 156423)
 - rust-lang/rust#165103 (add TrySendError::into_inner)
 - rust-lang/rust#157584 (Misc. `fmt_type` cleanups)
 - rust-lang/rust#161207 (Stop suggesting missing semicolon with multiline indexing)
 - rust-lang/rust#162070 (Add regression test for associated const equality param out of range ICE)
 - rust-lang/rust#162537 (Remove outdated windows-gnu test ignores)
 - rust-lang/rust#162978 (add regression test for rust-lang/rust#142717)
 - rust-lang/rust#163333 (va_arg: force right-adjust on `aarch64_be`)
 - rust-lang/rust#163377 (Avoid ICE when checking casts from function items)
 - rust-lang/rust#163399 (Support `cfg_version` in `doc_cfg`)
 - rust-lang/rust#165015 (Autolabel library modules)
 - rust-lang/rust#165181 (Implement `Duration::display_seconds`)
 - rust-lang/rust#165185 (Add codegen test for enumerate index bounds check elimination)
 - rust-lang/rust#165193 (Do attribute target checking on parameters with the new system)
 - rust-lang/rust#165292 (DropGuard: remove leading newlines from examples)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comma in indexing expression produces incorrect error location and suggestion to add a semicolon

5 participants