Skip to content

Bug with associated type discovery #95413

Closed

Description

@tema3210

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

Activity

  1. SNCPlay42 commented on Mar 28, 2022

    @SNCPlay42
    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

  2. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
    on Mar 28, 2022
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 29, 2022
  4. self-assigned this
    on Apr 23, 2022
  5. added a commit that references this issue on May 3, 2022
    5796726
  6. added a commit that references this issue on May 3, 2022
    e5e0925
  7. added a commit that references this issue on May 4, 2022
    9add632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler 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