-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
size_of_in_element_count false-positive when dividing byte-size by element size #6511
Comments
I can confirm this problem seen from
Fortunately, the check passed when I extracted the arg
|
Why was this a |
I think the intention was to only look for it in the dividend to catch things like The change should be here: https://github.com/nico-abram/rust-clippy/blob/c1a5329475d041dbeb077ecda6ae71f690b4bcc1/clippy_lints/src/size_of_in_element_count.rs#L54-L55 Maybe something like this ExprKind::Binary(op, left, right) if BinOpKind::Mul == op.node => {
get_size_of_ty(cx, left).or_else(|| get_size_of_ty(cx, right))
},
ExprKind::Binary(op, left, right) if BinOpKind::Div == op.node => {
get_size_of_ty(cx, left)
}, |
I'm fine with suppressing this manually, but it should really be a |
@nico-abram I wanted to be a bit more conservative and keep track of divisions (inversions) in the RHS. What do you think of this? https://github.com/MarijnS95/rust-clippy/compare/size-in-element-count-divide-by-byte-size? |
Lint name:
size_of_in_element_count
I tried this code:
I expected to see this happen:
No
size_of_in_element_count
lint warning/error when dividing bysize_of
.Instead, this happened:
#6394 recently introduced the
size_of_in_element_count
to catch cases where byte sizes instead of element sizes are passed intofrom_raw_parts
and related functions. However,size_of
is used in the example above to convert away from byte sizes by dividing instead of multiplying. After all the linter error states:When no count of bytes nor multiplication is used here at all.
CC @nico-abram
Meta
cargo +nightly clippy -V
:clippy 0.0.212 (257becb 2020-12-27)
rustc +nightly -Vv
:The text was updated successfully, but these errors were encountered: