-
Notifications
You must be signed in to change notification settings - Fork 1.6k
False positive in unnecessary_cast with hex literals #5220
New issue
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
Comments
I would like to work on this issue and investigated a bit. Unfortunately, the AST doesn't seem to record whether the integer literal was written in hex or decimal notation. The enum It seems to me that properly resolving these false positives would require extending the |
@mlegner that's unfortunate, I'm not really aware of those implementation details but from a glance it seems your summation of the problem is accurate. |
Clippy has it's own struct, that can be build from literals and from where you can detect if it is a hex, bin, or oct literal: rust-clippy/clippy_lints/src/literal_representation.rs Lines 132 to 150 in 0f4a3fe
So no need to modify the rustc AST. |
Thanks for addressing this so quickly! |
clippy 0.0.212 (69f99e7 2019-12-14)
The lint for
#[warn(unnecessary_cast)]
acts strangely when integers are written in hex. Example:However,
f32
is valid hex, so if I write0x1b_f32
rust interprets the value as an integer. It does helpfully output the integer literal as a decimal number in the suggestion, but it isn't hex anymore which defeats the purpose.The text was updated successfully, but these errors were encountered: