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

Interval match patterns won't parse namespace specifiers correctly #21475

Closed
simias opened this issue Jan 21, 2015 · 1 comment
Closed

Interval match patterns won't parse namespace specifiers correctly #21475

simias opened this issue Jan 21, 2015 · 1 comment
Labels
A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@simias
Copy link

simias commented Jan 21, 2015

The following code:

use m::{START, STOP};

fn main() {
    let i = 12u32;

    match i {
        20...30           => println!("ok"),
        START...END       => println!("still ok"),
        m::START...m::END => println!("bad"),
        _                 => (),
    }
}

mod m {
  const START: u32 = 4;
  const END:   u32 = 14;
}

Produces this error:

<anon>:10:17: 10:20 error: expected one of `::`, `=>`, or `|`, found `...`
<anon>:10         m::START...m::END => println!("bad"),
                          ^~~

Putting parens around m::START and m::END doesn't fix it.

@Gankra Gankra added A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Jan 21, 2015
@defuz
Copy link
Contributor

defuz commented Jan 22, 2015

Also, it doesn't work too (Should?):

struct Struct {
    x : u8
}

const C : Struct = Struct { x : 5u8 };

fn main() {
    match 3u8 {
        C.x ... 2u8 => { println!("bad"); }
        2u8 ... C.x => { println!("bad"); }
        _ => {}
    }
}

defuz added a commit to defuz/rust that referenced this issue Feb 28, 2015
defuz added a commit to defuz/rust that referenced this issue Feb 28, 2015
bors added a commit that referenced this issue Feb 28, 2015
Fixing #21475. Right now this code can not be parsed:

```rust
use m::{START, END};

fn main() {
    match 42u32 {
        m::START...m::END => {}, // error: expected one of `::`, `=>`, or `|`, found `...`
        _  => {},
    }
}

mod m {
  pub const START: u32 = 4;
  pub const END:   u32 = 14;
}
```

I fixed the parser and added test for this case, but now there are still problems with mixing literals and paths in interval:

```rust
    match 42u32 {
        0u32...m::END => {},       // mismatched types in range [E0031]
        m::START...59u32 => {},    // mismatched types in range [E0031]
        _  => {},
    }
}
```

I'll try fix this problem and need review.
@bors bors closed this as completed in 52fa187 Feb 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

3 participants