Skip to content

Commit 155cb7e

Browse files
committed
WIP
1 parent cba4a38 commit 155cb7e

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

compiler/rustc_resolve/src/access_levels.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::imports::ImportKind;
2-
use crate::NameBinding;
32
use crate::NameBindingKind;
43
use crate::Resolver;
54
use rustc_ast::ast;
@@ -50,37 +49,29 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
5049
if !module_level.is_some() {
5150
return;
5251
}
53-
// Set the given binding access level to `AccessLevel::Public` and
54-
// sets the rest of the `use` chain to `AccessLevel::Exported` until
55-
// we hit the actual exported item.
56-
let set_import_binding_access_level =
57-
|this: &mut Self, mut binding: &NameBinding<'a>, mut access_level| {
58-
while let NameBindingKind::Import { binding: nested_binding, import, .. } =
52+
53+
let module = self.r.get_module(module_id.to_def_id()).unwrap();
54+
let resolutions = self.r.resolutions(module);
55+
56+
for (.., name_resolution) in resolutions.borrow().iter() {
57+
if let Some(mut binding) = name_resolution.borrow().binding() && binding.vis.is_public() && !binding.is_ambiguity()
58+
{
59+
// Set the given binding access level to `AccessLevel::Public` and
60+
// sets the rest of the `use` chain to `AccessLevel::Exported` until
61+
// we hit the actual exported item.
62+
let mut access_level = module_level;
63+
while let NameBindingKind::Import { binding: next_binding, import, .. } =
5964
binding.kind
6065
{
61-
this.set_access_level(import.id, access_level);
66+
self.set_access_level(import.id, access_level);
6267
if let ImportKind::Single { additional_ids, .. } = import.kind {
63-
this.set_access_level(additional_ids.0, access_level);
64-
this.set_access_level(additional_ids.1, access_level);
68+
self.set_access_level(additional_ids.0, access_level);
69+
self.set_access_level(additional_ids.1, access_level);
6570
}
66-
71+
binding = next_binding;
6772
access_level = Some(AccessLevel::Exported);
68-
binding = nested_binding;
6973
}
70-
};
7174

72-
let module = self.r.get_module(module_id.to_def_id()).unwrap();
73-
let resolutions = self.r.resolutions(module);
74-
75-
for (.., name_resolution) in resolutions.borrow().iter() {
76-
if let Some(binding) = name_resolution.borrow().binding() && binding.vis.is_public() && !binding.is_ambiguity() {
77-
let access_level = match binding.is_import() {
78-
true => {
79-
set_import_binding_access_level(self, binding, module_level);
80-
Some(AccessLevel::Exported)
81-
},
82-
false => module_level,
83-
};
8475
if let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) {
8576
self.set_access_level_def_id(def_id, access_level);
8677
}

0 commit comments

Comments
 (0)