Open bingmatv opened 5 months ago
This seems to be covered by arithmetic_side_effects?
This seems to be covered by arithmetic_side_effects?
cargo clippy
only showed:
warning: unused variable: s
--> src/main.rs:4:9
|
4 | let s = (s.trim().parse::_s
Only warned about unused variable.
arithmetic_side_effects is in the restriction
lint group, which is allowed by default, so you have to explicitly enable it.
#![warn(clippy::arithmetic_side_effects)] // <-------------
#![allow(dead_code, unused_variables)]
fn main() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let s = (s.trim().parse::<u8>().unwrap()) * 3;
}
warning: arithmetic operation that can potentially result in unexpected side-effects
--> src/main.rs:7:13
|
7 | let s = (s.trim().parse::<u8>().unwrap()) * 3;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::arithmetic_side_effects)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Unfortunately arithmetic_side_effects
is quite poor:
.add_assign
(#12318)But probably it doesn't make sense to use this ticket as a tracking issue for problems with this lint; it shoud be closed.
What it does
Rust panics for integer overflow in debug mode, but it will wrap around any integers in release mode, aka, when
--release
parameter is added for cargo.Advantage
No response
Drawbacks
No response
Example
It accepts user input then multiply the accepted integer by 3, may wrap around when multiply by 3.