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

Suggest use of associated type bounds where possible #12925

Open
joshtriplett opened this issue Jun 13, 2024 · 0 comments · May be fixed by #13738
Open

Suggest use of associated type bounds where possible #12925

joshtriplett opened this issue Jun 13, 2024 · 0 comments · May be fixed by #13738
Assignees
Labels
A-lint Area: New lints

Comments

@joshtriplett
Copy link
Member

What it does

Now that associated type bounds are stabilized, I'd love to have a clippy lint (ideally with machine-applicable fix) that catches cases that could be written using associated type bounds.

This could start with the simplest cases:

  • if a set of bounds contains a trait with an associated type, and has the form T: TraitWithAssoc, <T as TraitWithAssoc>::Assoc: Bound, lint with a suggestion to merge into T: TraitWithAssoc<Assoc: Bound>.
  • if a set of bounds contains a trait with an associated type, and has the form T: TraitWithassoc<Assoc = U>, U: Bound, and U isn't used for anything else, lint with a suggestion to merge into T: TraitWithAssoc<Assoc: Bound> and delete the declaration of U.

Advantage

This simplifies bounds and makes them easier to follow, with less indirection. In some cases it also eliminates the need for the complex <T as TraitWithAssoc>::Assoc syntax.

Drawbacks

No response

Example

fn func<T>(iter: T)
where
    T: Iterator,
    <T as Iterator>::Item: Display,

Could be written as:

fn func<T>(iter: T)
where
    T: Iterator<Item: Display>,
@joshtriplett joshtriplett added the A-lint Area: New lints label Jun 13, 2024
@y21 y21 self-assigned this Nov 17, 2024
@y21 y21 linked a pull request Nov 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants