Skip to content

Commit

Permalink
Document inclusive ranges as a new feature.
Browse files Browse the repository at this point in the history
This provides documentation for rust-lang/rust#28237.
  • Loading branch information
Alexis Hunt committed Mar 16, 2018
1 parent 567bc1d commit 1a25aaa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion second-edition/src/appendix-06-newest-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ fn main() {
}
```


## Nested groups in `use` declarations

If you have a complex module tree with many different submodules and you need
Expand Down Expand Up @@ -91,3 +90,24 @@ use foo::{
#
# fn main() {}
```

## Inclusive ranges

Previously, when a range (`..` or `...`) was used as an expression, it had to be
`..`, which is exclusive of the upper bound, while patterns had to use `...`,
which is inclusive of the upper bound. Now, `..=` is accepted as syntax for
inclusive ranges in both expression and range context:

```rust
fn main() {
for i in 0 ..= 10 {
match i {
0 ..= 5 => println!("{}: low", i),
6 ..= 10 => println!("{}: high", i),
}
}
}
```

The `...` syntax is still accepted in matches, but it is not accepted in
expressions. `..=` should be preferred.

0 comments on commit 1a25aaa

Please sign in to comment.