Skip to content

Commit

Permalink
Addressed PR reviews regarding code style
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Aug 12, 2021
1 parent e67c25d commit 8465ba8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 7 additions & 8 deletions clippy_lints/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
7 changes: 1 addition & 6 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8465ba8

Please sign in to comment.