mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Merge #2358
2358: Hide data from public API r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
6d42db2e51
7 changed files with 61 additions and 83 deletions
|
@ -22,10 +22,10 @@ use hir_expand::{
|
|||
name::{self, AsName},
|
||||
};
|
||||
use ra_db::{CrateId, Edition};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
db::{DefDatabase, HirDatabase},
|
||||
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
|
||||
ids::{
|
||||
AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
|
||||
|
@ -644,12 +644,8 @@ impl Const {
|
|||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||
db.const_data(self)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
self.data(db).name().cloned()
|
||||
db.const_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||
|
@ -681,45 +677,6 @@ impl Const {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConstData {
|
||||
pub(crate) name: Option<Name>,
|
||||
pub(crate) type_ref: TypeRef,
|
||||
}
|
||||
|
||||
impl ConstData {
|
||||
pub fn name(&self) -> Option<&Name> {
|
||||
self.name.as_ref()
|
||||
}
|
||||
|
||||
pub fn type_ref(&self) -> &TypeRef {
|
||||
&self.type_ref
|
||||
}
|
||||
|
||||
pub(crate) fn const_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Const,
|
||||
) -> Arc<ConstData> {
|
||||
let node = konst.source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
|
||||
pub(crate) fn static_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Static,
|
||||
) -> Arc<ConstData> {
|
||||
let node = konst.source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
}
|
||||
|
||||
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
|
||||
let name = node.name().map(|n| n.as_name());
|
||||
let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
|
||||
let sig = ConstData { name, type_ref };
|
||||
Arc::new(sig)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Static {
|
||||
pub(crate) id: StaticId,
|
||||
|
@ -734,10 +691,6 @@ impl Static {
|
|||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||
db.static_data(self)
|
||||
}
|
||||
|
||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||
db.infer(self.into())
|
||||
}
|
||||
|
|
|
@ -16,15 +16,15 @@ use crate::{
|
|||
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
|
||||
TypeCtor,
|
||||
},
|
||||
Const, ConstData, Crate, DefWithBody, GenericDef, ImplBlock, Module, Static, StructField,
|
||||
Trait,
|
||||
Crate, DefWithBody, GenericDef, ImplBlock, Module, StructField, Trait,
|
||||
};
|
||||
|
||||
pub use hir_def::db::{
|
||||
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
||||
EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery,
|
||||
InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery,
|
||||
StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
|
||||
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, DefDatabase2,
|
||||
DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery,
|
||||
ImplDataQuery, InternDatabase, InternDatabaseStorage, RawItemsQuery,
|
||||
RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
|
||||
TypeAliasDataQuery,
|
||||
};
|
||||
pub use hir_expand::db::{
|
||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||
|
@ -35,12 +35,6 @@ pub use hir_expand::db::{
|
|||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
#[salsa::requires(AstDatabase)]
|
||||
pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
|
||||
#[salsa::invoke(ConstData::const_data_query)]
|
||||
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(ConstData::static_data_query)]
|
||||
fn static_data(&self, konst: Static) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(LangItems::module_lang_items_query)]
|
||||
fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>;
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ pub use crate::{
|
|||
attrs::{AttrDef, HasAttrs},
|
||||
docs::{DocDef, Docs, Documentation},
|
||||
src::{HasBodySource, HasSource},
|
||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||
EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local,
|
||||
MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait,
|
||||
TypeAlias, Union, VariantDef,
|
||||
Adt, AssocItem, Const, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant,
|
||||
FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, MacroDef,
|
||||
Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, TypeAlias,
|
||||
Union, VariantDef,
|
||||
},
|
||||
expr::ExprScopes,
|
||||
from_source::FromSource,
|
||||
|
|
|
@ -22,7 +22,7 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
use hir_def::{
|
||||
data::FunctionData,
|
||||
data::{ConstData, FunctionData},
|
||||
path::known,
|
||||
resolver::{HasResolver, Resolver, TypeNs},
|
||||
type_ref::{Mutability, TypeRef},
|
||||
|
@ -44,8 +44,8 @@ use crate::{
|
|||
db::HirDatabase,
|
||||
expr::{BindingAnnotation, Body, ExprId, PatId},
|
||||
ty::infer::diagnostics::InferenceDiagnostic,
|
||||
Adt, AssocItem, ConstData, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField,
|
||||
Trait, VariantDef,
|
||||
Adt, AssocItem, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, Trait,
|
||||
VariantDef,
|
||||
};
|
||||
|
||||
macro_rules! ty_app {
|
||||
|
@ -69,10 +69,10 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResu
|
|||
let resolver = DefWithBodyId::from(def).resolver(db);
|
||||
let mut ctx = InferenceContext::new(db, def, resolver);
|
||||
|
||||
match def {
|
||||
DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)),
|
||||
DefWithBody::Function(ref f) => ctx.collect_fn(&db.function_data(f.id)),
|
||||
DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)),
|
||||
match &def {
|
||||
DefWithBody::Const(c) => ctx.collect_const(&db.const_data(c.id)),
|
||||
DefWithBody::Function(f) => ctx.collect_fn(&db.function_data(f.id)),
|
||||
DefWithBody::Static(s) => ctx.collect_const(&db.static_data(s.id)),
|
||||
}
|
||||
|
||||
ctx.infer_body();
|
||||
|
@ -560,7 +560,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
|
||||
fn collect_const(&mut self, data: &ConstData) {
|
||||
self.return_ty = self.make_ty(data.type_ref());
|
||||
self.return_ty = self.make_ty(&data.type_ref);
|
||||
}
|
||||
|
||||
fn collect_fn(&mut self, data: &FunctionData) {
|
||||
|
|
|
@ -639,18 +639,18 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty {
|
|||
|
||||
/// Build the declared type of a const.
|
||||
fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty {
|
||||
let data = def.data(db);
|
||||
let data = db.const_data(def.id);
|
||||
let resolver = def.id.resolver(db);
|
||||
|
||||
Ty::from_hir(db, &resolver, data.type_ref())
|
||||
Ty::from_hir(db, &resolver, &data.type_ref)
|
||||
}
|
||||
|
||||
/// Build the declared type of a static.
|
||||
fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty {
|
||||
let data = def.data(db);
|
||||
let data = db.static_data(def.id);
|
||||
let resolver = def.id.resolver(db);
|
||||
|
||||
Ty::from_hir(db, &resolver, data.type_ref())
|
||||
Ty::from_hir(db, &resolver, &data.type_ref)
|
||||
}
|
||||
|
||||
/// Build the declared type of a static.
|
||||
|
|
|
@ -11,8 +11,8 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
|||
use crate::{
|
||||
db::DefDatabase2,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocItemId, AstItemDef, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, ImplId,
|
||||
Intern, Lookup, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
|
||||
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -190,3 +190,28 @@ impl ImplData {
|
|||
Arc::new(res)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConstData {
|
||||
pub name: Option<Name>,
|
||||
pub type_ref: TypeRef,
|
||||
}
|
||||
|
||||
impl ConstData {
|
||||
pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc<ConstData> {
|
||||
let node = konst.lookup(db).source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
|
||||
pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc<ConstData> {
|
||||
let node = konst.source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
}
|
||||
|
||||
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
|
||||
let name = node.name().map(|n| n.as_name());
|
||||
let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
|
||||
let sig = ConstData { name, type_ref };
|
||||
Arc::new(sig)
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ use ra_syntax::ast;
|
|||
use crate::{
|
||||
adt::{EnumData, StructData},
|
||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||
data::{FunctionData, ImplData, TraitData, TypeAliasData},
|
||||
data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData},
|
||||
generics::GenericParams,
|
||||
nameres::{
|
||||
raw::{ImportSourceMap, RawItems},
|
||||
CrateDefMap,
|
||||
},
|
||||
DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
|
||||
TypeAliasId,
|
||||
ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StaticId,
|
||||
StructOrUnionId, TraitId, TypeAliasId,
|
||||
};
|
||||
|
||||
#[salsa::query_group(InternDatabaseStorage)]
|
||||
|
@ -70,6 +70,12 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
|
|||
#[salsa::invoke(FunctionData::fn_data_query)]
|
||||
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
|
||||
|
||||
#[salsa::invoke(ConstData::const_data_query)]
|
||||
fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(ConstData::static_data_query)]
|
||||
fn static_data(&self, konst: StaticId) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
||||
|
||||
|
|
Loading…
Reference in a new issue