-
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.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`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
Successor of #61935 and #61383.
This code:
#![feature(const_generics)]
trait Foo {}
impl<const N: usize> Foo for [(); N]
where
Self:FooImpl<{N==0}>
{}
trait FooImpl<const IS_ZERO: bool>{}
impl FooImpl<{0u8==0u8}> for [();0] {}
impl<const N:usize> FooImpl<{0u8!=0u8}> for [();N] {}
fn foo<T: Foo>(v: T) {}
fn main() {
foo([]);
foo([()]);
}
Gives this error message (on nightly):
error: constant expression depends on a generic parameter
--> src/main.rs:6:10
|
6 | Self:FooImpl<{N==0}>
| ^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
It'd be great if this could work so that you can implement a trait differently for different values of type parameters.
cc @lcnr who suggested to open a new issue for this.
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.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`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.