From e17dd4efa983d2363bea58c8e2811b057063e831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 23 Mar 2019 23:37:38 +0100 Subject: [PATCH 1/2] rustup https://github.com/rust-lang/rust/pull/59096/ --- clippy_lints/src/functions.rs | 3 +-- clippy_lints/src/len_zero.rs | 8 +++----- clippy_lints/src/methods/mod.rs | 3 +-- clippy_lints/src/missing_inline.rs | 9 ++++----- clippy_lints/src/new_without_default.rs | 3 +-- clippy_lints/src/types.rs | 2 +- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 5378f7d455f7..4313d040474a 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -256,8 +256,7 @@ impl<'a, 'tcx> Functions { hir_id: hir::HirId, ) { let expr = &body.value; - let node_id = cx.tcx.hir().hir_to_node_id(hir_id); - if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(node_id) { + if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(hir_id) { let raw_ptrs = iter_input_pats(decl, body) .zip(decl.inputs.iter()) .filter_map(|(arg, ty)| raw_ptr_arg(arg, ty)) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 4762ce760c9b..dc55721eb299 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -148,9 +148,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items } } - let trait_node_id = cx.tcx.hir().hir_to_node_id(visited_trait.hir_id); - - if cx.access_levels.is_exported(trait_node_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { + if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { let mut current_and_super_traits = FxHashSet::default(); let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id); fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx); @@ -195,7 +193,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { if cx .access_levels - .is_exported(cx.tcx.hir().hir_to_node_id(is_empty.id.hir_id)) + .is_exported(is_empty.id.hir_id) { return; } else { @@ -206,7 +204,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte }; if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { - if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(i.id.hir_id)) { + if cx.access_levels.is_exported(i.id.hir_id) { let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let ty = cx.tcx.type_of(def_id); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 3e7403a3fe28..858184d7ea16 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -918,8 +918,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); if let hir::ItemKind::Impl(_, _, _, _, None, ref self_ty, _) = item.node; then { - let node_id = cx.tcx.hir().hir_to_node_id(implitem.hir_id); - if cx.access_levels.is_exported(node_id) { + if cx.access_levels.is_exported(implitem.hir_id) { // check missing trait implementations for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS { if name == method_name && diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index d6711900093e..090ed6d242d1 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(it.hir_id)) { + if !cx.access_levels.is_exported(it.hir_id) { return; } match it.node { @@ -146,8 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - let node_id = cx.tcx.hir().hir_to_node_id(impl_item.hir_id); - if !cx.access_levels.is_exported(node_id) { + if !cx.access_levels.is_exported(impl_item.hir_id) { return; } @@ -163,8 +162,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { }; if let Some(trait_def_id) = trait_def_id { - if let Some(n) = cx.tcx.hir().as_local_node_id(trait_def_id) { - if !cx.access_levels.is_exported(n) { + if cx.tcx.hir().as_local_node_id(trait_def_id).is_some() { + if !cx.access_levels.is_exported(impl_item.hir_id) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index fde4081ae8f5..3bf0c22c322c 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -111,7 +111,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { let name = impl_item.ident.name; let id = impl_item.hir_id; - let node_id = cx.tcx.hir().hir_to_node_id(id); if sig.header.constness == hir::Constness::Const { // can't be implemented by default return; @@ -129,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { // impl of `Default` return; } - if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(node_id) { + if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id)); let self_ty = cx.tcx.type_of(self_did); if_chain! { diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 2e50222c8a9f..33dea622b358 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -2075,7 +2075,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(item.hir_id)) { + if !cx.access_levels.is_exported(item.hir_id) { return; } From b5d82524b4761775533520955574b8eff2fbf480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 23 Mar 2019 23:39:58 +0100 Subject: [PATCH 2/2] run cargo fmt --- clippy_lints/src/len_zero.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index dc55721eb299..177c85adde58 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -191,10 +191,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte } let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { - if cx - .access_levels - .is_exported(is_empty.id.hir_id) - { + if cx.access_levels.is_exported(is_empty.id.hir_id) { return; } else { "a private"