diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres/path_resolution.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 695014c7b..d88076aa7 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs | |||
@@ -21,6 +21,7 @@ use crate::{ | |||
21 | nameres::{BuiltinShadowMode, CrateDefMap}, | 21 | nameres::{BuiltinShadowMode, CrateDefMap}, |
22 | path::{ModPath, PathKind}, | 22 | path::{ModPath, PathKind}, |
23 | per_ns::PerNs, | 23 | per_ns::PerNs, |
24 | visibility::{ResolvedVisibility, Visibility}, | ||
24 | AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, | 25 | AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, |
25 | }; | 26 | }; |
26 | 27 | ||
@@ -64,6 +65,32 @@ impl CrateDefMap { | |||
64 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) | 65 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) |
65 | } | 66 | } |
66 | 67 | ||
68 | pub(crate) fn resolve_visibility( | ||
69 | &self, | ||
70 | db: &impl DefDatabase, | ||
71 | original_module: LocalModuleId, | ||
72 | visibility: &Visibility, | ||
73 | ) -> Option<ResolvedVisibility> { | ||
74 | match visibility { | ||
75 | Visibility::Module(path) => { | ||
76 | let (result, remaining) = | ||
77 | self.resolve_path(db, original_module, &path, BuiltinShadowMode::Module); | ||
78 | if remaining.is_some() { | ||
79 | return None; | ||
80 | } | ||
81 | let types = result.take_types()?; | ||
82 | match types { | ||
83 | ModuleDefId::ModuleId(m) => Some(ResolvedVisibility::Module(m)), | ||
84 | _ => { | ||
85 | // error: visibility needs to refer to module | ||
86 | None | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | Visibility::Public => Some(ResolvedVisibility::Public), | ||
91 | } | ||
92 | } | ||
93 | |||
67 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change | 94 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change |
68 | // the result. | 95 | // the result. |
69 | pub(super) fn resolve_path_fp_with_macro( | 96 | pub(super) fn resolve_path_fp_with_macro( |