FYI “Rust’s Clippy is a collection of lints (static analysis rules) designed to catch common mistakes and suggest improvements in your Rust code.”
tialaramex · 3h ago
It's also very tunable. If you (or your team) hate shadowing for example, which is a common idiom in Rust but is often seen as undesirable in other languages, there are several Clippy rules you can enable for a project to either forbid specific kinds of shadowing or introduce a blanket prohibition.
Or at the other end of the scale, the average Rust programmer doesn't care that their code could panic if numbers stop making sense, for example if I'm summing the number of employees who quality for a bonus scheme, the fact that this operation (which I think might reach hundreds but likely is only dozens) could panic if it exceeds u32::MAX isn't worth linting. But if you write jet engine firmware, you need to take such "this can't happen" cases more seriously so you can turn on a lint which forbids these naive operations.
lewdwig · 3h ago
If Clippy struggles to account for current and future changes to the Rust compiler this to me raises an obvious question: why isn’t Clippy part of the Rust compiler?
afdbcreid · 2h ago
I wouldn't say it struggles to do that. And, it is part of the Rust compiler, somewhat. Every PR to the Rust compiler builds Clippy in CI and tests it (although I'm not sure if all tests are run or only part of them).
Clippy is a large collection of mostly unrelated lints, and more are always added. Understandably, they accumulate craft. I think stopping new lints for some time is a reasonable thing to do to keep a healthy codebase.
ishanjain28 · 1h ago
Unrelated, Is there a clippy lint to detect when you fill up and array/collection and immediately call clear on it ?
PartiallyTyped · 4h ago
I’ve contributed quite a few patches into clippy, it’s a great project and a great way to learn how the rustc “sees” code; from the AST, to HIR, to using typeck — sometimes we even construct types at runtime to validate the code against — to tracking traits and their implementations across a whole crate!
Clippy really is a labour of love project, and it’s been great to work with these folk <3
I will try to pick up some issues in the coming weeks.
jedisct1 · 2h ago
Just to be clear, this has nothing to do with Microsoft Clippy. This post is about a tool for a programming language called Rust.
Or at the other end of the scale, the average Rust programmer doesn't care that their code could panic if numbers stop making sense, for example if I'm summing the number of employees who quality for a bonus scheme, the fact that this operation (which I think might reach hundreds but likely is only dozens) could panic if it exceeds u32::MAX isn't worth linting. But if you write jet engine firmware, you need to take such "this can't happen" cases more seriously so you can turn on a lint which forbids these naive operations.
Clippy is a large collection of mostly unrelated lints, and more are always added. Understandably, they accumulate craft. I think stopping new lints for some time is a reasonable thing to do to keep a healthy codebase.
Clippy really is a labour of love project, and it’s been great to work with these folk <3
I will try to pick up some issues in the coming weeks.