diff options
| author | Evan Typanski <evan.typanski@microfocus.com> | 2022-06-22 14:08:47 -0400 |
|---|---|---|
| committer | Evan Typanski <evan.typanski@microfocus.com> | 2022-06-22 14:23:04 -0400 |
| commit | 90f8277fe3ce6d0e238feac3bf10891f8c18f23a (patch) | |
| tree | 3260ea77d05c7e3e6f59bbad54cf79cfd6e19e56 /clippy_lints | |
| parent | c8df6d6970749abc8ee3b3b5f78d4c1a9ad33bb6 (diff) | |
| download | rust-90f8277fe3ce6d0e238feac3bf10891f8c18f23a.tar.gz rust-90f8277fe3ce6d0e238feac3bf10891f8c18f23a.zip | |
Fix case for function params
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/manual_rem_euclid.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 3ffd9a07376..c338447686f 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -61,12 +61,23 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && op3.node == BinOpKind::Rem && let Some((const3, expr3)) = check_for_positive_int_constant(cx, expr2, false) && const1 == const2 && const2 == const3 - // Only apply if we see an explicit type annotation on the local. && let Some(hir_id) = path_to_local(expr3) - && let Some(Node::Binding(_)) = cx.tcx.hir().find(hir_id) - && let Some(Node::Local(local)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) - && let Some(ty) = local.ty - && !matches!(ty.kind, TyKind::Infer) { + && let Some(Node::Binding(_)) = cx.tcx.hir().find(hir_id) { + // Apply only to params or locals with annotated types + match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + Some(Node::Param(..)) => (), + Some(Node::Local(local)) => { + if let Some(ty) = local.ty { + if matches!(ty.kind, TyKind::Infer) { + return; + } + } else { + return; + } + } + _ => return, + }; + let mut app = Applicability::MachineApplicable; let rem_of = snippet_with_applicability(cx, expr3.span, "_", &mut app); span_lint_and_sugg( |
