Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document inclusive ranges as a new feature. #1134

Merged
merged 3 commits into from
Mar 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 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,25 @@ 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),
_ => println!("{}: out of range", i),
}
}
}
```

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