From 5c5f90ba57c83499a44af33bf8b91b24254fb685 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 15:28:40 -0500 Subject: Confluent `ModuleSource` usage --- crates/ra_hir/src/code_model/src.rs | 6 +----- crates/ra_hir_def/src/nameres.rs | 18 +++++------------- 2 files changed, 6 insertions(+), 18 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 083946729..d9bccd902 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -26,11 +26,7 @@ impl Module { /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. pub fn definition_source(self, db: &impl DefDatabase) -> InFile { let def_map = db.crate_def_map(self.id.krate); - let src = def_map[self.id.local_id].definition_source(db); - src.map(|it| match it { - Either::Left(it) => ModuleSource::SourceFile(it), - Either::Right(it) => ModuleSource::Module(it), - }) + def_map[self.id.local_id].definition_source(db) } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index feb2a4d32..e356515cb 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -57,7 +57,6 @@ mod tests; use std::sync::Arc; -use either::Either; use hir_expand::{ ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId, }; @@ -154,20 +153,16 @@ impl ModuleOrigin { /// Returns a node which defines this module. /// That is, a file or a `mod foo {}` with items. - pub fn definition_source( - &self, - db: &impl DefDatabase, - ) -> InFile> { + pub fn definition_source(&self, db: &impl DefDatabase) -> InFile { match self { ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => { let file_id = *file_id; let sf = db.parse(file_id).tree(); - return InFile::new(file_id.into(), Either::Left(sf)); + return InFile::new(file_id.into(), ModuleSource::SourceFile(sf)); } ModuleOrigin::Root(None) => unreachable!(), - ModuleOrigin::Inline(m) => InFile::new(m.file_id, Either::Right(m.to_node(db))), - // FIXME: right now it's never constructed, so it's fine to omit - ModuleOrigin::Block(_b) => unimplemented!(), + ModuleOrigin::Inline(m) => InFile::new(m.file_id, ModuleSource::Module(m.to_node(db))), + ModuleOrigin::Block(b) => InFile::new(b.file_id, ModuleSource::Block(b.to_node(db))), } } } @@ -348,10 +343,7 @@ impl CrateDefMap { impl ModuleData { /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source( - &self, - db: &impl DefDatabase, - ) -> InFile> { + pub fn definition_source(&self, db: &impl DefDatabase) -> InFile { self.origin.definition_source(db) } -- cgit v1.2.3