Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/nameres/collector.rs4
-rw-r--r--crates/hir-def/src/nameres/path_resolution.rs7
-rw-r--r--crates/hir-def/src/nameres/tests/globs.rs30
3 files changed, 41 insertions, 0 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 9ffc218818..b0dd01f9db 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -212,6 +212,7 @@ impl Import {
#[derive(Debug, Eq, PartialEq)]
struct ImportDirective {
+ /// The module this import directive is in.
module_id: LocalModuleId,
import: Import,
status: PartialResolvedImport,
@@ -963,8 +964,10 @@ impl DefCollector<'_> {
fn update(
&mut self,
+ // The module for which `resolutions` have been resolve
module_id: LocalModuleId,
resolutions: &[(Option<Name>, PerNs)],
+ // Visibility this import will have
vis: Visibility,
import_type: ImportType,
) {
@@ -974,6 +977,7 @@ impl DefCollector<'_> {
fn update_recursive(
&mut self,
+ // The module for which `resolutions` have been resolve
module_id: LocalModuleId,
resolutions: &[(Option<Name>, PerNs)],
// All resolutions are imported with this visibility; the visibilities in
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs
index 8dfda6df64..20d39ec6cb 100644
--- a/crates/hir-def/src/nameres/path_resolution.rs
+++ b/crates/hir-def/src/nameres/path_resolution.rs
@@ -73,7 +73,10 @@ impl DefMap {
pub(crate) fn resolve_visibility(
&self,
db: &dyn DefDatabase,
+ // module to import to
original_module: LocalModuleId,
+ // pub(path)
+ // ^^^^ this
visibility: &RawVisibility,
) -> Option<Visibility> {
let mut vis = match visibility {
@@ -115,6 +118,7 @@ impl DefMap {
&self,
db: &dyn DefDatabase,
mode: ResolveMode,
+ // module to import to
mut original_module: LocalModuleId,
path: &ModPath,
shadow: BuiltinShadowMode,
@@ -361,6 +365,9 @@ impl DefMap {
);
}
};
+
+ curr_per_ns = curr_per_ns
+ .filter_visibility(|vis| vis.is_visible_from_def_map(db, self, original_module));
}
ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None, Some(self.krate))
diff --git a/crates/hir-def/src/nameres/tests/globs.rs b/crates/hir-def/src/nameres/tests/globs.rs
index b2a6a592cf..84d14e3b92 100644
--- a/crates/hir-def/src/nameres/tests/globs.rs
+++ b/crates/hir-def/src/nameres/tests/globs.rs
@@ -336,3 +336,33 @@ mod d {
"#]],
);
}
+
+#[test]
+fn glob_name_collision_check_visibility() {
+ check(
+ r#"
+mod event {
+ mod serenity {
+ pub fn Event() {}
+ }
+ use serenity::*;
+
+ pub struct Event {}
+}
+
+use event::Event;
+ "#,
+ expect![[r#"
+ crate
+ Event: t
+ event: t
+
+ crate::event
+ Event: t v
+ serenity: t
+
+ crate::event::serenity
+ Event: v
+ "#]],
+ );
+}