- Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.Category: This is a bug.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.T-langRelevant to the language teamRelevant to the language team
Description
I tried this code:
trait MyTrait { fn foo<const N: i32>(); } impl MyTrait for i32 { fn foo<const N: Self>() {} }I expected this code to compile, but I got the following error instead:
error[E0770]: the type of const parameters must not depend on other generic parameters --> src/lib.rs:6:21 | 6 | fn foo<const N: Self>() {} | ^^^^ the type must not depend on the parameter `Self` error[E0053]: associated function `foo` has an incompatible generic parameter for trait `MyTrait` --> src/lib.rs:6:12 | 1 | trait MyTrait { | ------- 2 | fn foo<const N: i32>(); | ------------ expected const parameter of type `i32` ... 5 | impl MyTrait for i32 { | -------------------- 6 | fn foo<const N: Self>() {} | ^^^^^^^^^^^^^ found const parameter of type `{type error}` Some errors have detailed explanations: E0053, E0770. For more information about an error, try `rustc --explain E0053`. The Self type here just means i32, so it doesn't actually depend on any generic parameters.
In contrast, the following code compiles:
trait MyTrait { fn foo() -> i32; } impl MyTrait for i32 { fn foo() -> Self { 1 } }Meta
Reproducible on the playground with version 1.93.0-nightly (2025-11-21 27b076af7e3e7a363975)
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.Category: This is a bug.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.T-langRelevant to the language teamRelevant to the language team