Skip to content

Fix grammar rules pertaining to obsolete range patterns#2259

Open
fmease wants to merge 1 commit intorust-lang:masterfrom
fmease:fix-obs-range-pat-grammars
Open

Fix grammar rules pertaining to obsolete range patterns#2259
fmease wants to merge 1 commit intorust-lang:masterfrom
fmease:fix-obs-range-pat-grammars

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented May 5, 2026

reference@master incorrectly claims that the following patterns are syntactically invalid: &0...0, &mut 0...0. As a matter of fact, rustc specifically continues to accept obsolete range patterns as the "pointee" of reference patterns; it only rejects modern range patterns in this position (e.g., &..1, &0.., &mut 0..1, &&0..=0, &&mut ..=0).

Of course, the fact that pattern &0...1 and expression &0..=1 get interpreted differently wrt. precedence (&(0...1) and (&0)..=1, respectively) has been identified as a bug: rust-lang/rust#48501 (2018).

It's unclear to me if people have run crater back then to see if rejecting patterns like &0...0 would lead to any regressions. In any case, in PR rust-lang/rust#47813 (2018) it was only made an error for modern range patterns.

I don't think I have the time and energy to issue a crater run for this since I've been issuing crater run after crater run as of late. So I don't plan on fixing rust-lang/rust#48501 anytime soon. However, I figured it would make sense to update the Reference. As far as I understand it, the Reference is descriptive rather than prescriptive, so even though this is a bug in rustc, it's worth documenting it IMHO, esp. since it's so old.

Finally, the footnote for ObsoleteRangePattern made it sound like this grammar rule stopped being in effect in Rust 2021 and beyond whilst in reality ... patterns have only become semantically invalid in Rust 2021 and following, not syntactically. So I've clarified it.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 5, 2026
Comment thread src/patterns.md
Copy link
Copy Markdown
Member Author

@fmease fmease May 5, 2026

Choose a reason for hiding this comment

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

I'm fine with reverting the RangeModernRange renaming.

Advantage of the renaming: It prevents confusion that could lead to people repeatedly opening issues and PRs trying to move ObsoleteRangePattern back into RangePattern believing it to be a mistake.

Disadvantage of the renaming: It painfully highlights the fact that there are modern and obsolete range patterns; the latter are no longer hidden at the bottom of RangePattern's definition.

View changes since the review

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

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants