diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-28 22:12:45 +0400 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-28 22:12:45 +0400 |
| commit | ede21e8932224f4a51d024c5d6b37189a701f2e4 (patch) | |
| tree | b2fca00aae8ce4a6b658dd3305e772c6b87ccf94 /compiler/rustc_resolve/src/effective_visibilities.rs | |
| parent | 4695ddf510b8cc8727497be4702ed1859bee2cca (diff) | |
| download | rust-ede21e8932224f4a51d024c5d6b37189a701f2e4.tar.gz rust-ede21e8932224f4a51d024c5d6b37189a701f2e4.zip | |
effvis: Merge two similar code paths
Diffstat (limited to 'compiler/rustc_resolve/src/effective_visibilities.rs')
| -rw-r--r-- | compiler/rustc_resolve/src/effective_visibilities.rs | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index a1ae9b8a521..15df577e841 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -125,43 +125,32 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> { for (_, name_resolution) in resolutions.borrow().iter() { if let Some(mut binding) = name_resolution.borrow().binding() { - if !binding.is_ambiguity() { - // Set the given effective visibility level to `Level::Direct` and - // sets the rest of the `use` chain to `Level::Reexported` until - // we hit the actual exported item. - let mut parent_id = ParentId::Def(module_id); - while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind - { - let binding_id = ImportId::new_unchecked(binding); - self.update_import(binding_id, parent_id); - - parent_id = ParentId::Import(binding_id); - binding = nested_binding; - } - - if let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) { - self.update_def(def_id, binding.vis.expect_local(), parent_id); + // Set the given effective visibility level to `Level::Direct` and + // sets the rest of the `use` chain to `Level::Reexported` until + // we hit the actual exported item. + // + // If the binding is ambiguous, put the root ambiguity binding and all reexports + // leading to it into the table. They are used by the `ambiguous_glob_reexports` + // lint. For all bindings added to the table this way `is_ambiguity` returns true. + let mut parent_id = ParentId::Def(module_id); + while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind { + let binding_id = ImportId::new_unchecked(binding); + self.update_import(binding_id, parent_id); + + if binding.ambiguity.is_some() { + // Stop at the root ambiguity, further bindings in the chain should not + // be reexported because the root ambiguity blocks any access to them. + // (Those further bindings are most likely not ambiguities themselves.) + break; } - } else { - // Put the root ambiguity binding and all reexports leading to it into the - // table. They are used by the `ambiguous_glob_reexports` lint. For all - // bindings added to the table here `is_ambiguity` returns true. - let mut parent_id = ParentId::Def(module_id); - while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind - { - let binding_id = ImportId::new_unchecked(binding); - self.update_import(binding_id, parent_id); - if binding.ambiguity.is_some() { - // Stop at the root ambiguity, further bindings in the chain should not - // be reexported because the root ambiguity blocks any access to them. - // (Those further bindings are most likely not ambiguities themselves.) - break; - } + parent_id = ParentId::Import(binding_id); + binding = nested_binding; + } - parent_id = ParentId::Import(binding_id); - binding = nested_binding; - } + if binding.ambiguity.is_none() + && let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) { + self.update_def(def_id, binding.vis.expect_local(), parent_id); } } } |
