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

range notation with for expression for i in 0 .. n {} should be parsed as for i in (0 .. n) {} #20921

Closed
mandel59 opened this issue Jan 11, 2015 · 2 comments

Comments

@mandel59
Copy link

The problem is that for i in 0 .. n {} is ambiguous between for i in (0 .. n) {} and for i in 0 .. (n {}) for consistency.

fn main() {
    let n = 10;

    for i in 0..n {
        println!("{}", i);
    }
}

This code yields:

% rustc ambiguous.rs
ambiguous.rs:5:16: 5:17 error: expected `:`, found `!`
ambiguous.rs:5         println!("{}", i);
                              ^

While these codes pass:

fn main() {
    for i in 0..10 {
        println!("{}", i);
    }
}
fn main() {
    let mut n = 0..10;
    for i in n {
        println!("{}", i);
    }
}
@mandel59 mandel59 changed the title for i in 0 .. n {} should be parsed as for i in (0 .. n) {} range notation with for expression for i in 0 .. n {} should be parsed as for i in (0 .. n) {} Jan 11, 2015
@csouth3
Copy link
Contributor

csouth3 commented Jan 11, 2015

possibly related to #20811?

@Gankra
Copy link
Contributor

Gankra commented Jan 11, 2015

Particularly nasty dupe of #20811

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