remove Cancelable from ids

This commit is contained in:
Aleksey Kladov 2019-01-15 19:18:52 +03:00
parent 490112dea1
commit fafcd103d2
6 changed files with 27 additions and 34 deletions

View file

@ -2,7 +2,6 @@ mod scope;
use std::sync::Arc;
use ra_db::Cancelable;
use ra_syntax::{TreeArc, ast::{self, NameOwner}};
use crate::{
@ -24,12 +23,12 @@ impl Function {
db.body_hir(self.def_id)
}
pub(crate) fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
pub(crate) fn module(&self, db: &impl HirDatabase) -> Module {
self.def_id.module(db)
}
/// The containing impl block, if this is a method.
pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> {
pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> {
self.def_id.impl_block(db)
}
}

View file

@ -97,7 +97,7 @@ pub trait HirDatabase: SyntaxDatabase
use fn crate::module_tree::ModuleTree::module_tree_query;
}
fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleImplBlocks>> {
fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> {
type ImplsInModuleQuery;
use fn crate::impl_block::impls_in_module;
}

View file

@ -1,4 +1,4 @@
use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId};
use ra_db::{SourceRootId, LocationIntener, FileId};
use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast};
use ra_arena::{Arena, RawId, impl_arena_id};
@ -205,25 +205,21 @@ impl DefId {
}
/// For a module, returns that module; for any other def, returns the containing module.
pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
pub fn module(self, db: &impl HirDatabase) -> Module {
let loc = self.loc(db);
Ok(Module::from_module_id(
db,
loc.source_root_id,
loc.module_id,
))
Module::from_module_id(db, loc.source_root_id, loc.module_id)
}
/// Returns the containing crate.
pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
Ok(self.module(db)?.krate(db))
pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
self.module(db).krate(db)
}
/// Returns the containing impl block, if this is an impl item.
pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> {
pub fn impl_block(self, db: &impl HirDatabase) -> Option<ImplBlock> {
let loc = self.loc(db);
let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?;
Ok(ImplBlock::containing(module_impls, self))
let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id);
ImplBlock::containing(module_impls, self)
}
}

View file

@ -3,7 +3,7 @@ use rustc_hash::FxHashMap;
use ra_arena::{Arena, RawId, impl_arena_id};
use ra_syntax::ast::{self, AstNode};
use ra_db::{LocationIntener, Cancelable, SourceRootId};
use ra_db::{LocationIntener, SourceRootId};
use crate::{
DefId, DefLoc, DefKind, SourceItemId, SourceFileItems,
@ -166,7 +166,7 @@ impl ModuleImplBlocks {
}
}
fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
fn collect(&mut self, db: &impl HirDatabase, module: Module) {
let (file_id, module_source) = module.definition_source(db);
let node = match &module_source {
ModuleSource::SourceFile(node) => node.syntax(),
@ -185,8 +185,6 @@ impl ModuleImplBlocks {
self.impls_by_def.insert(impl_item.def_id(), id);
}
}
Ok(())
}
}
@ -194,9 +192,9 @@ pub(crate) fn impls_in_module(
db: &impl HirDatabase,
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Cancelable<Arc<ModuleImplBlocks>> {
) -> Arc<ModuleImplBlocks> {
let mut result = ModuleImplBlocks::new();
let module = Module::from_module_id(db, source_root_id, module_id);
result.collect(db, module)?;
Ok(Arc::new(result))
result.collect(db, module);
Arc::new(result)
}

View file

@ -447,8 +447,8 @@ impl fmt::Display for Ty {
/// function body.
fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
let signature = f.signature(db);
let module = f.module(db)?;
let impl_block = f.impl_block(db)?;
let module = f.module(db);
let impl_block = f.impl_block(db);
// TODO we ignore type parameters for now
let input = signature
.params()
@ -517,8 +517,8 @@ pub(super) fn type_for_field(
def_id
),
};
let module = def_id.module(db)?;
let impl_block = def_id.impl_block(db)?;
let module = def_id.module(db);
let impl_block = def_id.impl_block(db);
let type_ref = ctry!(variant_data.get_field_type_ref(&field));
Ok(Some(Ty::from_hir(
db,
@ -1207,8 +1207,8 @@ pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceRe
let function = Function::new(def_id); // TODO: consts also need inference
let body = function.body(db);
let scopes = db.fn_scopes(def_id);
let module = function.module(db)?;
let impl_block = function.impl_block(db)?;
let module = function.module(db);
let impl_block = function.impl_block(db);
let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block);
let signature = function.signature(db);

View file

@ -49,14 +49,14 @@ impl CrateImplBlocks {
.into_iter()
.flat_map(|i| i.iter())
.map(move |(module_id, impl_id)| {
let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id)?;
let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id);
Ok(ImplBlock::from_id(module_impl_blocks, *impl_id))
})
}
fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
let module_id = module.def_id.loc(db).module_id;
let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id)?;
let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id);
for (impl_id, impl_data) in module_impl_blocks.impls.iter() {
let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id);
@ -100,10 +100,10 @@ impl CrateImplBlocks {
}
}
fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Cancelable<Option<Crate>> {
fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
match ty {
Ty::Adt { def_id, .. } => def_id.krate(db),
_ => Ok(None),
_ => None,
}
}
@ -139,7 +139,7 @@ impl Ty {
// rustc does an autoderef and then autoref again).
for derefed_ty in self.autoderef(db) {
let krate = match def_crate(db, &derefed_ty)? {
let krate = match def_crate(db, &derefed_ty) {
Some(krate) => krate,
None => continue,
};