Skip to content

Commit dfe2bc2

Browse files
author
Alexis Hunt
committed
Document inclusive ranges as a new feature.
This provides documentation for rust-lang/rust#28237.
1 parent 567bc1d commit dfe2bc2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

second-edition/src/appendix-06-newest-features.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ fn main() {
5858
}
5959
```
6060

61-
6261
## Nested groups in `use` declarations
6362

6463
If you have a complex module tree with many different submodules and you need
@@ -91,3 +90,25 @@ use foo::{
9190
#
9291
# fn main() {}
9392
```
93+
94+
## Inclusive ranges
95+
96+
Previously, when a range (`..` or `...`) was used as an expression, it had to be
97+
`..`, which is exclusive of the upper bound, while patterns had to use `...`,
98+
which is inclusive of the upper bound. Now, `..=` is accepted as syntax for
99+
inclusive ranges in both expression and range context:
100+
101+
```rust
102+
fn main() {
103+
for i in 0 ..= 10 {
104+
match i {
105+
0 ..= 5 => println!("{}: low", i),
106+
6 ..= 10 => println!("{}: high", i),
107+
_ => println!("{}: out of range", i),
108+
}
109+
}
110+
}
111+
```
112+
113+
The `...` syntax is still accepted in matches, but it is not accepted in
114+
expressions. `..=` should be preferred.

0 commit comments

Comments
 (0)