aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-26 16:16:54 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-26 16:16:54 +0000
commita82755e24102bea85be450e0b210d45b05b9f246 (patch)
tree52f347ddfc4586e3dfa4467827b211d1684aaa74 /crates/ra_hir/src/nameres.rs
parent96acf4f7ec4257af0d5fd0415b31ab6757b475ad (diff)
parent1325a31e34a3b4bf5104a743bcb8217ef5c4f3cd (diff)
Merge #1059
1059: Typed ids r=matklad a=matklad just some type-safety and refactorings. closes https://github.com/rust-analyzer/rust-analyzer/issues/1054 bors r+ Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r--crates/ra_hir/src/nameres.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index e962bbd31..67b9d6986 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -59,13 +59,15 @@ use rustc_hash::FxHashMap;
59use ra_arena::{Arena, RawId, impl_arena_id}; 59use ra_arena::{Arena, RawId, impl_arena_id};
60use ra_db::{FileId, Edition}; 60use ra_db::{FileId, Edition};
61use test_utils::tested_by; 61use test_utils::tested_by;
62use ra_syntax::ast;
62 63
63use crate::{ 64use crate::{
64 ModuleDef, Name, Crate, Module, SourceItemId, 65 ModuleDef, Name, Crate, Module,
65 DefDatabase, Path, PathKind, HirFileId, Trait, 66 DefDatabase, Path, PathKind, HirFileId, Trait,
66 ids::MacroDefId, 67 ids::MacroDefId,
67 diagnostics::DiagnosticSink, 68 diagnostics::DiagnosticSink,
68 nameres::diagnostics::DefDiagnostic, 69 nameres::diagnostics::DefDiagnostic,
70 AstId,
69}; 71};
70 72
71pub(crate) use self::raw::{RawItems, ImportId, ImportSourceMap}; 73pub(crate) use self::raw::{RawItems, ImportId, ImportSourceMap};
@@ -106,7 +108,7 @@ pub(crate) struct ModuleData {
106 pub(crate) children: FxHashMap<Name, CrateModuleId>, 108 pub(crate) children: FxHashMap<Name, CrateModuleId>,
107 pub(crate) scope: ModuleScope, 109 pub(crate) scope: ModuleScope,
108 /// None for root 110 /// None for root
109 pub(crate) declaration: Option<SourceItemId>, 111 pub(crate) declaration: Option<AstId<ast::Module>>,
110 /// None for inline modules. 112 /// None for inline modules.
111 /// 113 ///
112 /// Note that non-inline modules, by definition, live inside non-macro file. 114 /// Note that non-inline modules, by definition, live inside non-macro file.
@@ -225,7 +227,7 @@ impl CrateDefMap {
225 pub(crate) fn find_module_by_source( 227 pub(crate) fn find_module_by_source(
226 &self, 228 &self,
227 file_id: HirFileId, 229 file_id: HirFileId,
228 decl_id: Option<SourceItemId>, 230 decl_id: Option<AstId<ast::Module>>,
229 ) -> Option<CrateModuleId> { 231 ) -> Option<CrateModuleId> {
230 let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| { 232 let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| {
231 if decl_id.is_some() { 233 if decl_id.is_some() {
@@ -429,10 +431,10 @@ impl CrateDefMap {
429 431
430mod diagnostics { 432mod diagnostics {
431 use relative_path::RelativePathBuf; 433 use relative_path::RelativePathBuf;
432 use ra_syntax::{AstPtr, AstNode, ast}; 434 use ra_syntax::{AstPtr, ast};
433 435
434 use crate::{ 436 use crate::{
435 SourceItemId, DefDatabase, 437 AstId, DefDatabase,
436 nameres::CrateModuleId, 438 nameres::CrateModuleId,
437 diagnostics::{DiagnosticSink, UnresolvedModule}, 439 diagnostics::{DiagnosticSink, UnresolvedModule},
438}; 440};
@@ -441,7 +443,7 @@ mod diagnostics {
441 pub(super) enum DefDiagnostic { 443 pub(super) enum DefDiagnostic {
442 UnresolvedModule { 444 UnresolvedModule {
443 module: CrateModuleId, 445 module: CrateModuleId,
444 declaration: SourceItemId, 446 declaration: AstId<ast::Module>,
445 candidate: RelativePathBuf, 447 candidate: RelativePathBuf,
446 }, 448 },
447 } 449 }
@@ -458,10 +460,9 @@ mod diagnostics {
458 if *module != target_module { 460 if *module != target_module {
459 return; 461 return;
460 } 462 }
461 let syntax = db.file_item(*declaration); 463 let decl = declaration.to_node(db);
462 let decl = ast::Module::cast(&syntax).unwrap();
463 sink.push(UnresolvedModule { 464 sink.push(UnresolvedModule {
464 file: declaration.file_id, 465 file: declaration.file_id(),
465 decl: AstPtr::new(&decl), 466 decl: AstPtr::new(&decl),
466 candidate: candidate.clone(), 467 candidate: candidate.clone(),
467 }) 468 })
@@ -469,5 +470,4 @@ mod diagnostics {
469 } 470 }
470 } 471 }
471 } 472 }
472
473} 473}