Skip to content

Arithmetic lint #8903

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

Closed
c410-f3r opened this issue May 27, 2022 · 3 comments · Fixed by #9130
Closed

Arithmetic lint #8903

c410-f3r opened this issue May 27, 2022 · 3 comments · Fixed by #9130

Comments

@c410-f3r
Copy link
Contributor

c410-f3r commented May 27, 2022

Are you guys open to include an allow-by-default restricted lint that will warn +/-///* regardless of the involved type? For example, num-bigint (among others) has arithmetic implementations that aren't triggered by clippy::integer_arithmetic.

If yes, then I will create a PR. If not, then feel free to close this issue.

@llogiq
Copy link
Contributor

llogiq commented May 27, 2022

This could be a restriction lint, and we may even want to make types to block arithmetic on configurable.

@ghost
Copy link

ghost commented May 31, 2022

Does it make sense to lint on types like std::num::Wrapping or std::num::Saturating? These can't overflow or panic (apart from
division by zero).

@c410-f3r
Copy link
Contributor Author

Like @llogiq said, types should be configurable. Built-in types that don't panic would then be listed as allowed somehow.

I was thinking about creating an arithmetic lint that could suppress integer_arithmetic in the long run.

bors added a commit that referenced this issue Jun 2, 2022
[1/N] Implement Arithmetic lint

Assuming that #8903 is OK, this PR starts the creation of the `Arithmetic` lint with configurable types.

My current struggle to get a rustc review inspired me to create smaller PRs in order to easy review and make merges as fast as possible. So the first step here only moves the `arithmetic.rs` file to `numeric_arithmetic.rs` to make room for the new lint.

--
changelog: none
@bors bors closed this as completed in 8882578 Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants