add lint: could_be_assoc_type_bounds
#13738
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #12925.
The issue explains the two patterns it looks for, but to quickly summarize:
can both be
This ended up far more involved than I originally expected and it's a bit annoying just how much code is required to have a proper machine applicable suggestion that can handle all the ways these bounds can be written.
TBH I'm not sure if it's worth all the complexity, but oh well (especially considering that something like
<T as Trait>::Assoc: Copy, <T as Trait>::Assoc: Clone
, which requires buffering the lint, is probably rather rare). The current suggestion still relies a bit on rustfmt to clean up, like a trailing comma because I didn't want to make it even more complicated than it already is, but I think it should be fine.There's the question if we want to lint
impl Trait
types (<T: Iterator<Item = impl Copy>>
-><T: Iterator<Item: Copy>>
). My initial implementation naturally linted them beacuse they're desugared to the pattern we already detect, but calling it a complexity issue is a stretch IMO as it barely saves a few characters so for now I just ignored them, and the lint description/messages would need some special casing.changelog: new lint:
could_be_assoc_type_bounds