mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-05 02:50:32 +00:00
163 lines
7 KiB
Text
163 lines
7 KiB
Text
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:8:13
|
|
|
|
|
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)`
|
|
|
|
|
= note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:9:13
|
|
|
|
|
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:10:13
|
|
|
|
|
LL | let _ = 1u8.checked_add(1).unwrap_or(255);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u8.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:11:13
|
|
|
|
|
LL | let _ = 1u128
|
|
| _____________^
|
|
LL | | .checked_add(1)
|
|
LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455);
|
|
| |_______________________________________________________________________^ help: try using `saturating_add`: `1u128.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:16:13
|
|
|
|
|
LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_mul`: `1u32.saturating_mul(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:18:13
|
|
|
|
|
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:19:13
|
|
|
|
|
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:20:13
|
|
|
|
|
LL | let _ = 1u8.checked_sub(1).unwrap_or(0);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u8.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:24:13
|
|
|
|
|
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:25:13
|
|
|
|
|
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:26:13
|
|
|
|
|
LL | let _ = 1i8.checked_add(1).unwrap_or(127);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:27:13
|
|
|
|
|
LL | let _ = 1i128
|
|
| _____________^
|
|
LL | | .checked_add(1)
|
|
LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
|
|
| |_______________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:30:13
|
|
|
|
|
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:31:13
|
|
|
|
|
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:32:13
|
|
|
|
|
LL | let _ = 1i8.checked_add(-1).unwrap_or(-128);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:33:13
|
|
|
|
|
LL | let _ = 1i128
|
|
| _____________^
|
|
LL | | .checked_add(-1)
|
|
LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|
| |________________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:40:13
|
|
|
|
|
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:41:13
|
|
|
|
|
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:42:13
|
|
|
|
|
LL | let _ = 1i8.checked_sub(1).unwrap_or(-128);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:43:13
|
|
|
|
|
LL | let _ = 1i128
|
|
| _____________^
|
|
LL | | .checked_sub(1)
|
|
LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|
| |________________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:46:13
|
|
|
|
|
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:47:13
|
|
|
|
|
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:48:13
|
|
|
|
|
LL | let _ = 1i8.checked_sub(-1).unwrap_or(127);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(-1)`
|
|
|
|
error: manual saturating arithmetic
|
|
--> $DIR/manual_saturating_arithmetic.rs:49:13
|
|
|
|
|
LL | let _ = 1i128
|
|
| _____________^
|
|
LL | | .checked_sub(-1)
|
|
LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
|
|
| |_______________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(-1)`
|
|
|
|
error: aborting due to 24 previous errors
|
|
|