diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 483ff10bb198..9588de8459cf 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -9,7 +9,6 @@ mod type_complexity; mod utils; mod vec_box; -use clippy_utils::is_item_exported; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{ @@ -310,7 +309,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { false }; - let is_exported = is_item_exported(cx, id.owner); + let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id)); self.check_fn_decl( cx, @@ -324,7 +323,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - let is_exported = is_item_exported(cx, item.def_id); + let is_exported = cx.access_levels.is_exported(item.def_id); match item.kind { ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( @@ -356,7 +355,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { - let is_exported = is_item_exported(cx, field.hir_id.owner) && field.vis.node.is_pub(); + let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(field.hir_id)); self.check_ty( cx, @@ -368,8 +367,8 @@ impl<'tcx> LateLintPass<'tcx> for Types { ); } - fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { - let is_exported = is_item_exported(cx, item.def_id); + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) { + let is_exported = cx.access_levels.is_exported(item.def_id); let context = CheckTyContext { is_exported, @@ -441,7 +440,7 @@ impl Types { let hir_id = hir_ty.hir_id; let res = cx.qpath_res(qpath, hir_id); if let Some(def_id) = res.opt_def_id() { - if self.does_api_allow_change(context) { + if self.is_type_change_allowed(context) { // All lints that are being checked in this block are guarded by // the `avoid_breaking_exported_api` configuration. When adding a // new lint, please also add the name to the configuration documentation @@ -528,7 +527,7 @@ impl Types { /// This function checks if the type is allowed to change in the current context /// based on the `avoid_breaking_exported_api` configuration - fn does_api_allow_change(&self, context: CheckTyContext) -> bool { + fn is_type_change_allowed(&self, context: CheckTyContext) -> bool { !(context.is_exported && self.avoid_breaking_exported_api) } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 746460a3a277..1d59d6bfea1b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -66,7 +66,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind}; use rustc_data_structures::unhash::UnhashMap; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::LangItem::{ResultErr, ResultOk}; use rustc_hir::{ @@ -135,11 +135,6 @@ macro_rules! extract_msrv_attr { }; } -// Returns true if the given item behind the `def_id` is accessible to other crates. -pub fn is_item_exported(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { - cx.access_levels.is_exported(def_id) -} - /// Returns `true` if the two spans come from differing expansions (i.e., one is /// from a macro and one isn't). #[must_use]