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

Unnecessary type repetition in trait bound #3764

Closed
xd009642 opened this issue Feb 14, 2019 · 2 comments · Fixed by #5761
Closed

Unnecessary type repetition in trait bound #3764

xd009642 opened this issue Feb 14, 2019 · 2 comments · Fixed by #5761
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group

Comments

@xd009642
Copy link
Contributor

So I raised this on rust-lang/rust#58471 and it was suggested this is better as a clippy lint so pasting the issue text here for quick reference:

My where clauses in traits recently had some unnecessary noise that the compiler could warn against:

What I was doing:

impl<T> SomeTrait<T> where T: Clone, T: Debug

What I should have been doing:

impl<T> SomeTrait<T> where T: Clone + Debug

I'd be happy to implement this myself if there's a consensus on adding this as a warning, though I may > need some mentoring 👍

The offer to help with a PR myself still stands, I had a quick check of the lints and didn't spot it.

@oli-obk oli-obk added A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group labels Feb 15, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2019

There are theoretically infinte ways to write where bounds. So as a first step just doing unification of T: Foo, T: Bar to T: Foo + Bar seems like a good idea.

This lint should not trigger inside macros (as it doesn't matter there and some macros might get hard to write), so you should use the in_macro function to bail out if we're inside a macro.

You can implement the check_generics method and access the where_clauses field on the generics argument. If you want any help with the implementation, don't hesitate to ask here.

@xd009642
Copy link
Contributor Author

I've just done a draft pull request. It's roughly there and builds but doesn't yet work.

bors added a commit that referenced this issue Jul 29, 2019
trait bounds lint - repeated types

This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go?

Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds.

There may be other issues with how I've implemented this so any assistance is appreciated!
bors added a commit that referenced this issue Jul 29, 2019
trait bounds lint - repeated types

This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go?

Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds.

There may be other issues with how I've implemented this so any assistance is appreciated!

changelog: Add new lint: `type_repetition_in_bounds`
bors added a commit that referenced this issue Jul 30, 2019
trait bounds lint - repeated types

This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go?

Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds.

There may be other issues with how I've implemented this so any assistance is appreciated!

changelog: Add new lint: `type_repetition_in_bounds`
@bors bors closed this as completed in fff8e72 Jul 3, 2020
@bors bors closed this as completed in #5761 Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants