diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index d7cc9b4ca..0d8e67547 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; | 1 | use ra_db::{SourceRootId, LocationIntener, FileId}; |
2 | use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; | 2 | use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; |
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | 4 | ||
@@ -159,9 +159,9 @@ impl DefId { | |||
159 | db.as_ref().id2loc(self) | 159 | db.as_ref().id2loc(self) |
160 | } | 160 | } |
161 | 161 | ||
162 | pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { | 162 | pub fn resolve(self, db: &impl HirDatabase) -> Def { |
163 | let loc = self.loc(db); | 163 | let loc = self.loc(db); |
164 | let res = match loc.kind { | 164 | match loc.kind { |
165 | DefKind::Module => { | 165 | DefKind::Module => { |
166 | let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); | 166 | let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); |
167 | Def::Module(module) | 167 | Def::Module(module) |
@@ -195,8 +195,7 @@ impl DefId { | |||
195 | 195 | ||
196 | DefKind::StructCtor => Def::Item, | 196 | DefKind::StructCtor => Def::Item, |
197 | DefKind::Item => Def::Item, | 197 | DefKind::Item => Def::Item, |
198 | }; | 198 | } |
199 | Ok(res) | ||
200 | } | 199 | } |
201 | 200 | ||
202 | pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) { | 201 | pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) { |
@@ -206,25 +205,21 @@ impl DefId { | |||
206 | } | 205 | } |
207 | 206 | ||
208 | /// 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. |
209 | pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { | 208 | pub fn module(self, db: &impl HirDatabase) -> Module { |
210 | let loc = self.loc(db); | 209 | let loc = self.loc(db); |
211 | Ok(Module::from_module_id( | 210 | Module::from_module_id(db, loc.source_root_id, loc.module_id) |
212 | db, | ||
213 | loc.source_root_id, | ||
214 | loc.module_id, | ||
215 | )) | ||
216 | } | 211 | } |
217 | 212 | ||
218 | /// Returns the containing crate. | 213 | /// Returns the containing crate. |
219 | pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { | 214 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { |
220 | Ok(self.module(db)?.krate(db)?) | 215 | self.module(db).krate(db) |
221 | } | 216 | } |
222 | 217 | ||
223 | /// Returns the containing impl block, if this is an impl item. | 218 | /// Returns the containing impl block, if this is an impl item. |
224 | pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { | 219 | pub fn impl_block(self, db: &impl HirDatabase) -> Option<ImplBlock> { |
225 | let loc = self.loc(db); | 220 | let loc = self.loc(db); |
226 | 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); |
227 | Ok(ImplBlock::containing(module_impls, self)) | 222 | ImplBlock::containing(module_impls, self) |
228 | } | 223 | } |
229 | } | 224 | } |
230 | 225 | ||