Skip to content

Commit 26eeeee

Browse files
committed
Auto merge of rust-lang#102233 - petrochenkov:effvis, r=jackh726
privacy: Rename "accessibility levels" to "effective visibilities" And a couple of other naming and comment tweaks. Related to rust-lang#48054 For `enum Level` I initially used naming `enum EffectiveVisibilityLevel`, but it was too long and inconvenient because it's used pretty often. So I shortened it to just `Level`, if it needs to be used from some context where this name would be ambiguous, then it can be imported with renaming like `use rustc_middle::privacy::Level as EffVisLevel` or something.
2 parents 678e675 + 45c000b commit 26eeeee

18 files changed

+32
-32
lines changed

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn lint_for_missing_headers<'tcx>(
345345
body_id: Option<hir::BodyId>,
346346
panic_span: Option<Span>,
347347
) {
348-
if !cx.access_levels.is_exported(def_id) {
348+
if !cx.effective_visibilities.is_exported(def_id) {
349349
return; // Private functions do not require doc comments
350350
}
351351

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl LateLintPass<'_> for EnumVariantNames {
296296
}
297297
}
298298
if let ItemKind::Enum(ref def, _) = item.kind {
299-
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id.def_id)) {
299+
if !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(item.def_id.def_id)) {
300300
check_variant(cx, self.threshold, def, item_name, item.span);
301301
}
302302
}

clippy_lints/src/exhaustive_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7373
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
7474
if_chain! {
7575
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
76-
if cx.access_levels.is_exported(item.def_id.def_id);
76+
if cx.effective_visibilities.is_exported(item.def_id.def_id);
7777
let attrs = cx.tcx.hir().attrs(item.hir_id());
7878
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
7979
then {

clippy_lints/src/functions/must_use.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
2424
let attrs = cx.tcx.hir().attrs(item.hir_id());
2525
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
2626
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
27-
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
27+
let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id);
2828
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2929
if let Some(attr) = attr {
3030
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
@@ -44,7 +44,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
4444

4545
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
4646
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
47-
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
47+
let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id);
4848
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4949
let attrs = cx.tcx.hir().attrs(item.hir_id());
5050
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
@@ -67,7 +67,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
6767

6868
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
6969
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
70-
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
70+
let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id);
7171
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
7272

7373
let attrs = cx.tcx.hir().attrs(item.hir_id());
@@ -137,7 +137,7 @@ fn check_must_use_candidate<'tcx>(
137137
|| mutates_static(cx, body)
138138
|| in_external_macro(cx.sess(), item_span)
139139
|| returns_unit(decl)
140-
|| !cx.access_levels.is_exported(item_id)
140+
|| !cx.effective_visibilities.is_exported(item_id)
141141
|| is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id)))
142142
{
143143
return;

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn check_raw_ptr<'tcx>(
4242
body: &'tcx hir::Body<'tcx>,
4343
def_id: LocalDefId,
4444
) {
45-
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) {
45+
if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) {
4646
let raw_ptrs = iter_input_pats(decl, body)
4747
.filter_map(|arg| raw_ptr_arg(cx, arg))
4848
.collect::<HirIdSet>();

clippy_lints/src/functions/result.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l
3636
if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
3737
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span)
3838
{
39-
if cx.access_levels.is_exported(item.def_id.def_id) {
39+
if cx.effective_visibilities.is_exported(item.def_id.def_id) {
4040
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4141
check_result_unit_err(cx, err_ty, fn_header_span);
4242
}
@@ -50,7 +50,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem
5050
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span)
5151
&& trait_ref_of_method(cx, item.def_id.def_id).is_none()
5252
{
53-
if cx.access_levels.is_exported(item.def_id.def_id) {
53+
if cx.effective_visibilities.is_exported(item.def_id.def_id) {
5454
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
5555
check_result_unit_err(cx, err_ty, fn_header_span);
5656
}
@@ -62,7 +62,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitIt
6262
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
6363
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
6464
if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) {
65-
if cx.access_levels.is_exported(item.def_id.def_id) {
65+
if cx.effective_visibilities.is_exported(item.def_id.def_id) {
6666
check_result_unit_err(cx, err_ty, fn_header_span);
6767
}
6868
check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold);

clippy_lints/src/implicit_hasher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
111111
}
112112
}
113113

114-
if !cx.access_levels.is_exported(item.def_id.def_id) {
114+
if !cx.effective_visibilities.is_exported(item.def_id.def_id) {
115115
return;
116116
}
117117

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
134134
if item.ident.name == sym::len;
135135
if let ImplItemKind::Fn(sig, _) = &item.kind;
136136
if sig.decl.implicit_self.has_implicit_self();
137-
if cx.access_levels.is_exported(item.def_id.def_id);
137+
if cx.effective_visibilities.is_exported(item.def_id.def_id);
138138
if matches!(sig.decl.output, FnRetTy::Return(_));
139139
if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id());
140140
if imp.of_trait.is_none();
@@ -210,7 +210,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
210210
}
211211
}
212212

213-
if cx.access_levels.is_exported(visited_trait.def_id.def_id)
213+
if cx.effective_visibilities.is_exported(visited_trait.def_id.def_id)
214214
&& trait_items.iter().any(|i| is_named_self(cx, i, sym::len))
215215
{
216216
let mut current_and_super_traits = DefIdSet::default();
@@ -331,7 +331,7 @@ fn check_for_is_empty<'tcx>(
331331
None,
332332
None,
333333
),
334-
Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => (
334+
Some(is_empty) if !cx.effective_visibilities.is_exported(is_empty.def_id.expect_local()) => (
335335
format!(
336336
"{item_kind} `{}` has a public `len` method, but a private `is_empty` method",
337337
item_name.as_str(),

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,7 +3258,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
32583258
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
32593259
let first_arg_ty_opt = method_sig.inputs().iter().next().copied();
32603260
// if this impl block implements a trait, lint in trait definition instead
3261-
if !implements_trait && cx.access_levels.is_exported(impl_item.def_id.def_id) {
3261+
if !implements_trait && cx.effective_visibilities.is_exported(impl_item.def_id.def_id) {
32623262
// check missing trait implementations
32633263
for method_config in &TRAIT_METHODS {
32643264
if name == method_config.method_name
@@ -3292,7 +3292,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
32923292

32933293
if sig.decl.implicit_self.has_implicit_self()
32943294
&& !(self.avoid_breaking_exported_api
3295-
&& cx.access_levels.is_exported(impl_item.def_id.def_id))
3295+
&& cx.effective_visibilities.is_exported(impl_item.def_id.def_id))
32963296
&& let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next()
32973297
&& let Some(first_arg_ty) = first_arg_ty_opt
32983298
{

clippy_lints/src/missing_inline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
8888
return;
8989
}
9090

91-
if !cx.access_levels.is_exported(it.def_id.def_id) {
91+
if !cx.effective_visibilities.is_exported(it.def_id.def_id) {
9292
return;
9393
}
9494
match it.kind {
@@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
142142
}
143143

144144
// If the item being implemented is not exported, then we don't need #[inline]
145-
if !cx.access_levels.is_exported(impl_item.def_id.def_id) {
145+
if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) {
146146
return;
147147
}
148148

@@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
159159
};
160160

161161
if let Some(trait_def_id) = trait_def_id {
162-
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id.def_id) {
162+
if trait_def_id.is_local() && !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) {
163163
// If a trait is being implemented for an item, and the
164164
// trait is not exported, we don't need #[inline]
165165
return;

clippy_lints/src/new_without_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
9696
if_chain! {
9797
if sig.decl.inputs.is_empty();
9898
if name == sym::new;
99-
if cx.access_levels.is_reachable(impl_item.def_id.def_id);
99+
if cx.effective_visibilities.is_reachable(impl_item.def_id.def_id);
100100
let self_def_id = cx.tcx.hir().get_parent_item(id);
101101
let self_ty = cx.tcx.type_of(self_def_id);
102102
if self_ty == return_ty(cx, id);

clippy_lints/src/pass_by_ref_or_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'tcx> PassByRefOrValue {
139139
}
140140

141141
fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, def_id: LocalDefId, decl: &FnDecl<'_>, span: Option<Span>) {
142-
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
142+
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) {
143143
return;
144144
}
145145

clippy_lints/src/redundant_pub_crate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
4747
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
4848
if_chain! {
4949
if cx.tcx.visibility(item.def_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id());
50-
if !cx.access_levels.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false);
50+
if !cx.effective_visibilities.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false);
5151
if is_not_macro_export(item);
5252
then {
5353
let span = item.span.with_hi(item.ident.span.hi());
@@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
7070
}
7171

7272
if let ItemKind::Mod { .. } = item.kind {
73-
self.is_exported.push(cx.access_levels.is_exported(item.def_id.def_id));
73+
self.is_exported.push(cx.effective_visibilities.is_exported(item.def_id.def_id));
7474
}
7575
}
7676

clippy_lints/src/return_self_not_must_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa
7474
if !in_external_macro(cx.sess(), span);
7575
if decl.implicit_self.has_implicit_self();
7676
// We only show this warning for public exported methods.
77-
if cx.access_levels.is_exported(fn_def);
77+
if cx.effective_visibilities.is_exported(fn_def);
7878
// We don't want to emit this lint if the `#[must_use]` attribute is already there.
7979
if !cx.tcx.hir().attrs(hir_id).iter().any(|attr| attr.has_name(sym::must_use));
8080
if cx.tcx.visibility(fn_def.to_def_id()).is_public();

clippy_lints/src/types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
319319
false
320320
};
321321

322-
let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id));
322+
let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(id));
323323

324324
self.check_fn_decl(
325325
cx,
@@ -333,7 +333,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
333333
}
334334

335335
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
336-
let is_exported = cx.access_levels.is_exported(item.def_id.def_id);
336+
let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id);
337337

338338
match item.kind {
339339
ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty(
@@ -379,7 +379,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
379379
}
380380

381381
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
382-
let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(field.hir_id));
382+
let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(field.hir_id));
383383

384384
self.check_ty(
385385
cx,
@@ -392,7 +392,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
392392
}
393393

394394
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) {
395-
let is_exported = cx.access_levels.is_exported(item.def_id.def_id);
395+
let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id);
396396

397397
let context = CheckTyContext {
398398
is_exported,

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
8383
match fn_kind {
8484
FnKind::ItemFn(..) | FnKind::Method(..) => {
8585
let def_id = cx.tcx.hir().local_def_id(hir_id);
86-
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
86+
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) {
8787
return;
8888
}
8989
},

clippy_lints/src/unused_self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
6161
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
6262
if assoc_item.fn_has_self_parameter;
6363
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
64-
if !cx.access_levels.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api;
64+
if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api;
6565
let body = cx.tcx.hir().body(*body_id);
6666
if let [self_param, ..] = body.params;
6767
if !is_local_used(cx, body, self_param.pat.hir_id);

clippy_lints/src/upper_case_acronyms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
105105
fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) {
106106
// do not lint public items or in macros
107107
if in_external_macro(cx.sess(), it.span)
108-
|| (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id.def_id))
108+
|| (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.def_id.def_id))
109109
{
110110
return;
111111
}

0 commit comments

Comments
 (0)