|
1 |
| -use crate::NameBindingKind; |
2 |
| -use crate::Resolver; |
| 1 | +use crate::{ImportKind, NameBindingKind, Resolver}; |
3 | 2 | use rustc_ast::ast;
|
4 | 3 | use rustc_ast::visit;
|
5 | 4 | use rustc_ast::visit::Visitor;
|
@@ -45,31 +44,40 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
|
45 | 44 | let module = self.r.get_module(module_id.to_def_id()).unwrap();
|
46 | 45 | let resolutions = self.r.resolutions(module);
|
47 | 46 |
|
48 |
| - for (key, name_resolution) in resolutions.borrow().iter() { |
| 47 | + for (_, name_resolution) in resolutions.borrow().iter() { |
49 | 48 | if let Some(mut binding) = name_resolution.borrow().binding() && !binding.is_ambiguity() {
|
50 | 49 | // Set the given binding access level to `AccessLevel::Public` and
|
51 | 50 | // sets the rest of the `use` chain to `AccessLevel::Exported` until
|
52 | 51 | // we hit the actual exported item.
|
53 | 52 |
|
54 |
| - // FIXME: tag and is_public() condition must be deleted, |
55 |
| - // but assertion fail occurs in import_id_for_ns |
| 53 | + // FIXME: tag and is_public() condition should be removed, but assertions occur. |
56 | 54 | let tag = if binding.is_import() { AccessLevel::Exported } else { AccessLevel::Public };
|
57 | 55 | if binding.vis.is_public() {
|
58 | 56 | let mut prev_parent_id = module_id;
|
59 | 57 | let mut level = AccessLevel::Public;
|
60 | 58 | while let NameBindingKind::Import { binding: nested_binding, import, .. } =
|
61 | 59 | binding.kind
|
62 | 60 | {
|
63 |
| - let id = self.r.local_def_id(self.r.import_id_for_ns(import, key.ns)); |
64 |
| - self.update( |
65 |
| - id, |
| 61 | + let mut update = |node_id| self.update( |
| 62 | + self.r.local_def_id(node_id), |
66 | 63 | binding.vis.expect_local(),
|
67 | 64 | prev_parent_id,
|
68 | 65 | level,
|
69 | 66 | );
|
| 67 | + // In theory all the import IDs have individual visibilities and effective |
| 68 | + // visibilities, but in practice these IDs go straigth to HIR where all |
| 69 | + // their few uses assume that their (effective) visibility applies to the |
| 70 | + // whole syntactic `use` item. So we update them all to the maximum value |
| 71 | + // among the potential individual effective visibilities. Maybe HIR for |
| 72 | + // imports shouldn't use three IDs at all. |
| 73 | + update(import.id); |
| 74 | + if let ImportKind::Single { additional_ids, .. } = import.kind { |
| 75 | + update(additional_ids.0); |
| 76 | + update(additional_ids.1); |
| 77 | + } |
70 | 78 |
|
71 | 79 | level = AccessLevel::Exported;
|
72 |
| - prev_parent_id = id; |
| 80 | + prev_parent_id = self.r.local_def_id(import.id); |
73 | 81 | binding = nested_binding;
|
74 | 82 | }
|
75 | 83 | }
|
|
0 commit comments