-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add clippy lints to catch more panics #1363
Comments
I don't agree with |
It's not really pointless because it tells you more about where in the code the problem happened. Fortunately, unwrap/expect now use I'm over all positive about adding these lints; I think they'll work out well! I feel like the main situation where we'll want to keep them in is near unsafe code: it's better to panic than trigger UB (which is essentially, allowing for a broader set of undesirable behavior including a panic elsewhere). We can also improve the lints upstream to handle more cases if there are panics that are clearly safe at compile time. |
I want to forbid both. |
This makes sense to me. |
I can add these clippy lints. Is anyone else working on this at the moment? |
@sffc is that list above up to date? |
Yes it is. Nothing has changed since I filed the issue. |
Looking at @ozghimire's PR, I'm wondering if we should restrict |
We're not saying the panic is "safe" (which has a special meaning in Rust), we're saying it's impossible. We shouldn't include a message in the binary that will never be used. I also think we should be consistent and either always |
But logic errors do come up, and the assumption that it'll never be shown can be wrong. |
Fixed in #1650 |
We should enable the following clippy lints:
indexing_slicing
https://rust-lang.github.io/rust-clippy/master/#indexing_slicingexpect_used
https://rust-lang.github.io/rust-clippy/master/#expect_usedunwrap_used
https://rust-lang.github.io/rust-clippy/master/#unwrap_usedpanic
https://rust-lang.github.io/rust-clippy/master/#panicIdeally we can limit this to library code only. We don't want these in test code or offline tooling code.
As usual, in cases where the usage of these operators is valid, an
#[allow(clippy::indexing_slicing)]
can be used, with a comment explaining why it is OK.The goal here is to better enforce this section of the style guide: https://github.com/unicode-org/icu4x/blob/main/docs/process/style_guide.md#best-practice
I can't talk about panics without also referencing #1183
The text was updated successfully, but these errors were encountered: