Namespacing inconsistency with type and const parameters #113090
Open
Description
I tried this code and it compiled:
trait Trait<T, const N: usize> {
type TYPE;
const TYPE: usize;
}
Then I tried this code and it didn't compile:
trait Trait<T, const T: usize> {
type TYPE;
const TYPE: usize;
}
Meta
rustc +nightly --version --verbose
:
rustc 1.72.0-nightly (36fb58e43 2023-06-26)
binary: rustc
commit-hash: 36fb58e433c782e27dd41034284e157cf86d587f
commit-date: 2023-06-26
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5
Backtrace
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
--> src/main.rs:1:22
|
1 | trait Trait<T, const T: usize> {
| - ^ already used
| |
| first use of `T`
For more information about this error, try `rustc --explain E0403`.
error: could not compile `proba2` (bin "proba2") due to previous error
Explanation
This is an inconsistency in namespacing of type parameters and const parameters. When used as associated types/consts they can have overlapping names, but when used as generic types they cannot
Activity