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

Use clippy to avoid unchecked casts and arithmetic #1236

Closed
RalfJung opened this issue Mar 17, 2020 · 4 comments · Fixed by #2441
Closed

Use clippy to avoid unchecked casts and arithmetic #1236

RalfJung opened this issue Mar 17, 2020 · 4 comments · Fixed by #2441
Labels
A-meta Not about any part of Miri per se, but about shaping the environment to make something in/with Miri C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out E-good-first-issue A good way to start contributing, mentoring is available

Comments

@RalfJung
Copy link
Member

@oli-obk writes

There's a clippy lint for this if we want to make sure we don't add more of these in the future: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic

AFAIK there is also one for casts, right?

Is there a good way to also subject the miri engine in librustc_mir/interpret to these checks?

@RalfJung RalfJung added A-meta Not about any part of Miri per se, but about shaping the environment to make something in/with Miri C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out labels Mar 17, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Mar 17, 2020

There's a whole group of cast lints.

Unfortunately we aren't quite at the stage where we can run clippy lints on rustc. Though @matthiaskrgr has been doing this, and it may actually work well nowadays.

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 17, 2020

Yes, one can get it to work but it is very fragile and I am currently waiting on clippy being updated :)
https://github.com/matthiaskrgr/rust/commits/fix_xpy_clippy

edit: the branch is probably somewhat I'll see if I can get it to work if clippy update lands tonight.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 30, 2022

The minimal bar would be to add it to our CI like with rustfmt. #2091 updates miri to be clean with clippy

@RalfJung
Copy link
Member Author

RalfJung commented Jun 8, 2022

We now have clippy on CI. So we can resolve this issue by adding

#![warn(
    clippy::cast_sign_loss,
    clippy::cast_possible_truncation,
    clippy::cast_possible_wrap,
    clippy::cast_lossless
)]

and fixing the warnings.

This doesn't help for the code in the rustc repo though.

@RalfJung RalfJung added the E-good-first-issue A good way to start contributing, mentoring is available label Jun 8, 2022
bors added a commit that referenced this issue Jul 25, 2022
enable clippy lints against integer casts and arithmetic

Cc #1236
bors added a commit that referenced this issue Jul 25, 2022
enable clippy lints against integer casts

Cc #1236
@bors bors closed this as completed in 6e306f9 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Not about any part of Miri per se, but about shaping the environment to make something in/with Miri C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out E-good-first-issue A good way to start contributing, mentoring is available
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants