From 38cdf63acfd8a46ce5753a8767feab43c6382aa4 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 22 Jan 2019 15:28:51 +0100 Subject: [PATCH] Don't make decisions on values that don't represent the decision --- clippy_lints/src/utils/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index ab394cc47eaa..a7af4a52714a 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -64,9 +64,14 @@ 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 | hir::BodyOwnerKind::Closure => 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, } }