You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to write a data-structure such that it is generic over different dimensionality.
The beginning is:
/// A field of adjacent sections in a given dimensionality./// With 1, you have `|left|center|right|`./// With 2 dimensions you have:/// ```/// up_left│ up│up_right/// ─────────┼──────┼──────────/// left│center│right/// ─────────┼──────┼──────────/// down_left│ down│down_right/// ```/// Etc.#[derive(Debug)]structAdjacents<T,constD:u32>([T;size(D)])constfnsize(d:u32) -> usize{3u32.pow(d)asusize}
When trying to write implementations like:
impl<T>Adjacents<T,1u32>{/*...*/}
I'm encountering the severe warning (in a few instances):
warning: cannot use constants which depend on generic parameters in types
--> src/main.rs:26:9
|
26 | impl<T> Adjacents<T,1u32> {
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note:for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
In my use case certain functionality can be generic across the stored data type (T) but not generic across dimensionality (D), so it seems only inevitable I must use Adjacents<T,1u32> throughout.
Given D does not depend on T, I would not expect such a warning to arise.
error: generic parameters may not be used in const operations
--> src/lib.rs:2:44
|
2 | struct Adjacents<T, const D: u32>([T; size(D)]);
| ^ cannot perform const operation using `D`
|
= help: const parameters may only be used as standalone arguments, i.e. `D`
Current output on nightly:
error: generic parameters may not be used in const operations
--> src/lib.rs:2:44
|
2 | struct Adjacents<T, const D: u32>([T; size(D)]);
| ^ cannot perform const operation using `D`
|
= help: const parameters may only be used as standalone arguments, i.e. `D`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
My original stack overflow post on the issue.
Rust Playground
I was trying to write a data-structure such that it is generic over different dimensionality.
The beginning is:
When trying to write implementations like:
I'm encountering the severe warning (in a few instances):
In my use case certain functionality can be generic across the stored data type (T) but not generic across dimensionality (D), so it seems only inevitable I must use Adjacents<T,1u32> throughout.
Given
D
does not depend onT
, I would not expect such a warning to arise.Meta
rustc --version --verbose
:Backtrace
Since this is not technically an error I have not included a backtrace.
The text was updated successfully, but these errors were encountered: