Skip to content
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

Warn on any panic code like unwrap, expect, assert, todo, ... #12754

Open
nyurik opened this issue May 2, 2024 · 2 comments
Open

Warn on any panic code like unwrap, expect, assert, todo, ... #12754

nyurik opened this issue May 2, 2024 · 2 comments
Labels
A-lint Area: New lints

Comments

@nyurik
Copy link
Contributor

nyurik commented May 2, 2024

What it does

When a library tries to be as "clean" as possible, it may want to prevent any accidental panics. Panics could be caused by many different calls. Clippy offers unwrap_used, todo, and some other lints, but there is no single lint that will catch any panic-producing calls. Granted that it is impossible to catch all such cases, but having a common lint that will grow as more panic-y functions are added to stdlib may offer a more stable solution.

Advantage

  • consolidates all panic-catching lints under one name, preventing user from accidentally missing some
  • as more panic-producing functions are added to stdlib, this lint will include them too
  • clearly indicates intention of "no panic" goal of the lib

Drawbacks

some panics are hard to catch, e.g. arithmetic wrapping (or maybe it should be caught too somehow?)

Example

result.unwrap()

Could be written as:

if Ok(v) = result { ... } else { ... }
@nyurik nyurik added the A-lint Area: New lints label May 2, 2024
@y21
Copy link
Member

y21 commented May 3, 2024

There's been some discussion for what this should look like in #11808.

arithmetic wrapping (or maybe it should be caught too somehow?)

arithmetic_side_effects should do this

@nyurik
Copy link
Contributor Author

nyurik commented May 3, 2024

@y21 thanks for the link! This is exactly what i was looking for (I wonder if this issue should be closed then?). My only concern is that the discussion has from the start dismissed the overlapping groups, making it far harder for the users (i.e. everyone now has to copy and maintain their own list of lints in each project - a huge detriment to usability). Overlapping lint groups is a far smaller evil in my opinion, especially now that we have group priorities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants