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

"expected pattern" when parsing slice patterns #1479

Closed
estebank opened this issue Jul 3, 2019 · 5 comments · Fixed by #1848
Closed

"expected pattern" when parsing slice patterns #1479

estebank opened this issue Jul 3, 2019 · 5 comments · Fixed by #1848
Labels
E-easy E-has-instructions Issue has some instructions and pointers to code to get started good first issue

Comments

@estebank
Copy link
Contributor

estebank commented Jul 3, 2019

The parser cannot cope with the following code using slice patterns:

if let &[ref start.., ref end] = &variant_spans[..] {
@matklad
Copy link
Member

matklad commented Jul 4, 2019

The relevant code is here:

https://github.com/rust-analyzer/rust-analyzer/blob/4e8664d9d37021e85d72b6228fa45e7edf4a1a74/crates/ra_parser/src/grammar/patterns.rs#L225-L254

Note that comments are executable tests

@matklad matklad added E-easy E-has-instructions Issue has some instructions and pointers to code to get started good first issue labels Jul 4, 2019
tomjakubowski added a commit to tomjakubowski/rust-analyzer that referenced this issue Jul 7, 2019
tomjakubowski added a commit to tomjakubowski/rust-analyzer that referenced this issue Jul 7, 2019
@tomjakubowski
Copy link

tomjakubowski commented Jul 7, 2019

That particular case parses without errors with cargo run --bin ra_cli parse.

fn main() {
    if let &[ref start.., ref end] = &variant_spans[..] {}
}
          LET_KW@[19; 22) "let"
          WHITESPACE@[22; 23) " "
          REF_PAT@[23; 46)
            AMP@[23; 24) "&"
            SLICE_PAT@[24; 46)
              L_BRACK@[24; 25) "["
              RANGE_PAT@[25; 36)
                BIND_PAT@[25; 34)
                  REF_KW@[25; 28) "ref"
                  WHITESPACE@[28; 29) " "
                  NAME@[29; 34)
                    IDENT@[29; 34) "start"
                DOTDOT@[34; 36) ".."
              COMMA@[36; 37) ","
              WHITESPACE@[37; 38) " "
              BIND_PAT@[38; 45)
                REF_KW@[38; 41) "ref"
                WHITESPACE@[41; 42) " "
                NAME@[42; 45)
                  IDENT@[42; 45) "end"
              R_BRACK@[45; 46) "]"
          WHITESPACE@[46; 47) " "

But it's a misparse: the RANGE_PAT is wrong, and should probably match a new SyntaxKind for "subslice patterns".

Another test case produces a RANGE_PAT but this one does error the parser:

fn main() {
    let [a, b..] = [];
}
      LET_STMT@[16; 34)
        LET_KW@[16; 19) "let"
        WHITESPACE@[19; 20) " "
        SLICE_PAT@[20; 28)
          L_BRACK@[20; 21) "["
          BIND_PAT@[21; 22)
            NAME@[21; 22)
              IDENT@[21; 22) "a"
          COMMA@[22; 23) ","
          WHITESPACE@[23; 24) " "
          RANGE_PAT@[24; 28)
            BIND_PAT@[24; 25)
              NAME@[24; 25)
                IDENT@[24; 25) "b"
            DOTDOT@[25; 27) ".."
            ERROR@[27; 28)
              R_BRACK@[27; 28) "]"
        WHITESPACE@[28; 29) " "
        EQ@[29; 30) "="

tomjakubowski added a commit to tomjakubowski/rust-analyzer that referenced this issue Jul 8, 2019
tomjakubowski added a commit to tomjakubowski/rust-analyzer that referenced this issue Jul 15, 2019
@matklad
Copy link
Member

matklad commented Jul 15, 2019

@estebank hm, I am now confused, what ref start.. means exactly? Is it a "subslice pattern" from rust-lang/rfcs#2359? Shouldn't it be spelled s ref start @ .. really soon?

@estebank
Copy link
Contributor Author

I believe you're correct in all your understanding. I don't think the syntax accepted in the RFC has been implemented, so rustc is using the previous syntax I'm showing here. It might be acceptable for rust-analyzer not to support it and skip straight to the finalized syntax, but I wanted to flag it.

@Centril
Copy link
Contributor

Centril commented Jul 28, 2019

The syntax in the RFC was implemented in rust-lang/rust#62550. cc rust-lang/rust#62254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy E-has-instructions Issue has some instructions and pointers to code to get started good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants