Skip to content

Commit 7629158

Browse files
committed
Reduce visibility, use struct instead of tuples
1 parent 088f50c commit 7629158

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

crates/ra_hir_def/src/nameres.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ pub enum ModuleOrigin {
107107
/// It should not be `None` after collecting definitions.
108108
Root(Option<FileId>),
109109
/// Note that non-inline modules, by definition, live inside non-macro file.
110-
File(AstId<ast::Module>, FileId),
111-
Inline(AstId<ast::Module>),
110+
File {
111+
declaration: AstId<ast::Module>,
112+
definition: FileId,
113+
},
114+
Inline {
115+
definition: AstId<ast::Module>,
116+
},
112117
}
113118

114119
impl Default for ModuleOrigin {
@@ -118,49 +123,47 @@ impl Default for ModuleOrigin {
118123
}
119124

120125
impl ModuleOrigin {
121-
pub fn root(file_id: FileId) -> Self {
126+
fn root(file_id: FileId) -> Self {
122127
ModuleOrigin::Root(Some(file_id))
123128
}
124129

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 {
126131
match file {
127-
None => ModuleOrigin::Inline(module),
128-
Some(file) => ModuleOrigin::File(module, file),
132+
None => ModuleOrigin::Inline { definition: declaration },
133+
Some(definition) => ModuleOrigin::File { declaration, definition },
129134
}
130135
}
131136

132-
pub fn not_sure_mod(file: FileId, module: Option<AstId<ast::Module>>) -> Self {
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>> {
137+
fn declaration(&self) -> Option<AstId<ast::Module>> {
140138
match self {
141-
ModuleOrigin::File(m, _) | ModuleOrigin::Inline(m) => Some(*m),
139+
ModuleOrigin::File { declaration: module, .. }
140+
| ModuleOrigin::Inline { definition: module, .. } => Some(*module),
142141
ModuleOrigin::Root(_) => None,
143142
}
144143
}
145144

146-
pub fn file_id(&self) -> Option<FileId> {
145+
pub(crate) fn file_id(&self) -> Option<FileId> {
147146
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+
}
149150
_ => None,
150151
}
151152
}
152153

153154
/// Returns a node which defines this module.
154155
/// 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> {
156157
match self {
157-
ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => {
158+
ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => {
158159
let file_id = *file_id;
159160
let sf = db.parse(file_id).tree();
160161
return InFile::new(file_id.into(), ModuleSource::SourceFile(sf));
161162
}
162163
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+
}
164167
}
165168
}
166169
}

0 commit comments

Comments
 (0)