Closed
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_patterns
andadvanced_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
Metadata
Metadata
Assignees
Labels
Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFC`#![feature(exclusive_range_pattern)]`Relevant to the language teamThis issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.Marks issues that should be documented in the release notes of the next release.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
slice_patterns
andadvanced_slice_patterns
) #23121..=
inclusive ranges (RFC #1192) -- originally...
#28237ghost commentedon Jul 30, 2017
EDIT: the following is no longer true 12 jan 2019 nightly debug 2018:
Missing
warning: unreachable pattern
in the case when1...10
then1..10
are present in that order. That warning is present in case of1..12
then1..11
for example.Example (playground link):
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-1
183 remaining items