[Nightly] Traits generic const expressions and slice size
⚓ Rust 📅 2025-09-20 👤 surdeus 👁️ 9Hello everyone,
We are dealing with generic traits and generic const expressions and the interchange among different implementations of that trait with different generics.
There is a Happy trait that is implemented to a zst crate::Origin and a module abroad with abroad::Origin; in abroad module besides Origin there is the Foreign struct that do also implement Happy<abroad::Origin>. We are to implement at crate scope
impl <A: Happy<abroad::Origin>> Happy<crate::Origin> for A
Here is the code with intended behavior commented out (66-67):
By uncommenting leads to:
Compiling playground v0.0.1 (/playground)
error: unconstrained generic constant
--> src/main.rs:66:73
|
66 | let recall = <Self as crate::Happy<abroad::Origin>>::tale_bytes(&self);
| -------------------------------------------------- ^^^^^
| |
| required by a bound introduced by this call
|
note: required by a bound in `Happy::tale_bytes`
--> src/main.rs:8:34
|
8 | fn tale_bytes(&self) -> [u8; <Self as Happy<Origin>>::TALE_SIZE] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Happy::tale_bytes`
help: try adding a `where` bound
|
64 | fn tale_bytes(&self) -> [u8; <Self as crate::Happy<Origin>>::TALE_SIZE] where [(); <Self as Happy<Origin>>::TALE_SIZE]: {
| +++++++++++++++++++++++++++++++++++++++++++++++
error: unconstrained generic constant
--> src/main.rs:66:22
|
66 | let recall = <Self as crate::Happy<abroad::Origin>>::tale_bytes(&self);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try adding a `where` bound
|
64 | fn tale_bytes(&self) -> [u8; <Self as crate::Happy<Origin>>::TALE_SIZE] where [(); <Self as Happy<Origin>>::TALE_SIZE]: {
| +++++++++++++++++++++++++++++++++++++++++++++++
error: could not compile `playground` (bin "playground") due to 2 previous errors
by following the compile it leads me to:
Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when building an abstract representation for `<impl at src/main.rs:58:1: 60:55>::{constant#0}`
--> src/main.rs:60:11
|
60 | [(); <Self as crate::Happy<Origin>>::TALE_SIZE]:,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires building THIR for `<impl at src/main.rs:58:1: 60:55>::{constant#0}`...
--> src/main.rs:60:11
|
60 | [(); <Self as crate::Happy<Origin>>::TALE_SIZE]:,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `<impl at src/main.rs:58:1: 60:55>::{constant#0}`...
--> src/main.rs:60:11
|
60 | [(); <Self as crate::Happy<Origin>>::TALE_SIZE]:,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which again requires building an abstract representation for `<impl at src/main.rs:58:1: 60:55>::{constant#0}`, completing the cycle
note: cycle used when type-checking `<impl at src/main.rs:58:1: 60:55>::tale_bytes::{constant#0}`
--> src/main.rs:64:34
|
64 | fn tale_bytes(&self) -> [u8; <Self as crate::Happy<Origin>>::TALE_SIZE] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (bin "playground") due to 1 previous error
1 post - 1 participant
🏷️ Rust_feed