Skip to content

A problem with inline_const feature in ranges #78108

Closed

Description

@leonardo-m

As soon as I've seen the new inline_const feature, I've tried to find some use cases for it in my code, and I did find only very few of them, unfortunately, and one of the two uses cases could be reduced to this:

#![allow(incomplete_features)]
#![feature(inline_const)]
fn main() {
    const N: u32 = 10;
    let x: u32 = 3;

    match x {
        1 .. const { N - 1 } => {},
        _ => {},
    }
}

That gives errors:

error: expected one of `=>`, `if`, or `|`, found keyword `const`
 --> ...\temp.rs:9:14
  |
9 |         1 .. const { N - 1 } => {},
  |              ^^^^^ expected one of `=>`, `if`, or `|`

error[E0658]: half-open range patterns are unstable
 --> ...\temp.rs:9:9
  |
9 |         1 .. const { N - 1 } => {},
  |         ^^^^
  |
  = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
  = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable

So I am not sure if this is a bug report or an enhancement request.

Activity

  1. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    A-parserArea: The lexing & parsing of Rust source code to an AST
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 19, 2020
  2. added
    F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)
    and removed
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Oct 19, 2020
  3. camelid commented on Oct 19, 2020

    @camelid
    Member

    Note that this does work in expressions (playground):

    #![allow(incomplete_features)]
    #![feature(inline_const)]
    fn main() {
        const N: u32 = 10;
    
        let range = 1 .. const { N - 1 };
        println!("{:?}", range);
    }
  4. self-assigned this
    on Oct 19, 2020
  5. petrochenkov commented on Oct 19, 2020

    @petrochenkov
    Contributor

    Support for ranges in patterns (1 .. const { 2 } or const { 1 } .. 2) needs to be added separately, to fn parse_pat_range_end and fn parse_pat_with_range_pat respectively.

  6. spastorino commented on Oct 19, 2020

    @spastorino
    Member

    Ohh I've just realized that we had this issue opened, I've fixed this in #78116.

    Going to adjust description of the PR accordingly so it closes this issue when merged.

  7. added a commit that references this issue on Oct 22, 2020
    84f1f54
  8. added a commit that references this issue on Oct 23, 2020
    982c4b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions