Code
struct Foo<const N: usize>;
impl<const N: usize> Foo<N> {
fn get_n_plus_one() -> usize {
const M: usize = N + 1;
M
}
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0401]: can't use generic parameters from outer item
--> src/lib.rs:5:26
|
3 | impl<const N: usize> Foo<N> {
| - const parameter from outer item
4 | fn get_n_plus_one() -> usize {
5 | const M: usize = N + 1;
| ^ use of generic parameter from outer item
|
= note: a `const` is a separate item from the item that contains it
Desired output
Compiling playground v0.0.1 (/playground)
error[E0401]: can't use generic parameters from outer item
--> src/lib.rs:5:26
|
3 | impl<const N: usize> Foo<N> {
| - const parameter from outer item
4 | fn get_n_plus_one() -> usize {
5 | const M: usize = N + 1;
| ^ use of generic parameter from outer item
|
= note: a `const` is a separate item from the item that contains it
help: associated constants and let statements can use const paramaters, consider using one of those.
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.84.0-nightly (759e07f06 2024-10-30)
binary: rustc
commit-hash: 759e07f063fb8e6306ff1bdaeb70af56a878b415
commit-date: 2024-10-30
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
No response
Other cases
Rust Version
Anything else?
No response