diff options
author | Seivan Heidari <[email protected]> | 2019-11-10 22:37:09 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-10 22:37:09 +0000 |
commit | 7cd075ff0beb97039cd1d1c6c021abf89339731b (patch) | |
tree | f814966917cabe3fa3fc56a60b1942442a8e57fd /crates/ra_hir_def | |
parent | 3886164bcce734825d20a1af08ce359fbe0710e3 (diff) | |
parent | 7973fd66e9a7f178b0963675c62233474dcec954 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests.rs | 31 |
2 files changed, 37 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7e6083961..6db9937a4 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -36,11 +36,12 @@ pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> | |||
36 | ); | 36 | ); |
37 | 37 | ||
38 | // look for the prelude | 38 | // look for the prelude |
39 | if def_map.prelude.is_none() { | 39 | // If the dependency defines a prelude, we overwrite an already defined |
40 | let map = db.crate_def_map(dep.crate_id); | 40 | // prelude. This is necessary to import the "std" prelude if a crate |
41 | if map.prelude.is_some() { | 41 | // depends on both "core" and "std". |
42 | def_map.prelude = map.prelude; | 42 | let dep_def_map = db.crate_def_map(dep.crate_id); |
43 | } | 43 | if dep_def_map.prelude.is_some() { |
44 | def_map.prelude = dep_def_map.prelude; | ||
44 | } | 45 | } |
45 | } | 46 | } |
46 | 47 | ||
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 52bd0aa91..256f7d4be 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs | |||
@@ -464,6 +464,37 @@ fn values_dont_shadow_extern_crates() { | |||
464 | } | 464 | } |
465 | 465 | ||
466 | #[test] | 466 | #[test] |
467 | fn std_prelude_takes_precedence_above_core_prelude() { | ||
468 | let map = def_map( | ||
469 | r#" | ||
470 | //- /main.rs crate:main deps:core,std | ||
471 | use {Foo, Bar}; | ||
472 | |||
473 | //- /std.rs crate:std deps:core | ||
474 | #[prelude_import] | ||
475 | pub use self::prelude::*; | ||
476 | mod prelude { | ||
477 | pub struct Foo; | ||
478 | pub use core::prelude::Bar; | ||
479 | } | ||
480 | |||
481 | //- /core.rs crate:core | ||
482 | #[prelude_import] | ||
483 | pub use self::prelude::*; | ||
484 | mod prelude { | ||
485 | pub struct Bar; | ||
486 | } | ||
487 | "#, | ||
488 | ); | ||
489 | |||
490 | assert_snapshot!(map, @r###" | ||
491 | ⋮crate | ||
492 | ⋮Bar: t v | ||
493 | ⋮Foo: t v | ||
494 | "###); | ||
495 | } | ||
496 | |||
497 | #[test] | ||
467 | fn cfg_not_test() { | 498 | fn cfg_not_test() { |
468 | let map = def_map( | 499 | let map = def_map( |
469 | r#" | 500 | r#" |