Skip to content

Commit 006a583

Browse files
committed
Use placeholder instead of Option
1 parent 7702f69 commit 006a583

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

crates/ra_hir_def/src/nameres.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ impl std::ops::Index<LocalModuleId> for CrateDefMap {
104104

105105
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
106106
pub enum ModuleOrigin {
107-
/// It should not be `None` after collecting definitions.
108-
Root(Option<FileId>),
107+
CrateRoot {
108+
definition: FileId,
109+
},
109110
/// Note that non-inline modules, by definition, live inside non-macro file.
110111
File {
111112
declaration: AstId<ast::Module>,
@@ -118,15 +119,11 @@ pub enum ModuleOrigin {
118119

119120
impl Default for ModuleOrigin {
120121
fn default() -> Self {
121-
ModuleOrigin::Root(None)
122+
ModuleOrigin::CrateRoot { definition: FileId(0) }
122123
}
123124
}
124125

125126
impl ModuleOrigin {
126-
fn root(file_id: FileId) -> Self {
127-
ModuleOrigin::Root(Some(file_id))
128-
}
129-
130127
pub(crate) fn not_sure_file(file: Option<FileId>, declaration: AstId<ast::Module>) -> Self {
131128
match file {
132129
None => ModuleOrigin::Inline { definition: declaration },
@@ -138,14 +135,14 @@ impl ModuleOrigin {
138135
match self {
139136
ModuleOrigin::File { declaration: module, .. }
140137
| ModuleOrigin::Inline { definition: module, .. } => Some(*module),
141-
ModuleOrigin::Root(_) => None,
138+
ModuleOrigin::CrateRoot { .. } => None,
142139
}
143140
}
144141

145142
pub(crate) fn file_id(&self) -> Option<FileId> {
146143
match self {
147-
ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => {
148-
Some(*file_id)
144+
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => {
145+
Some(*definition)
149146
}
150147
_ => None,
151148
}
@@ -155,12 +152,11 @@ impl ModuleOrigin {
155152
/// That is, a file or a `mod foo {}` with items.
156153
fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> {
157154
match self {
158-
ModuleOrigin::File { definition: file_id, .. } | ModuleOrigin::Root(Some(file_id)) => {
159-
let file_id = *file_id;
155+
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => {
156+
let file_id = *definition;
160157
let sf = db.parse(file_id).tree();
161158
return InFile::new(file_id.into(), ModuleSource::SourceFile(sf));
162159
}
163-
ModuleOrigin::Root(None) => unreachable!(),
164160
ModuleOrigin::Inline { definition } => {
165161
InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db)))
166162
}

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ where
131131
let file_id = crate_graph.crate_root(self.def_map.krate);
132132
let raw_items = self.db.raw_items(file_id.into());
133133
let module_id = self.def_map.root;
134-
self.def_map.modules[module_id].origin = ModuleOrigin::root(file_id);
134+
self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id };
135135
ModCollector {
136136
def_collector: &mut *self,
137137
module_id,

0 commit comments

Comments
 (0)