Skip to content

inline_const is not parsed correctly yet #6848

@PatchMixolydic

Description

@PatchMixolydic

I tried the following code:

#![allow(incomplete_features)]
#![allow(unused)]
#![feature(inline_const)]

#[repr(u8)]
enum Foo {
    Bar,
    Baz,
    Qux
}

fn main() {
    let x = const { Foo::Bar as u8 };
    // 0
    println!("{}", x);

    let bytes = [0, 4, 3];

    // Yes
    match bytes[0] {
        const { Foo::Bar as u8 } => println!("Yes"),
        const { Foo::Baz as u8 } | const { Foo::Qux as u8 } => println!("No!"),
        _ => panic!("not a valid Foo!")
    }
}

rustc (1.50.0-nightly (2225ee1 2020-12-11)) successfully compiles this, producing no warnings. Running the produced binary yields the expected output:

0
Yes

However, rust-analyzer (2020-11-16 (e8c8039), I was not able to install the nightly version) believes that the const blocks are syntax errors:
Diagnostic span on "const" in "let x = const ...": "Syntax Error: expected expression", "Syntax Error: expected SEMICOLON"
Diagnostic span on "const" in match arm "const {Foo::Bar as u8}": "Syntax Error: expected pattern", "Syntax Error: Expected FAT_ARROW"

I understand if this is expected behaviour since inline_const is an incomplete/unstable feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserparser issuesS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions