Skip to content

Commit 0d2e73a

Browse files
committed
fmt
1 parent a9e21a3 commit 0d2e73a

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

compiler/rustc_middle/src/middle/privacy.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A pass that checks to make sure private fields and methods aren't used
22
//! outside their scopes. This pass will also generate a set of exported items
33
//! which are available for use externally when compiled as a library.
4-
use crate::ty::{Visibility, DefIdTree};
4+
use crate::ty::{DefIdTree, Visibility};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_macros::HashStable;
@@ -60,7 +60,12 @@ impl EffectiveVisibility {
6060
}
6161

6262
pub fn nearest_available(&self, tag: AccessLevel) -> Option<Visibility> {
63-
for level in [AccessLevel::ReachableFromImplTrait, AccessLevel::Reachable, AccessLevel::Exported, AccessLevel::Public] {
63+
for level in [
64+
AccessLevel::ReachableFromImplTrait,
65+
AccessLevel::Reachable,
66+
AccessLevel::Exported,
67+
AccessLevel::Public,
68+
] {
6469
if (level <= tag) && self.get(tag).is_some() {
6570
return self.get(tag).cloned();
6671
}

compiler/rustc_resolve/src/access_levels.rs

+38-13
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,31 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
5656
if this.r.opt_local_def_id(import.id).is_some() {
5757
let vis = match binding.vis {
5858
Visibility::Public => Visibility::Public,
59-
Visibility::Restricted(id) => Visibility::Restricted(id.expect_local())
59+
Visibility::Restricted(id) => Visibility::Restricted(id.expect_local()),
6060
};
61-
this.update_effective_vis(this.r.local_def_id(import.id), vis, parent_id, AccessLevel::Exported);
61+
this.update_effective_vis(
62+
this.r.local_def_id(import.id),
63+
vis,
64+
parent_id,
65+
AccessLevel::Exported,
66+
);
6267
if let ImportKind::Single { additional_ids, .. } = import.kind {
63-
6468
if let Some(id) = this.r.opt_local_def_id(additional_ids.0) {
65-
this.update_effective_vis(id, vis, parent_id, AccessLevel::Exported);
69+
this.update_effective_vis(
70+
id,
71+
vis,
72+
parent_id,
73+
AccessLevel::Exported,
74+
);
6675
}
6776

6877
if let Some(id) = this.r.opt_local_def_id(additional_ids.1) {
69-
this.update_effective_vis(id, vis, parent_id, AccessLevel::Exported);
78+
this.update_effective_vis(
79+
id,
80+
vis,
81+
parent_id,
82+
AccessLevel::Exported,
83+
);
7084
}
7185
}
7286

@@ -76,8 +90,8 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
7690
}
7791
};
7892

79-
let module = self.r.get_module(module_id.to_def_id()).unwrap();
80-
let resolutions = self.r.resolutions(module);
93+
let module = self.r.get_module(module_id.to_def_id()).unwrap();
94+
let resolutions = self.r.resolutions(module);
8195

8296
for (.., name_resolution) in resolutions.borrow().iter() {
8397
if let Some(binding) = name_resolution.borrow().binding() {
@@ -87,8 +101,8 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
87101
set_import_binding_access_level(self, binding, module_id);
88102
}
89103
AccessLevel::Exported
90-
},
91-
false => AccessLevel::Public
104+
}
105+
false => AccessLevel::Public,
92106
};
93107

94108
if let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) && !binding.is_ambiguity(){
@@ -110,7 +124,8 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
110124
tag: AccessLevel,
111125
) {
112126
if let Some(inherited_effective_vis) = self.r.access_levels.get_effective_vis(module_id) {
113-
let mut current_effective_vis = self.r.access_levels.get_effective_vis(current_id).copied().unwrap_or_default();
127+
let mut current_effective_vis =
128+
self.r.access_levels.get_effective_vis(current_id).copied().unwrap_or_default();
114129
let current_effective_vis_copy = current_effective_vis.clone();
115130
for level in [
116131
AccessLevel::Public,
@@ -119,11 +134,16 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
119134
AccessLevel::ReachableFromImplTrait,
120135
] {
121136
if level <= tag {
122-
let nearest_available_vis = inherited_effective_vis.nearest_available(level).unwrap();
137+
let nearest_available_vis =
138+
inherited_effective_vis.nearest_available(level).unwrap();
123139
let calculated_effective_vis = match current_vis {
124140
Visibility::Public => nearest_available_vis,
125141
Visibility::Restricted(_) => {
126-
if current_vis.is_at_least(nearest_available_vis, &*self.r) {nearest_available_vis} else {current_vis}
142+
if current_vis.is_at_least(nearest_available_vis, &*self.r) {
143+
nearest_available_vis
144+
} else {
145+
current_vis
146+
}
127147
}
128148
};
129149
current_effective_vis.update(calculated_effective_vis, level, &*self.r);
@@ -169,7 +189,12 @@ impl<'r, 'ast> Visitor<'ast> for AccessLevelsVisitor<'ast, 'r> {
169189
// Foreign modules inherit level from parents.
170190
ast::ItemKind::ForeignMod(..) => {
171191
let parent_id = self.r.local_parent(def_id);
172-
self.update_effective_vis(def_id, Visibility::Public, parent_id, AccessLevel::Public);
192+
self.update_effective_vis(
193+
def_id,
194+
Visibility::Public,
195+
parent_id,
196+
AccessLevel::Public,
197+
);
173198
}
174199

175200
// Only exported `macro_rules!` items are public, but they always are

0 commit comments

Comments
 (0)