Fix cross-crate glob privacy handling

This commit is contained in:
Florian Diebold 2019-12-26 16:31:38 +01:00
parent 78111620a3
commit 04cf98f8a6
3 changed files with 28 additions and 6 deletions

View file

@ -378,12 +378,7 @@ where
.resolutions()
// only keep visible names...
.map(|(n, res)| {
(
n,
res.filter_visibility(|v| {
v.visible_from_def_map(&self.def_map, module_id)
}),
)
(n, res.filter_visibility(|v| v.visible_from_other_crate()))
})
.filter(|(_, res)| !res.is_none())
.collect::<Vec<_>>();

View file

@ -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]
fn glob_enum() {
covers!(glob_enum);

View file

@ -99,6 +99,13 @@ impl Visibility {
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(
self,
def_map: &crate::nameres::CrateDefMap,