Repository navigation
Tracking issue for exclusive range patterns #37854
Copy link
Copy link
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-exclusive_range_pattern`#![feature(exclusive_range_pattern)]``#![feature(exclusive_range_pattern)]`T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.
Description
Summary
This feature allows exclusive integer ranges (such as 0..100) in patterns.
fn is_digit(x: u32) -> bool {
match x {
0..10 => true,
10.. => false,
}
}Concerns
Conflict with the syntax of slice patterns Tracking issue for RFC #495 (featuresslice_patternsandadvanced_slice_patterns) #23121- General concern about the syntax of inclusive/exclusive patterns
History and status
- Proposed and implemented in PR exclusive range patterns #35712
- approved provisionally by lang team without an RFC
Reacted by Adelar da Silva Queiróz, Zac Sims, Evgeniy Dushistov, don bright, Lukas Wirth, Philipp Mildenberger, Jacob Pratt, D1mon, Dave Thomas, Parsa and 50 more
Reacted by Akshay, Aron Parker, Slanterns, QuestionDriven and Dumindu Madunuwan
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-exclusive_range_pattern`#![feature(exclusive_range_pattern)]``#![feature(exclusive_range_pattern)]`T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.
Activity
richard-uk1 commentedon Jun 5, 2018
I've just been saved for the second time by the compiler when I did
1 .. 10, but meant1 ..= 10. It might be worth considering that the compiler won't catch this error if exclusive ranges are allowed.Print battery level
donbright commentedon Jan 12, 2019
seems like exclusive range match would help to improve consistency ... why can i do range in a loop but not in a pattern?
also note that the following is not possible currently because the -1 will break the compile with "expected one of
::,=>,if, or|here"thank you
add #![feature(exclusive_range_pattern)]
kentfredric commentedon Jun 26, 2019
@donbright I know its a poor consolation, but a good workaround which ensures backwards compatibility might be:
playground
Figured this suggestion might help some poor soul who came here and also battled with not being allowed to use
0..=MAXN-1bcantrill commentedon Jan 16, 2020
It doesn't sound like much is going to happen on this issue, but (FWIW) I would argue against its inclusion in stable Rust: exclusive ranges on pattern matching makes it very easy to introduce bugs, as exclusive ranges are very rarely what the programmer wants in a pattern match (emphasis on match!). In these cases, I would argue that having the programmer be explicit is helpful; there is no reason to offer syntactic sugar in this case. (I landed here because of finding several bugs in a project that had turned this feature on; see tock/tock#1544 for details.)
Rollup merge of rust-lang#67712 - Centril:stabilize-slice_patterns, r…
Rollup merge of rust-lang#67712 - Centril:stabilize-slice_patterns, r…
131 remaining items
MultisampledNight commentedon Apr 15, 2024
I most professionally forgot about this xD. A bit busy right now, I'll try to come back to this in a few weeks.
Rollup merge of rust-lang#124459 - RossSmyth:stable_range, r=davidtwco
Auto merge of rust-lang#124459 - RossSmyth:stable_range, r=davidtwco
Nadrieril commentedon May 5, 2024
#124459 is merged, the feature is now stabilized! 🎉 Rust 1.80.0 will support exclusive integer ranges in patterns.
Thank you to everyone who participated in any way over the 8 years since this feature started.
@rustbot label +relnotes
Rollup merge of rust-lang#124749 - RossSmyth:stable_range, r=davidtwco
Unrolled build for rust-lang#124749
Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwco
Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwco
Fix compile error when compiling with rust 1.79.0 or earlier
patterns: include new exclusive range patterns
Update ruzstd from 0.7 to 0.8
Update ruzstd from 0.7 to 0.8