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

Fix test now that overflowing_literals is rejected in all editions. #148

Merged
merged 1 commit into from
Feb 28, 2019
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
16 changes: 8 additions & 8 deletions src/rust-2018/data-types/inclusive-ranges.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ three is included in the range. Inclusive ranges are especially useful if you
want to iterate over every possible value in a range. For example, this is a
surprising Rust program:

```rust
```rust,compile_fail
fn takes_u8(x: u8) {
// ...
}
Expand All @@ -38,21 +38,21 @@ fn main() {
}
```

What does this program do? The answer: nothing. The warning we get when
compiling has a hint:
What does this program do? The answer: it fails to compile. The error we get
when compiling has a hint:

```text
warning: literal out of range for u8
error: literal out of range for u8
--> src/main.rs:6:17
|
6 | for i in 0..256 {
| ^^^
|
= note: #[warn(overflowing_literals)] on by default
= note: #[deny(overflowing_literals)] on by default
```

That’s right, since `i` is a `u8`, this overflows, and is the same as writing
`for i in 0..0`, so the loop executes zero times.
That’s right, since `i` is a `u8`, this overflows, and the compiler produces
an error.

We can do this with inclusive ranges, however:

Expand All @@ -69,4 +69,4 @@ fn main() {
}
```

This will produce those 256 lines of output you might have been expecting.
This will produce those 256 lines of output you might have been expecting.