Enforce adding explanations for unwrap

I have unwraps in my code that are safe to do and I use comments to indicate why it is okay to unwrap. However, I was wondering if there is a way (maybe extending clippy for e.g) or other approaches that folx have used to detect unwraps in the code that don't include an explanation. Thanks!

No, if that would be enforced, that would likely break a fair amount of code.

However, there are {Result, Option}::expect() which may fit your needs.

2 Likes

And you can even enforce always using expect instead of unwrap with #![deny(clippy::unwrap_used)].

4 Likes

Thank you for the tips!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.