Skip to content

Commit 8465ba8

Browse files
committed
Addressed PR reviews regarding code style
1 parent e67c25d commit 8465ba8

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

clippy_lints/src/types/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mod type_complexity;
99
mod utils;
1010
mod vec_box;
1111

12-
use clippy_utils::is_item_exported;
1312
use rustc_hir as hir;
1413
use rustc_hir::intravisit::FnKind;
1514
use rustc_hir::{
@@ -310,7 +309,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
310309
false
311310
};
312311

313-
let is_exported = is_item_exported(cx, id.owner);
312+
let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id));
314313

315314
self.check_fn_decl(
316315
cx,
@@ -324,7 +323,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
324323
}
325324

326325
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
327-
let is_exported = is_item_exported(cx, item.def_id);
326+
let is_exported = cx.access_levels.is_exported(item.def_id);
328327

329328
match item.kind {
330329
ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty(
@@ -356,7 +355,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
356355
}
357356

358357
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
359-
let is_exported = is_item_exported(cx, field.hir_id.owner) && field.vis.node.is_pub();
358+
let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(field.hir_id));
360359

361360
self.check_ty(
362361
cx,
@@ -368,8 +367,8 @@ impl<'tcx> LateLintPass<'tcx> for Types {
368367
);
369368
}
370369

371-
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
372-
let is_exported = is_item_exported(cx, item.def_id);
370+
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) {
371+
let is_exported = cx.access_levels.is_exported(item.def_id);
373372

374373
let context = CheckTyContext {
375374
is_exported,
@@ -441,7 +440,7 @@ impl Types {
441440
let hir_id = hir_ty.hir_id;
442441
let res = cx.qpath_res(qpath, hir_id);
443442
if let Some(def_id) = res.opt_def_id() {
444-
if self.does_api_allow_change(context) {
443+
if self.is_type_change_allowed(context) {
445444
// All lints that are being checked in this block are guarded by
446445
// the `avoid_breaking_exported_api` configuration. When adding a
447446
// new lint, please also add the name to the configuration documentation
@@ -528,7 +527,7 @@ impl Types {
528527

529528
/// This function checks if the type is allowed to change in the current context
530529
/// based on the `avoid_breaking_exported_api` configuration
531-
fn does_api_allow_change(&self, context: CheckTyContext) -> bool {
530+
fn is_type_change_allowed(&self, context: CheckTyContext) -> bool {
532531
!(context.is_exported && self.avoid_breaking_exported_api)
533532
}
534533
}

clippy_utils/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind};
6666
use rustc_data_structures::unhash::UnhashMap;
6767
use rustc_hir as hir;
6868
use rustc_hir::def::{DefKind, Res};
69-
use rustc_hir::def_id::{DefId, LocalDefId};
69+
use rustc_hir::def_id::DefId;
7070
use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor};
7171
use rustc_hir::LangItem::{ResultErr, ResultOk};
7272
use rustc_hir::{
@@ -135,11 +135,6 @@ macro_rules! extract_msrv_attr {
135135
};
136136
}
137137

138-
// Returns true if the given item behind the `def_id` is accessible to other crates.
139-
pub fn is_item_exported(cx: &LateContext<'_>, def_id: LocalDefId) -> bool {
140-
cx.access_levels.is_exported(def_id)
141-
}
142-
143138
/// Returns `true` if the two spans come from differing expansions (i.e., one is
144139
/// from a macro and one isn't).
145140
#[must_use]

0 commit comments

Comments
 (0)