mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Fix cross-crate glob privacy handling
This commit is contained in:
parent
78111620a3
commit
04cf98f8a6
3 changed files with 28 additions and 6 deletions
|
@ -378,12 +378,7 @@ where
|
||||||
.resolutions()
|
.resolutions()
|
||||||
// only keep visible names...
|
// only keep visible names...
|
||||||
.map(|(n, res)| {
|
.map(|(n, res)| {
|
||||||
(
|
(n, res.filter_visibility(|v| v.visible_from_other_crate()))
|
||||||
n,
|
|
||||||
res.filter_visibility(|v| {
|
|
||||||
v.visible_from_def_map(&self.def_map, module_id)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.filter(|(_, res)| !res.is_none())
|
.filter(|(_, res)| !res.is_none())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
@ -169,6 +169,26 @@ fn glob_across_crates() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn glob_privacy_across_crates() {
|
||||||
|
covers!(glob_across_crates);
|
||||||
|
let map = def_map(
|
||||||
|
"
|
||||||
|
//- /main.rs crate:main deps:test_crate
|
||||||
|
use test_crate::*;
|
||||||
|
|
||||||
|
//- /lib.rs crate:test_crate
|
||||||
|
pub struct Baz;
|
||||||
|
struct Foo;
|
||||||
|
",
|
||||||
|
);
|
||||||
|
assert_snapshot!(map, @r###"
|
||||||
|
⋮crate
|
||||||
|
⋮Baz: t v
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn glob_enum() {
|
fn glob_enum() {
|
||||||
covers!(glob_enum);
|
covers!(glob_enum);
|
||||||
|
|
|
@ -99,6 +99,13 @@ impl Visibility {
|
||||||
self.visible_from_def_map(&def_map, from_module.local_id)
|
self.visible_from_def_map(&def_map, from_module.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn visible_from_other_crate(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Visibility::Module(_) => false,
|
||||||
|
Visibility::Public => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn visible_from_def_map(
|
pub(crate) fn visible_from_def_map(
|
||||||
self,
|
self,
|
||||||
def_map: &crate::nameres::CrateDefMap,
|
def_map: &crate::nameres::CrateDefMap,
|
||||||
|
|
Loading…
Reference in a new issue