zebra icon indicating copy to clipboard operation
zebra copied to clipboard

Enforce unwrap-pertinent Clippy lints

Open dconnolly opened this issue 3 years ago • 1 comments

Motivation

We have a few bugs that have crept in due to unwrap()s being trigger-able in production.

Solution

Enforce these Clippy lints in production (i.e. non-test code), by either adding clippy:(allow|deny) annotations at the top of each crate or in each module.

https://rust-lang.github.io/rust-clippy/master/#fallible_impl_from

Checks for impls of From<..> that contain panic!() or unwrap()

https://rust-lang.github.io/rust-clippy/master/#unwrap_in_result

Checks for functions of type Result that contain expect() or unwrap()

This might be extra pedantic: https://rust-lang.github.io/rust-clippy/master/#unwrap_used

Checks for impls of From<..> that contain panic!() or unwrap()

Alternatives

Try to enforce these rules at review time, by a human. Try to write a custom Clippy lint to enforce these rules: https://github.com/trailofbits/dylint (why, if Clippy proper has the above lints?)

Related Work

dconnolly avatar Jun 14 '21 21:06 dconnolly

I think we should enforce fallible_impl_from in test code as well.

We're unlikely to have From impls in test code, and if we do, we might as well get them right.

@dconnolly what do you think?

teor2345 avatar Jun 14 '21 22:06 teor2345

This is not a priority for Zebra right now.

teor2345 avatar Aug 26 '22 04:08 teor2345