Skip to content

Perculiar behaviour when parsing 0..<ident> range expressions in for loops #20858

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

Closed
brendanzab opened this issue Jan 10, 2015 · 2 comments
Closed

Comments

@brendanzab
Copy link
Member

fn main() {
    let n = 2;
    for x in 0..n {
        println!("Hello, world!")
    }
}
<anon>:5:16: 5:17 error: expected `:`, found `!`
<anon>:5         println!("Hello, world!")
                        ^

http://is.gd/pOrPMl

Using parentheses fixes the issue: for x in (0..n) {

Interestingly this works:

struct Foo { octaves: usize }

fn main() {
    let foo = Foo { octaves: 2 };
    for x in 0..foo.octaves {
        println!("Hello, world!")
    }
}

http://is.gd/3Rnvx2

This was encountered in noise-rs.

cc. @amaranth @Cifram

@brendanzab brendanzab changed the title Strange error when parsing ..<ident> range expressions in for loops Perculiar behaviour when parsing 0..<ident> range expressions in for loops Jan 10, 2015
@brendanzab
Copy link
Member Author

Ooops, this is probably a dupe of #20830 - I was searching for "range expression" not "range notation".

@huonw
Copy link
Member

huonw commented Jan 10, 2015

Closing as a dupe of #20830, thanks for filing.

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

2 participants