Skip to content

Namespacing inconsistency with type and const parameters #113090

Open
@mversic

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions