diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_hir/src/nameres | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/lower.rs | 31 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 34 |
2 files changed, 17 insertions, 48 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 7e6e48ae0..7e9a3de2b 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs | |||
@@ -82,13 +82,9 @@ impl LoweredModule { | |||
82 | let mut source_map = ImportSourceMap::default(); | 82 | let mut source_map = ImportSourceMap::default(); |
83 | let mut res = LoweredModule::default(); | 83 | let mut res = LoweredModule::default(); |
84 | match source { | 84 | match source { |
85 | ModuleSource::SourceFile(it) => res.fill( | 85 | ModuleSource::SourceFile(it) => { |
86 | &mut source_map, | 86 | res.fill(&mut source_map, db, module, file_id, &mut it.items_with_macros()) |
87 | db, | 87 | } |
88 | module, | ||
89 | file_id, | ||
90 | &mut it.items_with_macros(), | ||
91 | ), | ||
92 | ModuleSource::Module(it) => { | 88 | ModuleSource::Module(it) => { |
93 | if let Some(item_list) = it.item_list() { | 89 | if let Some(item_list) = it.item_list() { |
94 | res.fill( | 90 | res.fill( |
@@ -121,10 +117,8 @@ impl LoweredModule { | |||
121 | } | 117 | } |
122 | ast::ItemOrMacro::Macro(macro_call) => { | 118 | ast::ItemOrMacro::Macro(macro_call) => { |
123 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); | 119 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); |
124 | let loc = MacroCallLoc { | 120 | let loc = |
125 | module, | 121 | MacroCallLoc { module, source_item_id: SourceItemId { file_id, item_id } }; |
126 | source_item_id: SourceItemId { file_id, item_id }, | ||
127 | }; | ||
128 | let id = loc.id(db); | 122 | let id = loc.id(db); |
129 | let file_id = HirFileId::from(id); | 123 | let file_id = HirFileId::from(id); |
130 | //FIXME: expand recursively | 124 | //FIXME: expand recursively |
@@ -163,22 +157,19 @@ impl LoweredModule { | |||
163 | ast::ModuleItemKind::FnDef(it) => { | 157 | ast::ModuleItemKind::FnDef(it) => { |
164 | if let Some(name) = it.name() { | 158 | if let Some(name) = it.name() { |
165 | let func = Function { id: ctx.to_def(it) }; | 159 | let func = Function { id: ctx.to_def(it) }; |
166 | self.declarations | 160 | self.declarations.insert(name.as_name(), PerNs::values(func.into())); |
167 | .insert(name.as_name(), PerNs::values(func.into())); | ||
168 | } | 161 | } |
169 | } | 162 | } |
170 | ast::ModuleItemKind::TraitDef(it) => { | 163 | ast::ModuleItemKind::TraitDef(it) => { |
171 | if let Some(name) = it.name() { | 164 | if let Some(name) = it.name() { |
172 | let t = Trait { id: ctx.to_def(it) }; | 165 | let t = Trait { id: ctx.to_def(it) }; |
173 | self.declarations | 166 | self.declarations.insert(name.as_name(), PerNs::types(t.into())); |
174 | .insert(name.as_name(), PerNs::types(t.into())); | ||
175 | } | 167 | } |
176 | } | 168 | } |
177 | ast::ModuleItemKind::TypeDef(it) => { | 169 | ast::ModuleItemKind::TypeDef(it) => { |
178 | if let Some(name) = it.name() { | 170 | if let Some(name) = it.name() { |
179 | let t = Type { id: ctx.to_def(it) }; | 171 | let t = Type { id: ctx.to_def(it) }; |
180 | self.declarations | 172 | self.declarations.insert(name.as_name(), PerNs::types(t.into())); |
181 | .insert(name.as_name(), PerNs::types(t.into())); | ||
182 | } | 173 | } |
183 | } | 174 | } |
184 | ast::ModuleItemKind::ImplBlock(_) => { | 175 | ast::ModuleItemKind::ImplBlock(_) => { |
@@ -207,15 +198,13 @@ impl LoweredModule { | |||
207 | ast::ModuleItemKind::ConstDef(it) => { | 198 | ast::ModuleItemKind::ConstDef(it) => { |
208 | if let Some(name) = it.name() { | 199 | if let Some(name) = it.name() { |
209 | let c = Const { id: ctx.to_def(it) }; | 200 | let c = Const { id: ctx.to_def(it) }; |
210 | self.declarations | 201 | self.declarations.insert(name.as_name(), PerNs::values(c.into())); |
211 | .insert(name.as_name(), PerNs::values(c.into())); | ||
212 | } | 202 | } |
213 | } | 203 | } |
214 | ast::ModuleItemKind::StaticDef(it) => { | 204 | ast::ModuleItemKind::StaticDef(it) => { |
215 | if let Some(name) = it.name() { | 205 | if let Some(name) = it.name() { |
216 | let s = Static { id: ctx.to_def(it) }; | 206 | let s = Static { id: ctx.to_def(it) }; |
217 | self.declarations | 207 | self.declarations.insert(name.as_name(), PerNs::values(s.into())); |
218 | .insert(name.as_name(), PerNs::values(s.into())); | ||
219 | } | 208 | } |
220 | } | 209 | } |
221 | ast::ModuleItemKind::Module(_) => { | 210 | ast::ModuleItemKind::Module(_) => { |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 0654dbaa1..3dfad6bf2 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -42,19 +42,11 @@ fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { | |||
42 | .collect::<Vec<_>>(); | 42 | .collect::<Vec<_>>(); |
43 | lines.sort(); | 43 | lines.sort(); |
44 | let actual = lines.join("\n"); | 44 | let actual = lines.join("\n"); |
45 | let expected = expected | 45 | let expected = expected.trim().lines().map(|it| it.trim()).collect::<Vec<_>>().join("\n"); |
46 | .trim() | ||
47 | .lines() | ||
48 | .map(|it| it.trim()) | ||
49 | .collect::<Vec<_>>() | ||
50 | .join("\n"); | ||
51 | assert_eq_text!(&expected, &actual); | 46 | assert_eq_text!(&expected, &actual); |
52 | 47 | ||
53 | fn dump_resolution(resolution: &Resolution) -> &'static str { | 48 | fn dump_resolution(resolution: &Resolution) -> &'static str { |
54 | match ( | 49 | match (resolution.def.types.is_some(), resolution.def.values.is_some()) { |
55 | resolution.def.types.is_some(), | ||
56 | resolution.def.values.is_some(), | ||
57 | ) { | ||
58 | (true, true) => "t v", | 50 | (true, true) => "t v", |
59 | (true, false) => "t", | 51 | (true, false) => "t", |
60 | (false, true) => "v", | 52 | (false, true) => "v", |
@@ -314,9 +306,7 @@ fn item_map_across_crates() { | |||
314 | let mut crate_graph = CrateGraph::default(); | 306 | let mut crate_graph = CrateGraph::default(); |
315 | let main_crate = crate_graph.add_crate_root(main_id); | 307 | let main_crate = crate_graph.add_crate_root(main_id); |
316 | let lib_crate = crate_graph.add_crate_root(lib_id); | 308 | let lib_crate = crate_graph.add_crate_root(lib_id); |
317 | crate_graph | 309 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); |
318 | .add_dep(main_crate, "test_crate".into(), lib_crate) | ||
319 | .unwrap(); | ||
320 | 310 | ||
321 | db.set_crate_graph(Arc::new(crate_graph)); | 311 | db.set_crate_graph(Arc::new(crate_graph)); |
322 | 312 | ||
@@ -357,9 +347,7 @@ fn extern_crate_rename() { | |||
357 | let mut crate_graph = CrateGraph::default(); | 347 | let mut crate_graph = CrateGraph::default(); |
358 | let main_crate = crate_graph.add_crate_root(main_id); | 348 | let main_crate = crate_graph.add_crate_root(main_id); |
359 | let lib_crate = crate_graph.add_crate_root(lib_id); | 349 | let lib_crate = crate_graph.add_crate_root(lib_id); |
360 | crate_graph | 350 | crate_graph.add_dep(main_crate, "alloc".into(), lib_crate).unwrap(); |
361 | .add_dep(main_crate, "alloc".into(), lib_crate) | ||
362 | .unwrap(); | ||
363 | 351 | ||
364 | db.set_crate_graph(Arc::new(crate_graph)); | 352 | db.set_crate_graph(Arc::new(crate_graph)); |
365 | 353 | ||
@@ -406,9 +394,7 @@ fn import_across_source_roots() { | |||
406 | let mut crate_graph = CrateGraph::default(); | 394 | let mut crate_graph = CrateGraph::default(); |
407 | let main_crate = crate_graph.add_crate_root(main_id); | 395 | let main_crate = crate_graph.add_crate_root(main_id); |
408 | let lib_crate = crate_graph.add_crate_root(lib_id); | 396 | let lib_crate = crate_graph.add_crate_root(lib_id); |
409 | crate_graph | 397 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); |
410 | .add_dep(main_crate, "test_crate".into(), lib_crate) | ||
411 | .unwrap(); | ||
412 | 398 | ||
413 | db.set_crate_graph(Arc::new(crate_graph)); | 399 | db.set_crate_graph(Arc::new(crate_graph)); |
414 | 400 | ||
@@ -447,9 +433,7 @@ fn reexport_across_crates() { | |||
447 | let mut crate_graph = CrateGraph::default(); | 433 | let mut crate_graph = CrateGraph::default(); |
448 | let main_crate = crate_graph.add_crate_root(main_id); | 434 | let main_crate = crate_graph.add_crate_root(main_id); |
449 | let lib_crate = crate_graph.add_crate_root(lib_id); | 435 | let lib_crate = crate_graph.add_crate_root(lib_id); |
450 | crate_graph | 436 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); |
451 | .add_dep(main_crate, "test_crate".into(), lib_crate) | ||
452 | .unwrap(); | ||
453 | 437 | ||
454 | db.set_crate_graph(Arc::new(crate_graph)); | 438 | db.set_crate_graph(Arc::new(crate_graph)); |
455 | 439 | ||
@@ -482,11 +466,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
482 | let events = db.log_executed(|| { | 466 | let events = db.log_executed(|| { |
483 | db.item_map(krate); | 467 | db.item_map(krate); |
484 | }); | 468 | }); |
485 | assert!( | 469 | assert!(!format!("{:?}", events).contains("item_map"), "{:#?}", events) |
486 | !format!("{:?}", events).contains("item_map"), | ||
487 | "{:#?}", | ||
488 | events | ||
489 | ) | ||
490 | } | 470 | } |
491 | } | 471 | } |
492 | 472 | ||