aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 3cbf8070f..0d8e67547 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -1,4 +1,4 @@
1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; 1use ra_db::{SourceRootId, LocationIntener, FileId};
2use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; 2use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast};
3use ra_arena::{Arena, RawId, impl_arena_id}; 3use ra_arena::{Arena, RawId, impl_arena_id};
4 4
@@ -205,25 +205,21 @@ impl DefId {
205 } 205 }
206 206
207 /// For a module, returns that module; for any other def, returns the containing module. 207 /// For a module, returns that module; for any other def, returns the containing module.
208 pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { 208 pub fn module(self, db: &impl HirDatabase) -> Module {
209 let loc = self.loc(db); 209 let loc = self.loc(db);
210 Ok(Module::from_module_id( 210 Module::from_module_id(db, loc.source_root_id, loc.module_id)
211 db,
212 loc.source_root_id,
213 loc.module_id,
214 ))
215 } 211 }
216 212
217 /// Returns the containing crate. 213 /// Returns the containing crate.
218 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 214 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
219 Ok(self.module(db)?.krate(db)) 215 self.module(db).krate(db)
220 } 216 }
221 217
222 /// Returns the containing impl block, if this is an impl item. 218 /// Returns the containing impl block, if this is an impl item.
223 pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { 219 pub fn impl_block(self, db: &impl HirDatabase) -> Option<ImplBlock> {
224 let loc = self.loc(db); 220 let loc = self.loc(db);
225 let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?; 221 let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id);
226 Ok(ImplBlock::containing(module_impls, self)) 222 ImplBlock::containing(module_impls, self)
227 } 223 }
228} 224}
229 225