-
Notifications
You must be signed in to change notification settings - Fork 1.8k
add ptr_offset_by_literal
lint
#15606
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
base: master
Are you sure you want to change the base?
Conversation
Lintcheck changes for b0e37f3
This comment will be updated if you push new changes |
} | ||
|
||
fn get_literal_bits<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<u128> { | ||
let ExprKind::Lit(lit) = expr.kind else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a let-chain is a bit more concise
let ExprKind::Lit(lit) = expr.kind else { | |
if let ExprKind::Lit(lit) = expr.kind | |
&& let LitKind::Int(packed_u128, _) = lit.node | |
{ | |
Some(packed_u128.get()) | |
} else { | |
None | |
} |
(the suggestion seems to be formatted weirdly, but it should (?) work correctly)
Method::Offset => "add", | ||
Method::WrappingOffset => "wrapping_add", | ||
}, | ||
Ordering::Equal => return Some(format!("{receiver}")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case looks a bit surprising, maybe add a short comment to it? Something like:
Ordering::Equal => return Some(format!("{receiver}")), | |
// `ptr.offset(0)` is equivalent to `ptr`, so no adjustment is needed | |
Ordering::Equal => return Some(format!("{receiver}")), |
(why on earth do the suggestions look like this)
This comment has been minimized.
This comment has been minimized.
5017b8a
to
50b300b
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
8818e59
to
43fa068
Compare
CI fails on an invalid version attribute, I'm using |
1.92.0 It will be fixed if necessary. |
43fa068
to
b0e37f3
Compare
@rustbot ready |
Related to https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast (and very much modelled off of its implementation).
This lint is motivated by cleaning up the output of c2rust, which contains many
.offset
calls with by literal. The lint also nicely handles offsets by zero, which are unnecessary.I'm aware that the feature freeze is still in place, but this was top-of-mind now. I'll patiently wait until the freeze is lifted.
changelog: [
ptr_offset_by_literal
]: addptr_offset_by_literal
lint