`// PANIC` comment on panic-able calls
What it does
Reports on functions marked as panic-able (for example, .expect()) in the config file or with a special #[clippy::may_panic].
Advantage
- Ensures that specially critical code is handled with the requirement that it won't panic
- Allows for more flexibility than
unwrap_usedordisallowed_methods
Drawbacks
No response
Example
#[clippy::may_panic]
fn dangerous(v: Vec<usize>) -> usize {
v[1]
}
fn foo() {
let v = vec![];
let _ = dangerous(v);
}
Comparison with existing lints
Unlike unwrap_used, this allows for any function marked such as that.
Compared disallowed_methods, this allows for any function call and gives a specific reason.
Unlike indexing_slicing, this works for any function marked as clippy::may_panic
Unlike unreachable/unimplemented, this works for any functions marked with the attribute.
Additional Context
This was requested by the Rust-for-Linux project, giving it priority. I will mentor anyone trying to implement it.
@rustbot claim
I'd love to work on this, and would certainly appreciate some mentorship :)
Hi @hcbarker! Thanks for taking the time to contribute to Clippy. I'll guide you through this process (and obviously respond any question that you might have)
First of all, some useful resources:
- Rust's Zulip is used for instant messaging with anyone on the team, you can find me for more direct messaging.
- Rust Clippy book
- Rustdoc for
rustc_hir(an internal module, not useful to you right now) - The rustc dev guide, it has some information that the Clippy book doesn't have because it's more related at compiler internals, more than Clippy internals
I suggest that you start by reading the Clippy book, it teaches you how to add a lint. For examples on how current lints are written, I'd say that this specific lint could be similar to how undocumented_unsafe_blocks works.
Note that, in the end, a Clippy lint is just a struct that implements a special trait that goes token-by-token, expr-by-expr, item-by-item, calling a set of functions to check that item and emit a warn if necessary.
Once you have a pull request, write "r? blyxyas" somewhere on the body of your pull request.
Also note that I might be slow to respond on weekends, I'm under direct threat from my partner that if I review anything on weekends, she'll assassinate me hit-man style.
@blyxyas Thanks a bunch! I'll reach out on Zulip as I have questions :)