Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Centril opened this issue Feb 5, 2020 · 3 comments · Fixed by #70006
Closed

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

Centril opened this issue Feb 5, 2020 · 3 comments · Fixed by #70006
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Feb 5, 2020

#![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 => {}
  |     ^
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-const-generics Area: const generics (parameters and arguments) requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Feb 5, 2020
@petrochenkov
Copy link
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
Copy link
Contributor Author

Centril commented Feb 5, 2020

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.

@petrochenkov
Copy link
Contributor

Fixed in #70006.

@petrochenkov petrochenkov removed their assignment Mar 14, 2020
@bors bors closed this as completed in d986a70 Mar 15, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants