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

Detected overflow in ranges should suggest inclusive ranges #50641

Closed
porglezomp opened this issue May 11, 2018 · 1 comment
Closed

Detected overflow in ranges should suggest inclusive ranges #50641

porglezomp opened this issue May 11, 2018 · 1 comment

Comments

@porglezomp
Copy link
Contributor

Now that inclusive ranges are stabilized, we have a good way to write (for example) 0..=255u8. Right now compiling:

fn main() {
    for i in 0..256u8 {
        println!("{}", i);
    }
}

will give the error message:

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

I believe it should additionally suggest using 0..=255u8 as a teaching aid.

@varkor
Copy link
Member

varkor commented May 11, 2018

This is a duplicate of #47213.

@oli-obk oli-obk closed this as completed May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants