mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-30 11:37:31 +00:00
fix: Prevent public reexport of private item
This commit is contained in:
parent
f9935be013
commit
685fe4b8dc
4 changed files with 98 additions and 9 deletions
|
|
@ -191,6 +191,11 @@ impl Visibility {
|
|||
return None;
|
||||
}
|
||||
|
||||
let def_block = def_map.block_id();
|
||||
if (mod_a.containing_block(), mod_b.containing_block()) != (def_block, def_block) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut a_ancestors =
|
||||
iter::successors(Some(mod_a.local_id), |&m| def_map[m].parent);
|
||||
let mut b_ancestors =
|
||||
|
|
@ -210,6 +215,43 @@ impl Visibility {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the least permissive visibility of `self` and `other`.
|
||||
///
|
||||
/// If there is no subset relation between `self` and `other`, returns `None` (ie. they're only
|
||||
/// visible in unrelated modules).
|
||||
pub(crate) fn min(self, other: Visibility, def_map: &DefMap) -> Option<Visibility> {
|
||||
match (self, other) {
|
||||
(vis, Visibility::Public) | (Visibility::Public, vis) => Some(vis),
|
||||
(Visibility::Module(mod_a, expl_a), Visibility::Module(mod_b, expl_b)) => {
|
||||
if mod_a.krate != mod_b.krate {
|
||||
return None;
|
||||
}
|
||||
|
||||
let def_block = def_map.block_id();
|
||||
if (mod_a.containing_block(), mod_b.containing_block()) != (def_block, def_block) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut a_ancestors =
|
||||
iter::successors(Some(mod_a.local_id), |&m| def_map[m].parent);
|
||||
let mut b_ancestors =
|
||||
iter::successors(Some(mod_b.local_id), |&m| def_map[m].parent);
|
||||
|
||||
if a_ancestors.any(|m| m == mod_b.local_id) {
|
||||
// B is above A
|
||||
return Some(Visibility::Module(mod_a, expl_b));
|
||||
}
|
||||
|
||||
if b_ancestors.any(|m| m == mod_a.local_id) {
|
||||
// A is above B
|
||||
return Some(Visibility::Module(mod_b, expl_a));
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the item was imported through an explicit `pub(crate) use` or just a `use` without
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue