aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-05 07:53:08 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-05 07:53:08 +0000
commit4d4c46aff8f9a7ce8c2f91fbe6c7c363f5d3e08c (patch)
tree90473c4a67ac70ee40fde54a25b11d7768c41593 /crates/ra_hir/src/nameres/tests.rs
parent94d5d0d7e893a50bdd22ce4366ca15f083218d22 (diff)
parentde4c5e381fb1adc25143dcd67af6c87f6d9789ae (diff)
Merge #742
742: Extern crate r=matklad a=flodiebold This implements `extern crate` declarations by lowering them to (absolute) imports, and adds support for absolute paths. It also extracts the extern prelude from the per-module item map, and handles the special case of extern crates in the crate root adding to the extern prelude. This means we finally resolve `Arc`, so it fixes #523 :smile: Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres/tests.rs')
-rw-r--r--crates/ra_hir/src/nameres/tests.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 81c8a4f12..0654dbaa1 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -329,7 +329,49 @@ fn item_map_across_crates() {
329 module.module_id, 329 module.module_id,
330 " 330 "
331 Baz: t v 331 Baz: t v
332 test_crate: t 332 ",
333 );
334}
335
336#[test]
337fn extern_crate_rename() {
338 let (mut db, sr) = MockDatabase::with_files(
339 "
340 //- /main.rs
341 extern crate alloc as alloc_crate;
342
343 mod alloc;
344 mod sync;
345
346 //- /sync.rs
347 use alloc_crate::Arc;
348
349 //- /lib.rs
350 struct Arc;
351 ",
352 );
353 let main_id = sr.files[RelativePath::new("/main.rs")];
354 let sync_id = sr.files[RelativePath::new("/sync.rs")];
355 let lib_id = sr.files[RelativePath::new("/lib.rs")];
356
357 let mut crate_graph = CrateGraph::default();
358 let main_crate = crate_graph.add_crate_root(main_id);
359 let lib_crate = crate_graph.add_crate_root(lib_id);
360 crate_graph
361 .add_dep(main_crate, "alloc".into(), lib_crate)
362 .unwrap();
363
364 db.set_crate_graph(Arc::new(crate_graph));
365
366 let module = crate::source_binder::module_from_file_id(&db, sync_id).unwrap();
367 let krate = module.krate(&db).unwrap();
368 let item_map = db.item_map(krate);
369
370 check_module_item_map(
371 &item_map,
372 module.module_id,
373 "
374 Arc: t v
333 ", 375 ",
334 ); 376 );
335} 377}
@@ -361,8 +403,6 @@ fn import_across_source_roots() {
361 403
362 let main_id = sr2.files[RelativePath::new("/main.rs")]; 404 let main_id = sr2.files[RelativePath::new("/main.rs")];
363 405
364 eprintln!("lib = {:?}, main = {:?}", lib_id, main_id);
365
366 let mut crate_graph = CrateGraph::default(); 406 let mut crate_graph = CrateGraph::default();
367 let main_crate = crate_graph.add_crate_root(main_id); 407 let main_crate = crate_graph.add_crate_root(main_id);
368 let lib_crate = crate_graph.add_crate_root(lib_id); 408 let lib_crate = crate_graph.add_crate_root(lib_id);
@@ -381,7 +421,6 @@ fn import_across_source_roots() {
381 module.module_id, 421 module.module_id,
382 " 422 "
383 C: t v 423 C: t v
384 test_crate: t
385 ", 424 ",
386 ); 425 );
387} 426}
@@ -423,7 +462,6 @@ fn reexport_across_crates() {
423 module.module_id, 462 module.module_id,
424 " 463 "
425 Baz: t v 464 Baz: t v
426 test_crate: t
427 ", 465 ",
428 ); 466 );
429} 467}