Skip to content

Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression#155698

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
fmease:no-struct-pat-tuple-index-shorthand
Apr 24, 2026
Merged

Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression#155698
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
fmease:no-struct-pat-tuple-index-shorthand

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented Apr 23, 2026

Split out of PR #154492. This fixes a correctness regression introduced in PR #81235 from 2021. Crater was run in my other PR and didn't report any real regressions (#154492 (comment)); a rerun has been issued for a few spurious builds (#154492 (comment)) but I'm certain it won't find anything either.

This is a theoretical breaking change that doesn't need any T-lang input IMHO since it's such a minute, niche and crystal clear bug that's not worth bothering them with (such a decision is not unprecedented). I'm adding it to the compatibility section of the release notes as is customary.

The Reference doesn't need updating since it didn't adopt this bug and thus accurately describes this part of the grammar as it used to be before 2021-02-23 and as it's meant to be.

The majority of the diff is doc comment additions & necessary UI test restructurings.

@fmease fmease added the relnotes Marks issues that should be documented in the release notes of the next release. label Apr 23, 2026
@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 Apr 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 23, 2026

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

let mutability = self.parse_mutability();
let by_ref = self.parse_byref();

let fieldname = self.parse_field_name()?;
Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

This was the culprit.

Prior to the regressing PR #81235 this used to be let fieldname = self.parse_ident()?;.

Changing it (back) to parse_ident_common makes it consistent again with its expression counterpart, cf:

let ident = this.parse_ident_common(false)?;

View changes since the review

Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

Merged into tests/ui/parser/struct-expr-pat-tuple-index-shorthand.rs.

This test exercises struct expressions while the new struct-expr-pat-tuple-index-shorthand.rs tests both expressions and patterns to make it less likely that they accidentally diverge again.

View changes since the review

Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

Split into

  1. tests/ui/structs/struct-pat-unmentioned-tuple-indices.rs
    • the if let E::S { 0: a } = x { //~ ERROR: pattern does not mention field `1` part to be precise
  2. tests/ui/tuple/tuple-variant-written-as-empty-struct-variant.rs
    • the S { } => {} //~ ERROR: tuple variant `S` written as struct variant [E0769] part to be precise

The third test case, E::S { 0, 1 } => {} // //~^ ERROR tuple variant `E::S` written as struct variant [E0769] is superseded by the test case in tests/ui/parser/struct-expr-pat-tuple-index-shorthand.rs since that snippet is now a syntax error again and no longer a semantic error.

View changes since the review

@fmease fmease force-pushed the no-struct-pat-tuple-index-shorthand branch from e72ed63 to e778b9b Compare April 23, 2026 20:16
@mu001999
Copy link
Copy Markdown
Member

mu001999 commented Apr 24, 2026

LGTM!

@bors r+ rollup=always

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 24, 2026

📌 Commit 07d015e has been approved by mu001999

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 Apr 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 24, 2026
Rollup of 9 pull requests

Successful merges:

 - #155684 (Generalize IO Traits for `Arc<T>` where `&T: IoTrait`)
 - #155081 (Move and clean up some ui test)
 - #155379 (Avoid query cycles in DataflowConstProp)
 - #155663 (Eliminate `CrateMetadataRef`.)
 - #155669 (Add `Sender` diagnostic item for `std::sync::mpsc::Sender`)
 - #155698 (Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression)
 - #155703 (Remove myself as a maintainer of `wasm32-wasip1-threads`)
 - #155706 (Remove `AttributeLintKind` variants - part 7)
 - #155712 (Forbid `*-pass` and `*-fail` directives in tests/crashes)
@rust-bors rust-bors Bot merged commit 1230f74 into rust-lang:main Apr 24, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 24, 2026
rust-timer added a commit that referenced this pull request Apr 24, 2026
Rollup merge of #155698 - fmease:no-struct-pat-tuple-index-shorthand, r=mu001999

Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression

Split out of PR #154492. This fixes a correctness regression introduced in PR #81235 from 2021. Crater was run in my other PR and didn't report any real regressions (#154492 (comment)); a rerun has been issued for a few spurious builds (#154492 (comment)) but I'm certain it won't find anything either.

This is a theoretical breaking change that doesn't need any T-lang input IMHO since it's such a minute, niche and crystal clear bug that's not worth bothering them with (such a decision is not unprecedented). I'm adding it to the compatibility section of the release notes as is customary.

The Reference doesn't need updating since it didn't adopt this bug and thus accurately describes this part of the grammar as it used to be before 2021-02-23 and as it's meant to be.

The majority of the diff is doc comment additions & necessary UI test restructurings.
@fmease fmease deleted the no-struct-pat-tuple-index-shorthand branch April 24, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes Marks issues that should be documented in the release notes of the next release. 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.

3 participants