We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, I think I'm having a false positive with the identity_conversion lint. Minimal example:
identity_conversion
pub trait SafeSignedArithmetic: Copy { type Unsigned; fn checked_add_unsigned(self, u: Self::Unsigned) -> Option<Self>; } macro_rules! impl_safe_signed_arithmetic { ( $i:ty, $u:ty ) => { impl SafeSignedArithmetic for $i { type Unsigned = $u; fn checked_add_unsigned(self, u: $u) -> Option<$i> { let u_half = (u / 2) as $i; let u_rem = (u % 2) as $i; self.checked_add(u_half)? .checked_add(u_half)? .checked_add(u_rem) } } }; } impl_safe_signed_arithmetic!(i8, u8); fn main() { println!("Hello, world!"); }
Versions:
$ cargo clippy -V clippy 0.0.212 (3710ec5 2019-05-11) $ rustc --version rustc 1.36.0-nightly (af98304b9 2019-05-11)
Clippy's output:
$ cargo clippy Checking check_identical_conversion v0.1.0 (/home/real/temp/check_identical_conversion) warning: identical conversion --> src/main.rs:17:41 | 17 | self.checked_add(u_half)? | ^ ... 25 | impl_safe_signed_arithmetic!(i8, u8); | ------------------------------------- in this macro invocation | = note: #[warn(clippy::identity_conversion)] on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion warning: identical conversion --> src/main.rs:18:41 | 18 | .checked_add(u_half)? | ^ ... 25 | impl_safe_signed_arithmetic!(i8, u8); | ------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion Finished dev [unoptimized + debuginfo] target(s) in 0.20s
Interestingly enough, if I try to implement this code without the macro, the clippy warnings disappear.
Thank you for developing clippy!
The text was updated successfully, but these errors were encountered:
This is already fixed in the latest release of Clippy: #4082 #4089
Playground
Try running rustup update nightly and try it again. If the issue still persists feel free to reopen.
rustup update nightly
Sorry, something went wrong.
Beta is coming soon, we should consider backports
No branches or pull requests
Hi, I think I'm having a false positive with the
identity_conversion
lint. Minimal example:Versions:
Clippy's output:
Interestingly enough, if I try to implement this code without the macro, the clippy warnings disappear.
Thank you for developing clippy!
The text was updated successfully, but these errors were encountered: