mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Minor cleanup
This commit is contained in:
parent
aa0646be29
commit
fc055281a5
6 changed files with 44 additions and 47 deletions
|
@ -550,7 +550,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
||||||
db.body_hir(self.into())
|
db.body(self.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
|
@ -564,7 +564,7 @@ impl HasBody for DefWithBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
||||||
db.body_hir(self)
|
db.body(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
|
@ -666,7 +666,7 @@ impl Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
|
||||||
db.body_hir(self.into())
|
db.body(self.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty(self, db: &impl HirDatabase) -> Ty {
|
pub fn ty(self, db: &impl HirDatabase) -> Ty {
|
||||||
|
@ -1079,7 +1079,7 @@ pub struct Local {
|
||||||
|
|
||||||
impl Local {
|
impl Local {
|
||||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||||
let body = db.body_hir(self.parent);
|
let body = db.body(self.parent);
|
||||||
match &body[self.pat_id] {
|
match &body[self.pat_id] {
|
||||||
Pat::Bind { name, .. } => Some(name.clone()),
|
Pat::Bind { name, .. } => Some(name.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -1091,7 +1091,7 @@ impl Local {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_mut(self, db: &impl HirDatabase) -> bool {
|
pub fn is_mut(self, db: &impl HirDatabase) -> bool {
|
||||||
let body = db.body_hir(self.parent);
|
let body = db.body(self.parent);
|
||||||
match &body[self.pat_id] {
|
match &body[self.pat_id] {
|
||||||
Pat::Bind { mode, .. } => match mode {
|
Pat::Bind { mode, .. } => match mode {
|
||||||
BindingAnnotation::Mutable | BindingAnnotation::RefMut => true,
|
BindingAnnotation::Mutable | BindingAnnotation::RefMut => true,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use ra_syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
debug::HirDebugDatabase,
|
debug::HirDebugDatabase,
|
||||||
|
expr::{Body, BodySourceMap},
|
||||||
generics::{GenericDef, GenericParams},
|
generics::{GenericDef, GenericParams},
|
||||||
ids,
|
ids,
|
||||||
impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
|
impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
|
||||||
|
@ -112,14 +113,11 @@ pub trait HirDatabase: DefDatabase + AstDatabase {
|
||||||
#[salsa::invoke(crate::ty::generic_defaults_query)]
|
#[salsa::invoke(crate::ty::generic_defaults_query)]
|
||||||
fn generic_defaults(&self, def: GenericDef) -> Substs;
|
fn generic_defaults(&self, def: GenericDef) -> Substs;
|
||||||
|
|
||||||
#[salsa::invoke(crate::expr::body_with_source_map_query)]
|
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||||
fn body_with_source_map(
|
fn body_with_source_map(&self, def: DefWithBody) -> (Arc<Body>, Arc<BodySourceMap>);
|
||||||
&self,
|
|
||||||
def: DefWithBody,
|
|
||||||
) -> (Arc<crate::expr::Body>, Arc<crate::expr::BodySourceMap>);
|
|
||||||
|
|
||||||
#[salsa::invoke(crate::expr::body_hir_query)]
|
#[salsa::invoke(Body::body_query)]
|
||||||
fn body_hir(&self, def: DefWithBody) -> Arc<crate::expr::Body>;
|
fn body(&self, def: DefWithBody) -> Arc<Body>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
||||||
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
||||||
|
|
|
@ -75,6 +75,36 @@ pub struct BodySourceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
|
pub(crate) fn body_with_source_map_query(
|
||||||
|
db: &impl HirDatabase,
|
||||||
|
def: DefWithBody,
|
||||||
|
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
||||||
|
let mut params = None;
|
||||||
|
|
||||||
|
let (file_id, body) = match def {
|
||||||
|
DefWithBody::Function(f) => {
|
||||||
|
let src = f.source(db);
|
||||||
|
params = src.ast.param_list();
|
||||||
|
(src.file_id, src.ast.body().map(ast::Expr::from))
|
||||||
|
}
|
||||||
|
DefWithBody::Const(c) => {
|
||||||
|
let src = c.source(db);
|
||||||
|
(src.file_id, src.ast.body())
|
||||||
|
}
|
||||||
|
DefWithBody::Static(s) => {
|
||||||
|
let src = s.source(db);
|
||||||
|
(src.file_id, src.ast.body())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
|
||||||
|
(Arc::new(body), Arc::new(source_map))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn body_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
|
||||||
|
db.body_with_source_map(def).0
|
||||||
|
}
|
||||||
|
|
||||||
pub fn params(&self) -> &[PatId] {
|
pub fn params(&self) -> &[PatId] {
|
||||||
&self.params
|
&self.params
|
||||||
}
|
}
|
||||||
|
@ -542,34 +572,3 @@ impl Pat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queries
|
|
||||||
pub(crate) fn body_with_source_map_query(
|
|
||||||
db: &impl HirDatabase,
|
|
||||||
def: DefWithBody,
|
|
||||||
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
|
||||||
let mut params = None;
|
|
||||||
|
|
||||||
let (file_id, body) = match def {
|
|
||||||
DefWithBody::Function(f) => {
|
|
||||||
let src = f.source(db);
|
|
||||||
params = src.ast.param_list();
|
|
||||||
(src.file_id, src.ast.body().map(ast::Expr::from))
|
|
||||||
}
|
|
||||||
DefWithBody::Const(c) => {
|
|
||||||
let src = c.source(db);
|
|
||||||
(src.file_id, src.ast.body())
|
|
||||||
}
|
|
||||||
DefWithBody::Static(s) => {
|
|
||||||
let src = s.source(db);
|
|
||||||
(src.file_id, src.ast.body())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
|
|
||||||
(Arc::new(body), Arc::new(source_map))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
|
|
||||||
db.body_with_source_map(def).0
|
|
||||||
}
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub(crate) struct ScopeData {
|
||||||
|
|
||||||
impl ExprScopes {
|
impl ExprScopes {
|
||||||
pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
|
pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
|
||||||
let body = db.body_hir(def);
|
let body = db.body(def);
|
||||||
let res = ExprScopes::new(body);
|
let res = ExprScopes::new(body);
|
||||||
Arc::new(res)
|
Arc::new(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -714,7 +714,7 @@ fn closure_fn_trait_impl_datum(
|
||||||
let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?;
|
let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?;
|
||||||
let trait_ = get_fn_trait(db, krate, data.fn_trait)?; // get corresponding fn trait
|
let trait_ = get_fn_trait(db, krate, data.fn_trait)?; // get corresponding fn trait
|
||||||
|
|
||||||
let num_args: u16 = match &db.body_hir(data.def)[data.expr] {
|
let num_args: u16 = match &db.body(data.def)[data.expr] {
|
||||||
crate::expr::Expr::Lambda { args, .. } => args.len() as u16,
|
crate::expr::Expr::Lambda { args, .. } => args.len() as u16,
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("closure for closure type {:?} not found", data);
|
log::warn!("closure for closure type {:?} not found", data);
|
||||||
|
|
|
@ -276,7 +276,7 @@ impl RootDatabase {
|
||||||
|
|
||||||
self.query(hir::db::ExprScopesQuery).sweep(sweep);
|
self.query(hir::db::ExprScopesQuery).sweep(sweep);
|
||||||
self.query(hir::db::InferQuery).sweep(sweep);
|
self.query(hir::db::InferQuery).sweep(sweep);
|
||||||
self.query(hir::db::BodyHirQuery).sweep(sweep);
|
self.query(hir::db::BodyQuery).sweep(sweep);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
|
pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
|
||||||
|
@ -333,7 +333,7 @@ impl RootDatabase {
|
||||||
hir::db::GenericPredicatesQuery
|
hir::db::GenericPredicatesQuery
|
||||||
hir::db::GenericDefaultsQuery
|
hir::db::GenericDefaultsQuery
|
||||||
hir::db::BodyWithSourceMapQuery
|
hir::db::BodyWithSourceMapQuery
|
||||||
hir::db::BodyHirQuery
|
hir::db::BodyQuery
|
||||||
hir::db::ImplsInCrateQuery
|
hir::db::ImplsInCrateQuery
|
||||||
hir::db::ImplsForTraitQuery
|
hir::db::ImplsForTraitQuery
|
||||||
hir::db::AssociatedTyDataQuery
|
hir::db::AssociatedTyDataQuery
|
||||||
|
|
Loading…
Reference in a new issue