-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(integer_division_remainder_used): also detect inherent division/r… #17618
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,40 @@ pub(super) fn check(cx: &LateContext<'_>, op: BinOpKind, lhs: &Expr<'_>, rhs: &E | |
| ); | ||
| } | ||
| } | ||
| // check method call is present in specific list if yes also lint it | ||
| pub(super) fn check_method_call(cx: &LateContext<'_>, method_name: &str, receiver: &Expr<'_>, span: Span) { | ||
| let instance_ty = cx.typeck_results().expr_ty(receiver); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please change the order here that we first check the name, then |
||
| if matches!( | ||
| method_name, | ||
| "checked_div" | ||
| | "checked_div_euclid" | ||
| | "checked_div_exact" | ||
| | "checked_rem" | ||
| | "checked_rem_euclid" | ||
| | "div_ceil" | ||
| | "div_euclid" | ||
| | "div_exact" | ||
| | "overflowing_div" | ||
| | "overflowing_div_euclid" | ||
| | "overflowing_rem" | ||
| | "overflowing_rem_euclid" | ||
| | "rem_euclid" | ||
| | "strict_div" | ||
| | "strict_div_euclid" | ||
| | "saturating_div" | ||
| | "strict_rem" | ||
| | "strict_rem_euclid" | ||
| | "wrapping_div" | ||
| | "wrapping_div_euclid" | ||
| | "wrapping_rem" | ||
| | "wrapping_rem_euclid" | ||
|
Comment on lines
+30
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check using |
||
| ) && matches!(instance_ty.peel_refs().kind(), ty::Int(_) | ty::Uint(_)) | ||
| { | ||
| span_lint( | ||
| cx, | ||
| INTEGER_DIVISION_REMAINDER_USED, | ||
| span.source_callsite(), | ||
| format!("use of `{method_name}` has been disallowed in this context"), | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,21 @@ impl std::ops::Rem for CustomOps { | |
| } | ||
| } | ||
|
|
||
| fn issue17603() { | ||
| let x: u16 = 7; | ||
| let _ = x.div_ceil(3); | ||
| //~^ integer_division_remainder_used | ||
|
|
||
| let _ = x.wrapping_div(3); | ||
| //~^ integer_division_remainder_used | ||
|
|
||
| let _ = x.checked_rem(3); | ||
| //~^ integer_division_remainder_used | ||
|
|
||
| let f: f64 = 7.0; | ||
| let _ = f.div_euclid(3.0); | ||
| } | ||
|
Comment on lines
+23
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for each of the methods noted above, I would expect one testcase, so please copy paste the list and add a testcase for each 😉 Since |
||
|
|
||
| fn main() { | ||
| // should trigger | ||
| let a = 10; | ||
|
|
||
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.
Does not seem like very usefull docs.. I can see this by glossing over the fn..
Also not a doc comment