Skip to content

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

@Centril

Description

@Centril
Contributor
#![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 => {}
  |     ^

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
A-const-genericsArea: const generics (parameters and arguments)
requires-nightlyThis issue requires a nightly compiler in some way.
on Feb 5, 2020
petrochenkov

petrochenkov commented on Feb 5, 2020

@petrochenkov
Contributor

This is strange, fn fresh_binding had an assert for unexpected things in the binding position, and const parameters should be unexpected if nobody explicitly whitelisted them to behave like this.

Centril

Centril commented on Feb 5, 2020

@Centril
ContributorAuthor

The relevant code is in try_resolve_as_non_binding now (moved in #64111). The span_bug!(...) should be hit, but for some reason it seems like DefKind::ConstParam is not being created when calling resolve_ident_in_lexical_scope.

self-assigned this
on Feb 5, 2020
petrochenkov

petrochenkov commented on Mar 14, 2020

@petrochenkov
Contributor

Fixed in #70006.

removed their assignment
on Mar 14, 2020
added a commit that references this issue on Mar 15, 2020
d986a70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @Centril@petrochenkov

      Issue actions

        Const param as `PatKind::Path` interpreted as a binding instead of being rejected · Issue #68853 · rust-lang/rust