Skip to content

Remove duplicate trait bound or where clause #8674

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

Closed
aldhsu opened this issue Apr 10, 2022 · 2 comments
Closed

Remove duplicate trait bound or where clause #8674

aldhsu opened this issue Apr 10, 2022 · 2 comments
Labels
A-lint Area: New lints

Comments

@aldhsu
Copy link
Contributor

aldhsu commented Apr 10, 2022

What it does

This lint warns about repetitions of the same trait in trait bounds or where clauses.

Lint Name

repetition_where_clause_or_trait_bound

Category

pedantic

Advantage

Leaving duplicate trait bounds is less readable.

Drawbacks

None

Example

pub fn foo<T: Copy + Copy>(t: T) {}

Could be written as:

pub fn foo<T: Copy>(t: T) {}

OR

pub fn foo<T>(t: T) where T: Copy + Copy {}

Could be written as:

pub fn foo<T>(t: T) where T: Copy {}
@aldhsu aldhsu added the A-lint Area: New lints label Apr 10, 2022
@aldhsu aldhsu changed the title Remove duplicate trait bound Remove duplicate trait bound or where clause Apr 10, 2022
@aldhsu
Copy link
Contributor Author

aldhsu commented Apr 10, 2022

I saw there is an existing lint that compares where clauses and trait bounds for duplicates. This could be an extension of that lint.

bors added a commit that referenced this issue Jul 12, 2022
…, r=flip1995

Add `repeated_where_clause_or_trait_bound` lint

I thought I would try and scratch my own itch for #8674.

1. Is comparing the `Res` the correct way for ensuring we have the same trait?
2. Is there a way to get the spans for the bounds and clauses for suggestions?
I tried to use `GenericParam::bounds_span_for_suggestions` but it only gave me an empty span at the end of the spans.
I tried `WhereClause::span_for_predicates_or_empty_place` and it included the comma.
3. Is there a simpler way to get the trait names? I have used the spans of the traits because I didn't see a way to get it off the `Res` or `Def`.

changelog: Add ``[`repeated_where_clause_or_trait_bound`]`` lint.
@aldhsu
Copy link
Contributor Author

aldhsu commented Jul 13, 2022

Closed by #8703.

@aldhsu aldhsu closed this as completed Jul 13, 2022
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

No branches or pull requests

1 participant