Comma in indexing expression produces incorrect error location and suggestion to add a semicolon
Open
@hu-jeff is already working on this.
Since Aug 15, 2026.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn example() {
(foo[
bar
.baz(),
])
}
Current output
error: expected `;`, found `[`
--> src/lib.rs:2:9
|
2 | (foo[
| ^
|
help: consider adding `;` here
|
2 | (foo;[
| +
Desired output
error: expected `]`, found `,`
|
4 | .baz(),
| ^
Rationale and extra context
The existing error message points to the wrong line, and suggests that a semicolon could help, when in fact it would make things worse.
Other cases
This problem is sensitive to line breaks — it does not happen if the extra comma is on the same line as foo.
Rust Version
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: aarch64-apple-darwin
release: 1.97.1
LLVM version: 22.1.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.