|
1 | 1 | use crate::imports::ImportKind;
|
2 |
| -use crate::NameBinding; |
3 | 2 | use crate::NameBindingKind;
|
4 | 3 | use crate::Resolver;
|
5 | 4 | use rustc_ast::ast;
|
@@ -50,37 +49,29 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
|
50 | 49 | if !module_level.is_some() {
|
51 | 50 | return;
|
52 | 51 | }
|
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, .. } = |
59 | 64 | binding.kind
|
60 | 65 | {
|
61 |
| - this.set_access_level(import.id, access_level); |
| 66 | + self.set_access_level(import.id, access_level); |
62 | 67 | 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); |
65 | 70 | }
|
66 |
| - |
| 71 | + binding = next_binding; |
67 | 72 | access_level = Some(AccessLevel::Exported);
|
68 |
| - binding = nested_binding; |
69 | 73 | }
|
70 |
| - }; |
71 | 74 |
|
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 |
| - }; |
84 | 75 | if let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) {
|
85 | 76 | self.set_access_level_def_id(def_id, access_level);
|
86 | 77 | }
|
|
0 commit comments