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

Name resolution does not work if associated type and constant use the same name #44247

Closed
matklad opened this issue Sep 1, 2017 · 0 comments
Closed
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matklad
Copy link
Member

matklad commented Sep 1, 2017

Consider this program:

trait T {
    type X;
    const X: Self::X;
}
fn foo<X: T>() {
    let _: X::X = X::X;
}

I believe it should compile OK, but currently (Rust 1.20) it fails to compile with a wrong error message:

Error
   Compiling example_project v0.1.0 (file:///home/matklad/projects/intellij-rust/exampleProject)
error[E0599]: no associated item named `X` found for type `X` in the current scope
 --> src/main.rs:6:19
  |
6 |     let _: X::X = X::X;
  |                   ^^^^
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: candidate #1 is defined in the trait `T`
 --> src/main.rs:2:5
  |
2 |     type X;
  |     ^^^^^^^
  = help: to disambiguate the method call, write `T::X(...)` instead
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `X`, perhaps you need to implement it:
          candidate #1: `T`

error: aborting due to previous error

error: Could not compile `example_project`.

To learn more, run the command again with --verbose.

For comparison, the following program builds just fine:

mod X {
    pub type X = i32;
    pub const X: self::X = 0;
}
fn foo() {
    let _: X::X = X::X;
}
@shepmaster shepmaster added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2017
bors added a commit that referenced this issue Oct 16, 2017
…trochenkov

Check namespaces when resolving associated items in typeck

Closes #35600
Closes #44247
Fixes a "cannot move a value of type..." error in the same case as #44247 but with the associated items swapped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants