-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Associated types should not trigger a type_complexity message. #5157
Conversation
Thanks for directly opening a PR! A few notes: I think disabling it completely for impl T for S {
type X = Result<Option<Vec<u32>>, (String, Error)>;
}
// can be improved to
type OptVec = Option<Vec<u32>>;
type ErrTuple = (String, Error);
impl T for S {
type X = Result<OptVec, ErrTuple>;
} The problem at hand is rather, that First you have to add a field to this visitor ( rust-clippy/clippy_lints/src/types.rs Lines 1506 to 1511 in 63f818e
After that you just have to find the assoc type in a impl type. This can be done by adding (Doc) TyKind::Path(QPath::Resolved(Some(_), _)) => {
self.assoc_type_found = true;
return;
} between those two arms: rust-clippy/clippy_lints/src/types.rs Lines 1519 to 1522 in 63f818e
After that just gate the linting not only on the score, but also on rust-clippy/clippy_lints/src/types.rs Lines 1488 to 1494 in 63f818e
Also can you add the test to the already existing |
Hi @moshevds, are you still interested in finishing this PR up? Let us know if you need any further help =) |
Hi @phansch, I did discuss it a bit more with @flip1995 on discord, and made some changes. But I did come across a couple of things I didn't immediately know how to solve. Other priorities came along, and I forgot to come back to this. Looking back at what I did, I see that I added 3 commits related to the tests:
I also have a fix locally for the situation that third commit tests for, but I think I wasn't sure about the quality of that change. All in all, the scope of this is a bit larger than I anticipated, in a project that I know almost nothing about. I'm still interested in improving this lint, but what is the best way to proceed?
Perhaps you have another suggestion? |
@moshevds Breaking down the task seems like a good plan, especially since you're just getting started. Feel free to open separate PRs for the commits 👍 |
Thanks for contributing to Clippy! Sadly this PR was not updated in quite some time. If you waited on input from a reviewer, we're sorry that this fell under the radar. If you want to continue to work on this, just reopen the PR and/or ping a reviewer. |
@rustbot label -S-inactive-closed |
This PR fixes #1013 by removing the check entirely. Whether this check is useful could be a point of discussion. But considering that type_complexity isn't applied to the generic types of a trait, I don't think it should be applied to the associated types of a trait either.
Still, A lint for the complexity of associated types could be useful. IMHO, it would be better to add that as a separate lint. (And maybe a different threshold.)
I have not contributed to rust-clippy before and did not dive deeply into this, so I might have missed some things. The fix is simple, but I would appreciate a careful review.
changelog: Don't trigger type_complexity for associated types.