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

Tracking issue for exclusive range patterns #37854

Open
oli-obk opened this Issue Nov 18, 2016 · 2 comments

Comments

Projects
None yet
5 participants
@oli-obk
Contributor

oli-obk commented Nov 18, 2016

Concerns

  • Conflict with the syntax of slice patterns #23121
  • General concern about the syntax of inclusive/exclusive patterns

History and status

@xftroxgpx

This comment has been minimized.

xftroxgpx commented Jul 30, 2017

Missing warning: unreachable pattern in the case when 1...10 then 1..10 are present in that order. That warning is present in case of 1..12 then 1..11 for example.

Example (playground link):

#![feature(exclusive_range_pattern)]
fn main() {
    let i = 9; //this hits whichever branch is first in the match without warning
    match i {
        1...10 => println!("hit inclusive"),
        1..10 => println!("hit exclusive"),//FIXME: there's no warning here
        // ^ can shuffle the above two, still no warnings.
        1...10 => println!("hit inclusive2"),//this does get warning: unreachable pattern
        1..10 => println!("hit exclusive2"),//this also gets warning: unreachable pattern

        _ => (),
    };

    //expecting a warning like in this:
    match i {
        1..12 => println!("hit 12"),
        1..11 => println!("hit 11"),//warning: unreachable pattern
        _ => (),
    }
}
@derekdreery

This comment has been minimized.

Contributor

derekdreery commented Jun 5, 2018

I've just been saved for the second time by the compiler when I did 1 .. 10, but meant 1 ..= 10. It might be worth considering that the compiler won't catch this error if exclusive ranges are allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment