Skip to content

Const param as PatKind::Path interpreted as a binding instead of being rejected #68853

Closed
@Centril

Description

@Centril
#![feature(const_generics)]

fn take_const_param<const N: usize>() {
    match 1 {
        N => {},
        _ => {},
    }
}

fn main() {
    take_const_param::<0>();
    take_const_param::<1>()
}

results in:

warning: unreachable pattern
 --> src/main.rs:6:9
  |
5 |         N => {},
  |         - matches any value
6 |         _ => {},
  |         ^ unreachable pattern
  |
  = note: `#[warn(unreachable_patterns)]` on by default

warning: unused variable: `N`
 --> src/main.rs:5:9
  |
5 |         N => {},
  |         ^ help: consider prefixing with an underscore: `_N`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: variable `N` should have a snake case name
 --> src/main.rs:5:9
  |
5 |         N => {},
  |         ^ help: convert the identifier to snake case: `n`
  |
  = note: `#[warn(non_snake_case)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.64s
     Running `target/debug/playground`

but should, similarly to associated constants, result in:

error[E0158]: const parameters cannot be referenced in patterns
 --> src/lib.rs:L:C
  |
L |     N => {}
  |     ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions