From 762915826ac6893036f8b5cd5e63677ed862f6d9 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 5 Dec 2019 08:19:27 -0500 Subject: Reduce visibility, use struct instead of tuples --- crates/ra_hir_def/src/nameres.rs | 43 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index f70235c99..01d67777d 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -107,8 +107,13 @@ pub enum ModuleOrigin { /// It should not be `None` after collecting definitions. Root(Option), /// Note that non-inline modules, by definition, live inside non-macro file. - File(AstId, FileId), - Inline(AstId), + File { + declaration: AstId, + definition: FileId, + }, + Inline { + definition: AstId, + }, } impl Default for ModuleOrigin { @@ -118,49 +123,47 @@ impl Default for ModuleOrigin { } impl ModuleOrigin { - pub fn root(file_id: FileId) -> Self { + fn root(file_id: FileId) -> Self { ModuleOrigin::Root(Some(file_id)) } - pub fn not_sure_file(file: Option, module: AstId) -> Self { + pub(crate) fn not_sure_file(file: Option, declaration: AstId) -> Self { match file { - None => ModuleOrigin::Inline(module), - Some(file) => ModuleOrigin::File(module, file), + None => ModuleOrigin::Inline { definition: declaration }, + Some(definition) => ModuleOrigin::File { declaration, definition }, } } - pub fn not_sure_mod(file: FileId, module: Option>) -> Self { - match module { - None => ModuleOrigin::root(file), - Some(module) => ModuleOrigin::File(module, file), - } - } - - pub fn declaration(&self) -> Option> { + fn declaration(&self) -> Option> { match self { - ModuleOrigin::File(m, _) | ModuleOrigin::Inline(m) => Some(*m), + ModuleOrigin::File { declaration: module, .. } + | ModuleOrigin::Inline { definition: module, .. } => Some(*module), ModuleOrigin::Root(_) => None, } } - pub fn file_id(&self) -> Option { + pub(crate) fn file_id(&self) -> Option { match self { - ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => Some(*file_id), + ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => { + Some(*file_id) + } _ => None, } } /// 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 { + fn definition_source(&self, db: &impl DefDatabase) -> InFile { match self { - ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => { + ModuleOrigin::File { definition: 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(), ModuleSource::SourceFile(sf)); } ModuleOrigin::Root(None) => unreachable!(), - ModuleOrigin::Inline(m) => InFile::new(m.file_id, ModuleSource::Module(m.to_node(db))), + ModuleOrigin::Inline { definition } => { + InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) + } } } } -- cgit v1.2.3