aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/db.rs10
-rw-r--r--crates/hir_ty/src/lower.rs27
-rw-r--r--crates/hir_ty/src/method_resolution.rs2
3 files changed, 5 insertions, 34 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index b1d22a9f9..91a2e0b5b 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -4,8 +4,8 @@ use std::sync::Arc;
4 4
5use base_db::{impl_intern_key, salsa, CrateId, Upcast}; 5use base_db::{impl_intern_key, salsa, CrateId, Upcast};
6use hir_def::{ 6use hir_def::{
7 db::DefDatabase, expr::ExprId, visibility::Visibility, ConstParamId, DefWithBodyId, FunctionId, 7 db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId,
8 GenericDefId, ImplId, LocalFieldId, TypeParamId, VariantId, 8 LocalFieldId, TypeParamId, VariantId,
9}; 9};
10use la_arena::ArenaMap; 10use la_arena::ArenaMap;
11 11
@@ -128,12 +128,6 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
128 krate: CrateId, 128 krate: CrateId,
129 env: chalk_ir::Environment<chalk::Interner>, 129 env: chalk_ir::Environment<chalk::Interner>,
130 ) -> chalk_ir::ProgramClauses<chalk::Interner>; 130 ) -> chalk_ir::ProgramClauses<chalk::Interner>;
131
132 #[salsa::invoke(crate::lower::field_visibilities_query)]
133 fn field_visibilities(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Visibility>>;
134
135 #[salsa::invoke(crate::lower::fn_visibility_query)]
136 fn fn_visibility(&self, def: FunctionId) -> Visibility;
137} 131}
138 132
139fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { 133fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index c4062a41d..cbbb535e5 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -16,10 +16,9 @@ use hir_def::{
16 path::{GenericArg, Path, PathSegment, PathSegments}, 16 path::{GenericArg, Path, PathSegment, PathSegments},
17 resolver::{HasResolver, Resolver, TypeNs}, 17 resolver::{HasResolver, Resolver, TypeNs},
18 type_ref::{TypeBound, TypeRef}, 18 type_ref::{TypeBound, TypeRef},
19 visibility::Visibility,
20 AdtId, AssocContainerId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId, 19 AdtId, AssocContainerId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId,
21 GenericDefId, HasModule, ImplId, LocalFieldId, Lookup, ModuleDefId, StaticId, StructId, 20 GenericDefId, HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId,
22 TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, 21 TypeAliasId, TypeParamId, UnionId, VariantId,
23}; 22};
24use hir_expand::name::Name; 23use hir_expand::name::Name;
25use la_arena::ArenaMap; 24use la_arena::ArenaMap;
@@ -868,28 +867,6 @@ pub(crate) fn field_types_query(
868 Arc::new(res) 867 Arc::new(res)
869} 868}
870 869
871/// Resolve visibility of all specific fields of a struct or union variant.
872pub(crate) fn field_visibilities_query(
873 db: &dyn HirDatabase,
874 variant_id: VariantId,
875) -> Arc<ArenaMap<LocalFieldId, Visibility>> {
876 let def_db = db.upcast();
877 let var_data = variant_data(def_db, variant_id);
878 let resolver = variant_id.module(def_db).resolver(def_db);
879 let mut res = ArenaMap::default();
880 for (field_id, field_data) in var_data.fields().iter() {
881 res.insert(field_id, field_data.visibility.resolve(def_db, &resolver))
882 }
883 Arc::new(res)
884}
885
886/// Resolve visibility of a function.
887pub(crate) fn fn_visibility_query(db: &dyn HirDatabase, def: FunctionId) -> Visibility {
888 let def_db = db.upcast();
889 let resolver = ModuleDefId::from(def).module(def_db).unwrap().resolver(def_db);
890 db.function_data(def).visibility.resolve(def_db, &resolver)
891}
892
893/// This query exists only to be used when resolving short-hand associated types 870/// This query exists only to be used when resolving short-hand associated types
894/// like `T::Item`. 871/// like `T::Item`.
895/// 872///
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index f91208068..54192ec30 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -686,7 +686,7 @@ fn is_valid_candidate(
686 } 686 }
687 } 687 }
688 if let Some(from_module) = visible_from_module { 688 if let Some(from_module) = visible_from_module {
689 if !db.fn_visibility(m).is_visible_from(db.upcast(), from_module) { 689 if !db.function_visibility(m).is_visible_from(db.upcast(), from_module) {
690 cov_mark::hit!(autoderef_candidate_not_visible); 690 cov_mark::hit!(autoderef_candidate_not_visible);
691 return false; 691 return false;
692 } 692 }