-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
For now, manual_rotate
only lints when the shift amounts are constant. However, there is also the option of shifting by some expression x
and either BIT_WIDTH - x
or (BIT_WIDTH - 1) ^ x
. This is a bit harder to detect, as we don't know whether the subtraction will be in the first or second part of the binary operation, but it should certainly be possible.
cc @frp who implemented the original lint.
Lint Name
manual_rotate
Reproducer
I tried this code:
let s = 5;
let x = 123456_u32;
let _ = (x << s) | (x >> (32 - s));
let _ = (x << s) | (x >> (31 ^ s));
The lint should be extended to catch both cases, suggesting x.rotate_left(s)
.
Version
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't