Skip to content

Commit b09db8b

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,24 @@ fn main() {
5757
assert_eq!(result, 20);
5858
}
5959
```
60+
61+
## Inclusive ranges
62+
63+
Previously, when a range (`..` or `...`) was used as an expression, it had to be
64+
`..`, which is exclusive of the upper bound, while patterns had to use `...`,
65+
which is inclusive of the upper bound. Now, `..=` is accepted as syntax for
66+
inclusive ranges in both expression and range context:
67+
68+
```rust
69+
fn main() {
70+
for i in 0 ..= 10 {
71+
match i {
72+
0 ..= 5 => println!("{}: low", i),
73+
6 ..= 10 => println!("{}: high", i),
74+
}
75+
}
76+
}
77+
```
78+
79+
The `...` syntax is still accepted in matches, but it is not accepted in
80+
expressions. `..=` should be preferred.

0 commit comments

Comments
 (0)