-
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
Disable type_complexity
lint by default
#10571
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
The question is, is the lint the problem or is it just too trigger happy and we should increase the default threshold: rust-clippy/clippy_lints/src/utils/conf.rs Lines 294 to 297 in d43714a
Moving it to |
Increasing the threshold probably won't help tremendously: I don't think there's a good threshold for "normal" Rust that also works well for type-heavy frameworks. If we wanted to keep it enabled by default, but make it less trigger happy, I would actually suggest that it should only trigger on types that are used more than once. In these frameworks (like Bevy), types are used to construct one-off requests. In cases where the type is only used once, there's no benefit to defining a wrapper type: the author is merely moving the complexity. With that change in place, this lint could probably stay enabled in most cases, and only locally ignored if needed. |
Personally I would oppose disabling this lint, I think there is insufficient justification for doing so. Clippy lints are meant to be used with a liberal sprinkling of per-use-case I think most of the ecosystem still prefers small types, using aliases where necessary, but there are a couple frameworks where heavy type chains are a core part of how they work, and I think users of those frameworks are correct to disable this lint. It might be worth having this mentioned in your docs, it is not a code smell to disable a clippy lint for codebase-specific reasons. Footnotes
|
@Manishearth, how would you feel about "the type must be used more than once" as a restriction? I think that would reduce the false positive rate significantly, but it may lead to surprising behavior and adds complexity to clippy's code base. |
That's a pretty tricky heuristic to implement since clippy largely sticks to local passes, not global ones. It's possible, would be a perf issue. But also; I not actually sure if I agree with that heuristic either, even if a very complex type is used in one place, I think it's reasonable to want to simplify it in the general case, though not in the case of frameworks which are designed with this kind of type in mind. FWIW we are open to special casing crates as well, we can do that with a second config and we include some crates by default. This would mean that if a I've also posted this to Zulip to get more feedback. |
Yeah, that's my concern too. Things like
This would work very well for us: in our case, only the types from
If we had a first class tool for variadics (🥺), skipping over "all variadic types" would probably similarly eliminate this class of false positive. One day. |
@sgrif Do you have opinions on the proposed heuristics above from a Diesel perspective? Would it make sense to be at the crate level, or with specific types? @alice-i-cecile Another option if you really care about specific types only (rather than blanket for a crate) is that we could add a |
I love the |
Diesel would probably need it at the crate level, the only type that doesn't end up getting built to arbitrary complexity regularly is the connection. @weiznich can probably give more concrete thoughts than I can though |
Would it be ok if it was item-level and Diesel just applied it to every item? Note that the lint would be suppressed by the presence of a tagged type anywhere inside a "complex type". |
Thanks for the ping. It might work for diesel if the lint is suppressed of any tagged type appears inside of a "complex type". (It will nevertheless be quite a bit of work to add the relevant |
I really like the idea of a Just allowing tagging items with the attribute is easier to implement in Clippy, I think. But we might be able to also allow an inner Adding a config to Clippy and providing some crates as a default configuration has the downside, that we would have to decide which crate is "important" enough to include in the default configuration. I'd like to avoid that. |
Alright, we probably should close this PR but open two issues:
|
# Objective The clippy lint `type_complexity` is known not to play well with bevy. It frequently triggers when writing complex queries, and taking the lint's advice of using a type alias almost always just obfuscates the code with no benefit. Because of this, this lint is currently ignored in CI, but unfortunately it still shows up when viewing bevy code in an IDE. As someone who's made a fair amount of pull requests to this repo, I will say that this issue has been a consistent thorn in my side. Since bevy code is filled with spurious, ignorable warnings, it can be very difficult to spot the *real* warnings that must be fixed -- most of the time I just ignore all warnings, only to later find out that one of them was real after I'm done when CI runs. ## Solution Suppress this lint in all bevy crates. This was previously attempted in #7050, but the review process ended up making it more complicated than it needs to be and landed on a subpar solution. The discussion in rust-lang/rust-clippy#10571 explores some better long-term solutions to this problem. Since there is no timeline on when these solutions may land, we should resolve this issue in the meantime by locally suppressing these lints. ### Unresolved issues Currently, these lints are not suppressed in our examples, since that would require suppressing the lint in every single source file. They are still ignored in CI.
# Objective The clippy lint `type_complexity` is known not to play well with bevy. It frequently triggers when writing complex queries, and taking the lint's advice of using a type alias almost always just obfuscates the code with no benefit. Because of this, this lint is currently ignored in CI, but unfortunately it still shows up when viewing bevy code in an IDE. As someone who's made a fair amount of pull requests to this repo, I will say that this issue has been a consistent thorn in my side. Since bevy code is filled with spurious, ignorable warnings, it can be very difficult to spot the *real* warnings that must be fixed -- most of the time I just ignore all warnings, only to later find out that one of them was real after I'm done when CI runs. ## Solution Suppress this lint in all bevy crates. This was previously attempted in #7050, but the review process ended up making it more complicated than it needs to be and landed on a subpar solution. The discussion in rust-lang/rust-clippy#10571 explores some better long-term solutions to this problem. Since there is no timeline on when these solutions may land, we should resolve this issue in the meantime by locally suppressing these lints. ### Unresolved issues Currently, these lints are not suppressed in our examples, since that would require suppressing the lint in every single source file. They are still ignored in CI.
# Objective The clippy lint `type_complexity` is known not to play well with bevy. It frequently triggers when writing complex queries, and taking the lint's advice of using a type alias almost always just obfuscates the code with no benefit. Because of this, this lint is currently ignored in CI, but unfortunately it still shows up when viewing bevy code in an IDE. As someone who's made a fair amount of pull requests to this repo, I will say that this issue has been a consistent thorn in my side. Since bevy code is filled with spurious, ignorable warnings, it can be very difficult to spot the *real* warnings that must be fixed -- most of the time I just ignore all warnings, only to later find out that one of them was real after I'm done when CI runs. ## Solution Suppress this lint in all bevy crates. This was previously attempted in #7050, but the review process ended up making it more complicated than it needs to be and landed on a subpar solution. The discussion in rust-lang/rust-clippy#10571 explores some better long-term solutions to this problem. Since there is no timeline on when these solutions may land, we should resolve this issue in the meantime by locally suppressing these lints. ### Unresolved issues Currently, these lints are not suppressed in our examples, since that would require suppressing the lint in every single source file. They are still ignored in CI.
The
type_complexity
lint is currently the most globally ignored lint. Across whole ecosystems (Bevy, Diesel and more), it simply must be turned off by every user and every crate in the ecosystem: clear and idiomatic use of type-heavy frameworks constantly triggers this lint.In these cases, it encourages replacing straightforward dependency injection code with type definitions that are only used once, misleading beginners into masking complexity with indirection.
Feedback requested: I'm new to contributing to clippy, and I wasn't sure of the best way to disable this by default. Should this be pedantic? Style? It's clearly a "complexity" lint still, but it doesn't appear that we can configure it to be off-by-default without moving it out of the group.