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

Misleading suggestion to add bound to type alias parameter #125789

Open
johannesherschel opened this issue May 30, 2024 · 1 comment · May be fixed by #126575
Open

Misleading suggestion to add bound to type alias parameter #125789

johannesherschel opened this issue May 30, 2024 · 1 comment · May be fixed by #126575
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@johannesherschel
Copy link

Code

trait Trait {
    type Assoc;
}

type AssocOf<T> = T::Assoc;

Current output

error[E0220]: associated type `Assoc` not found for `T`
 --> lib.rs:5:22
  |
5 | type AssocOf<T> = T::Assoc;
  |                      ^^^^^ there is an associated type `Assoc` in the trait `Trait`
  |
help: consider restricting type parameter `T`
  |
5 | type AssocOf<T: Trait> = T::Assoc;
  |               +++++++

Desired output

suggestion to use type AssocOf<T> = <T as Trait>::Assoc;

Rationale and extra context

Restricting T as suggested causes a warning about the bound being ignored, including the correct suggestion to write <T as Trait>::Assoc. If I understand #112792 correctly, type alias bounds will be supported eventually, but right now the suggestion is misleading.

Other cases

No response

Rust Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Anything else?

No response

@johannesherschel johannesherschel added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 30, 2024
@compiler-errors
Copy link
Member

cc @fmease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

3 participants