Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespacing inconsistency with type and const parameters #113090

Open
mversic opened this issue Jun 27, 2023 · 1 comment
Open

Namespacing inconsistency with type and const parameters #113090

mversic opened this issue Jun 27, 2023 · 1 comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@mversic
Copy link

mversic commented Jun 27, 2023

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

@mversic mversic added the C-bug Category: This is a bug. label Jun 27, 2023
@mversic
Copy link
Author

mversic commented Jun 27, 2023

related to #112560

@jyn514 jyn514 added T-lang Relevant to the language team, which will review and decide on the PR/issue. A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants