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)
I tried this code:
I expected this code to compile, but I got the following error instead:
The
Selftype here just meansi32, so it doesn't actually depend on any generic parameters.In contrast, the following code compiles:
Meta
Reproducible on the playground with version
1.93.0-nightly (2025-11-21 27b076af7e3e7a363975)