diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 473db1869ac..efa53ff94c3 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } self.const_span = Some(body_span); }, - hir::BodyOwnerKind::Fn => (), + hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => (), } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 5d94f0f3f05..c83b0f155fc 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -64,9 +64,25 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool { /// ``` pub fn in_constant(cx: &LateContext<'_, '_>, id: NodeId) -> bool { let parent_id = cx.tcx.hir().get_parent(id); - match cx.tcx.hir().body_owner_kind(parent_id) { - hir::BodyOwnerKind::Fn => false, - hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true, + match cx.tcx.hir().get(parent_id) { + Node::Item(&Item { + node: ItemKind::Const(..), + .. + }) + | Node::TraitItem(&TraitItem { + node: TraitItemKind::Const(..), + .. + }) + | Node::ImplItem(&ImplItem { + node: ImplItemKind::Const(..), + .. + }) + | Node::AnonConst(_) + | Node::Item(&Item { + node: ItemKind::Static(..), + .. + }) => true, + _ => false, } }