-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
#![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
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
petrochenkov commentedon Feb 5, 2020
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 commentedon Feb 5, 2020
The relevant code is in
try_resolve_as_non_binding
now (moved in #64111). Thespan_bug!(...)
should be hit, but for some reason it seems likeDefKind::ConstParam
is not being created when callingresolve_ident_in_lexical_scope
.petrochenkov commentedon Mar 14, 2020
Fixed in #70006.
Rollup merge of rust-lang#70006 - petrochenkov:fresh, r=Centril