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

Syntax error when using const + exclusive range pattern syntax #13955

Closed
clarfonthey opened this issue Jan 14, 2023 · 1 comment · Fixed by #14580
Closed

Syntax error when using const + exclusive range pattern syntax #13955

clarfonthey opened this issue Jan 14, 2023 · 1 comment · Fixed by #14580
Labels
A-parser parser issues C-bug Category: bug

Comments

@clarfonthey
Copy link

clarfonthey commented Jan 14, 2023

rust-analyzer version: rust-analyzer 1 (643bc02de 2023-01-01)

rustc version: rustc 1.68.0-nightly (0b90256ad 2023-01-13)

relevant settings: installed via rustup

Take this snippet: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a2f288d06c1dfcaf8e916a6eca9594cd

#![feature(inline_const_pat)]
#![feature(exclusive_range_pattern)]
pub fn ohno(val: i128) -> Option<i64> {
    match val {
        const { i64::MAX as i128 + 1 }.. => None,
        ..const { i64::MIN as i128 } => None,
        _ => Some(val as i64),
    }
}

This compiles fine on the latest version of rustc, but I'm getting a syntax error in rust-analyzer on this line:

        ..const { i64::MIN as i128 } => None,

The span of the error appears to be the arrow. I'm not sure if there's a succinct command I can run to get the exact error output, but here's what it looks like via kak-lsp:

Syntax errors displayed

(note: the features are applied to the crate, this is just running inside a file in that crate)

@lowr lowr added the A-parser parser issues label Jan 18, 2023
@Veykril Veykril added the C-bug Category: bug label Feb 9, 2023
@fmease
Copy link
Member

fmease commented Apr 2, 2023

I've stumbled upon a similar case where inline const patterns are inside of tuple patterns. It seems like r-a can only parse const patterns at the “top-level” of a pattern.

Minimal reproducer:

fn cmplx_ct_pat() {
    match ((),) {
        (const { () },) => {}
    }
}

Output:

Syntax Error: expected a pattern
Syntax Error: expected R_PAREN
Syntax Error: expected FAT_ARROW
Syntax Error: expected pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser parser issues C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants