aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-03 22:23:22 +0000
committerFlorian Diebold <[email protected]>2019-02-04 20:49:34 +0000
commit1056b480d6235ee72849a416b84e13180f84307c (patch)
tree7c9cf6822357bff4bd4d2055f464bf9991c8e4a4 /crates/ra_hir/src/nameres
parentd69023fc72b26e64ebf1f96fc322a2f7377a5f4d (diff)
Make extern crates in the root module add to the extern prelude
To accomplish this, separate the extern prelude from the per-module item maps.
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/lower.rs3
-rw-r--r--crates/ra_hir/src/nameres/tests.rs12
2 files changed, 7 insertions, 8 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index db898a782..7e6e48ae0 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -23,6 +23,7 @@ pub(super) struct ImportData {
23 pub(super) path: Path, 23 pub(super) path: Path,
24 pub(super) alias: Option<Name>, 24 pub(super) alias: Option<Name>,
25 pub(super) is_glob: bool, 25 pub(super) is_glob: bool,
26 pub(super) is_extern_crate: bool,
26} 27}
27 28
28/// A set of items and imports declared inside a module, without relation to 29/// A set of items and imports declared inside a module, without relation to
@@ -199,6 +200,7 @@ impl LoweredModule {
199 path, 200 path,
200 alias, 201 alias,
201 is_glob: false, 202 is_glob: false,
203 is_extern_crate: true,
202 }); 204 });
203 } 205 }
204 } 206 }
@@ -228,6 +230,7 @@ impl LoweredModule {
228 path, 230 path,
229 alias, 231 alias,
230 is_glob: segment.is_none(), 232 is_glob: segment.is_none(),
233 is_extern_crate: false,
231 }); 234 });
232 if let Some(segment) = segment { 235 if let Some(segment) = segment {
233 source_map.insert(import, segment) 236 source_map.insert(import, segment)
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 42c59f76f..0654dbaa1 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -329,7 +329,6 @@ 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
333 ", 332 ",
334 ); 333 );
335} 334}
@@ -342,7 +341,9 @@ fn extern_crate_rename() {
342 extern crate alloc as alloc_crate; 341 extern crate alloc as alloc_crate;
343 342
344 mod alloc; 343 mod alloc;
344 mod sync;
345 345
346 //- /sync.rs
346 use alloc_crate::Arc; 347 use alloc_crate::Arc;
347 348
348 //- /lib.rs 349 //- /lib.rs
@@ -350,6 +351,7 @@ fn extern_crate_rename() {
350 ", 351 ",
351 ); 352 );
352 let main_id = sr.files[RelativePath::new("/main.rs")]; 353 let main_id = sr.files[RelativePath::new("/main.rs")];
354 let sync_id = sr.files[RelativePath::new("/sync.rs")];
353 let lib_id = sr.files[RelativePath::new("/lib.rs")]; 355 let lib_id = sr.files[RelativePath::new("/lib.rs")];
354 356
355 let mut crate_graph = CrateGraph::default(); 357 let mut crate_graph = CrateGraph::default();
@@ -361,7 +363,7 @@ fn extern_crate_rename() {
361 363
362 db.set_crate_graph(Arc::new(crate_graph)); 364 db.set_crate_graph(Arc::new(crate_graph));
363 365
364 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); 366 let module = crate::source_binder::module_from_file_id(&db, sync_id).unwrap();
365 let krate = module.krate(&db).unwrap(); 367 let krate = module.krate(&db).unwrap();
366 let item_map = db.item_map(krate); 368 let item_map = db.item_map(krate);
367 369
@@ -370,8 +372,6 @@ fn extern_crate_rename() {
370 module.module_id, 372 module.module_id,
371 " 373 "
372 Arc: t v 374 Arc: t v
373 alloc: t
374 alloc_crate: t
375 ", 375 ",
376 ); 376 );
377} 377}
@@ -403,8 +403,6 @@ fn import_across_source_roots() {
403 403
404 let main_id = sr2.files[RelativePath::new("/main.rs")]; 404 let main_id = sr2.files[RelativePath::new("/main.rs")];
405 405
406 eprintln!("lib = {:?}, main = {:?}", lib_id, main_id);
407
408 let mut crate_graph = CrateGraph::default(); 406 let mut crate_graph = CrateGraph::default();
409 let main_crate = crate_graph.add_crate_root(main_id); 407 let main_crate = crate_graph.add_crate_root(main_id);
410 let lib_crate = crate_graph.add_crate_root(lib_id); 408 let lib_crate = crate_graph.add_crate_root(lib_id);
@@ -423,7 +421,6 @@ fn import_across_source_roots() {
423 module.module_id, 421 module.module_id,
424 " 422 "
425 C: t v 423 C: t v
426 test_crate: t
427 ", 424 ",
428 ); 425 );
429} 426}
@@ -465,7 +462,6 @@ fn reexport_across_crates() {
465 module.module_id, 462 module.module_id,
466 " 463 "
467 Baz: t v 464 Baz: t v
468 test_crate: t
469 ", 465 ",
470 ); 466 );
471} 467}