From 3168023cc8027c3fa53c7777d4f27be6a06bf168 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 22 Jan 2019 15:17:05 +0100 Subject: [PATCH 1/3] Rustup --- clippy_lints/src/arithmetic.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 473db1869ac0..efa53ff94c39 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 5d94f0f3f051..ab394cc47eaa 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -65,7 +65,7 @@ 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::Fn | hir::BodyOwnerKind::Closure => false, hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true, } } From 38cdf63acfd8a46ce5753a8767feab43c6382aa4 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 22 Jan 2019 15:28:51 +0100 Subject: [PATCH 2/3] 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, } } From d6c806378e6901b83d5ab8594dcd2c6347e0196a Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 22 Jan 2019 16:27:42 +0100 Subject: [PATCH 3/3] Rustfmt all the things --- clippy_lints/src/utils/mod.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index a7af4a52714a..c83b0f155fca 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -65,12 +65,23 @@ 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().get(parent_id) { - | Node::Item(&Item { node: ItemKind::Const(..), .. }) - | Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) - | Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) + 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, + | Node::Item(&Item { + node: ItemKind::Static(..), + .. + }) => true, _ => false, } }