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

Bug with associated type discovery #95413

Closed
tema3210 opened this issue Mar 28, 2022 · 1 comment · Fixed by #96353
Closed

Bug with associated type discovery #95413

tema3210 opened this issue Mar 28, 2022 · 1 comment · Fixed by #96353
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tema3210
Copy link

I tried this code playground

I expected to see this happen: resolve associated types and compile

Instead, this happened: visibility error with strange, broken suggestions

@tema3210 tema3210 added the C-bug Category: This is a bug. label Mar 28, 2022
@SNCPlay42
Copy link
Contributor

Reduced some:

mod A {
    pub trait Trait {}
}

mod B {
    struct A<H: A::Trait>(H);
}

Which emits (ignoring the extra suggestion from a crate visible to the playground):

error[E0405]: cannot find trait `Trait` in `A`
 --> src/lib.rs:6:20
  |
6 |     struct A<H: A::Trait>(H);
  |                    ^^^^^ not found in `A`
  |
help: consider importing one of these items
  |
6 |     use crate::A::Trait;
  |

The error is correct - in mod B A refers to struct A itself, which has no associated item called Trait.

The suggestion is invalid - whether Trait is imported in the current module has no effect on the path A::Trait.

(Note that the playground's click-to-insert-use-statement feature also inserts the suggestion in the wrong position - at the top of the file instead of in mod B - which isn't a compiler issue.)

@rustbot label A-diagnostics A-resolve A-associated-items D-confusing D-invalid-suggestion

@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Mar 28, 2022
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 29, 2022
@estebank estebank self-assigned this Apr 23, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue May 3, 2022
…rors

When suggesting to import an item, also suggest changing the path if appropriate

When we don't find an item we search all of them for an appropriate
import and suggest `use`ing it. This is sometimes done for expressions
that have paths with more than one segment. We now also suggest changing
that path to work with the `use`.

Fix rust-lang#95413
bors added a commit to rust-lang-ci/rust that referenced this issue May 4, 2022
When suggesting to import an item, also suggest changing the path if appropriate

When we don't find an item we search all of them for an appropriate
import and suggest `use`ing it. This is sometimes done for expressions
that have paths with more than one segment. We now also suggest changing
that path to work with the `use`.

Fix rust-lang#95413
@bors bors closed this as completed in 5796726 May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants