diff options
author | ice1000 <[email protected]> | 2019-12-05 13:19:27 +0000 |
---|---|---|
committer | ice1000 <[email protected]> | 2019-12-05 13:19:27 +0000 |
commit | 762915826ac6893036f8b5cd5e63677ed862f6d9 (patch) | |
tree | 3e8e70b95341f82fc2754d72d5377c94e37fbf24 | |
parent | 088f50c0ab351d5ac072547a47c1ce7eeae029f3 (diff) |
Reduce visibility, use struct instead of tuples
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 43 |
1 files changed, 23 insertions, 20 deletions
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 { | |||
107 | /// It should not be `None` after collecting definitions. | 107 | /// It should not be `None` after collecting definitions. |
108 | Root(Option<FileId>), | 108 | Root(Option<FileId>), |
109 | /// Note that non-inline modules, by definition, live inside non-macro file. | 109 | /// Note that non-inline modules, by definition, live inside non-macro file. |
110 | File(AstId<ast::Module>, FileId), | 110 | File { |
111 | Inline(AstId<ast::Module>), | 111 | declaration: AstId<ast::Module>, |
112 | definition: FileId, | ||
113 | }, | ||
114 | Inline { | ||
115 | definition: AstId<ast::Module>, | ||
116 | }, | ||
112 | } | 117 | } |
113 | 118 | ||
114 | impl Default for ModuleOrigin { | 119 | impl Default for ModuleOrigin { |
@@ -118,49 +123,47 @@ impl Default for ModuleOrigin { | |||
118 | } | 123 | } |
119 | 124 | ||
120 | impl ModuleOrigin { | 125 | impl ModuleOrigin { |
121 | pub fn root(file_id: FileId) -> Self { | 126 | fn root(file_id: FileId) -> Self { |
122 | ModuleOrigin::Root(Some(file_id)) | 127 | ModuleOrigin::Root(Some(file_id)) |
123 | } | 128 | } |
124 | 129 | ||
125 | pub fn not_sure_file(file: Option<FileId>, module: AstId<ast::Module>) -> Self { | 130 | pub(crate) fn not_sure_file(file: Option<FileId>, declaration: AstId<ast::Module>) -> Self { |
126 | match file { | 131 | match file { |
127 | None => ModuleOrigin::Inline(module), | 132 | None => ModuleOrigin::Inline { definition: declaration }, |
128 | Some(file) => ModuleOrigin::File(module, file), | 133 | Some(definition) => ModuleOrigin::File { declaration, definition }, |
129 | } | 134 | } |
130 | } | 135 | } |
131 | 136 | ||
132 | pub fn not_sure_mod(file: FileId, module: Option<AstId<ast::Module>>) -> Self { | 137 | fn declaration(&self) -> Option<AstId<ast::Module>> { |
133 | match module { | ||
134 | None => ModuleOrigin::root(file), | ||
135 | Some(module) => ModuleOrigin::File(module, file), | ||
136 | } | ||
137 | } | ||
138 | |||
139 | pub fn declaration(&self) -> Option<AstId<ast::Module>> { | ||
140 | match self { | 138 | match self { |
141 | ModuleOrigin::File(m, _) | ModuleOrigin::Inline(m) => Some(*m), | 139 | ModuleOrigin::File { declaration: module, .. } |
140 | | ModuleOrigin::Inline { definition: module, .. } => Some(*module), | ||
142 | ModuleOrigin::Root(_) => None, | 141 | ModuleOrigin::Root(_) => None, |
143 | } | 142 | } |
144 | } | 143 | } |
145 | 144 | ||
146 | pub fn file_id(&self) -> Option<FileId> { | 145 | pub(crate) fn file_id(&self) -> Option<FileId> { |
147 | match self { | 146 | match self { |
148 | ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => Some(*file_id), | 147 | ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => { |
148 | Some(*file_id) | ||
149 | } | ||
149 | _ => None, | 150 | _ => None, |
150 | } | 151 | } |
151 | } | 152 | } |
152 | 153 | ||
153 | /// Returns a node which defines this module. | 154 | /// Returns a node which defines this module. |
154 | /// That is, a file or a `mod foo {}` with items. | 155 | /// That is, a file or a `mod foo {}` with items. |
155 | pub fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> { | 156 | fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> { |
156 | match self { | 157 | match self { |
157 | ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => { | 158 | ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => { |
158 | let file_id = *file_id; | 159 | let file_id = *file_id; |
159 | let sf = db.parse(file_id).tree(); | 160 | let sf = db.parse(file_id).tree(); |
160 | return InFile::new(file_id.into(), ModuleSource::SourceFile(sf)); | 161 | return InFile::new(file_id.into(), ModuleSource::SourceFile(sf)); |
161 | } | 162 | } |
162 | ModuleOrigin::Root(None) => unreachable!(), | 163 | ModuleOrigin::Root(None) => unreachable!(), |
163 | ModuleOrigin::Inline(m) => InFile::new(m.file_id, ModuleSource::Module(m.to_node(db))), | 164 | ModuleOrigin::Inline { definition } => { |
165 | InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) | ||
166 | } | ||
164 | } | 167 | } |
165 | } | 168 | } |
166 | } | 169 | } |