You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggests to replace code that contains an as cast, with specialized functions from the std library.
Advantage
Makes the intent more explicit.
Drawbacks
Slightly longer code.
Example
#![warn(clippy::all)]#![warn(clippy::pedantic)]#![warn(clippy::nursery)]#![warn(clippy::style)]fnmain(){let a = 1_i64;let b = 2_u64;let c = 2_u32;let x = a - (b asi64);let y = a.wrapping_sub_unsigned(b);let z = a.wrapping_sub_unsigned(u64::from(c));println!("{x:?} {y:?} {z:?}");}
This code gives a clippy::cast_possible_wrap warning on the (b as i64) part, but I think it should suggest to replace code like in the computation of x, with the code that computes y. Similar suggestions could be used for other mixed-type operations.
The text was updated successfully, but these errors were encountered:
What it does
Suggests to replace code that contains an as cast, with specialized functions from the std library.
Advantage
Makes the intent more explicit.
Drawbacks
Slightly longer code.
Example
This code gives a clippy::cast_possible_wrap warning on the (b as i64) part, but I think it should suggest to replace code like in the computation of x, with the code that computes y. Similar suggestions could be used for other mixed-type operations.
The text was updated successfully, but these errors were encountered: