rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Allowing `clippy::arithmetic` in const contexts

Open DrSloth opened this issue 3 years ago • 1 comments

Description

The new clippy::arithmetic lint always lints against usage of arithmetic operators. Would it be feasible to not lint in const contexts? The reasoning for the lint is the overflow/panic behavior, there are a lot of scenarios which could be statically checked.

For instance:

// This will never panic
let x = 60i32 * 100;
// This will never panic and a panic in a const would appear at compile time
const Y = 100u8 + 17;

Would it be feasible to disallow arithmetic only in scenarios which may actually overflow/panic?

Version

binary: rustc
commit-hash: d394408fb38c4de61f765a3ed5189d2731a1da91
commit-date: 2022-08-07
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 14.0.6

Additional Labels

@rustbot label +C-enhancement

DrSloth avatar Aug 08 '22 20:08 DrSloth

Yes, it is in my TODO list. I will probably provide a PR in the following days.

c410-f3r avatar Aug 11 '22 20:08 c410-f3r