diff options
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 15 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 2 |
2 files changed, 8 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 36a61dc3d..6db9937a4 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -27,7 +27,6 @@ pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> | |||
27 | let crate_graph = db.crate_graph(); | 27 | let crate_graph = db.crate_graph(); |
28 | 28 | ||
29 | // populate external prelude | 29 | // populate external prelude |
30 | let mut prelude_is_core = false; | ||
31 | for dep in crate_graph.dependencies(def_map.krate) { | 30 | for dep in crate_graph.dependencies(def_map.krate) { |
32 | let dep_def_map = db.crate_def_map(dep.crate_id); | 31 | let dep_def_map = db.crate_def_map(dep.crate_id); |
33 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 32 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
@@ -37,14 +36,12 @@ pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> | |||
37 | ); | 36 | ); |
38 | 37 | ||
39 | // look for the prelude | 38 | // look for the prelude |
40 | // If the prelude is the "core" prelude, try to replace it with a higher | 39 | // If the dependency defines a prelude, we overwrite an already defined |
41 | // level prelude (e.g. "std") if available. | 40 | // prelude. This is necessary to import the "std" prelude if a crate |
42 | if def_map.prelude.is_none() || prelude_is_core { | 41 | // depends on both "core" and "std". |
43 | let map = db.crate_def_map(dep.crate_id); | 42 | let dep_def_map = db.crate_def_map(dep.crate_id); |
44 | if map.prelude.is_some() { | 43 | if dep_def_map.prelude.is_some() { |
45 | def_map.prelude = map.prelude; | 44 | def_map.prelude = dep_def_map.prelude; |
46 | prelude_is_core = dep.name == "core"; | ||
47 | } | ||
48 | } | 45 | } |
49 | } | 46 | } |
50 | 47 | ||
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index b1268f29b..0e14f1b70 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -241,6 +241,8 @@ impl ProjectWorkspace { | |||
241 | } | 241 | } |
242 | } | 242 | } |
243 | } | 243 | } |
244 | // core is added as a dependency before std in order to | ||
245 | // mimic rustcs dependency order | ||
244 | if let Some(core) = libcore { | 246 | if let Some(core) = libcore { |
245 | if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { | 247 | if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { |
246 | log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) | 248 | log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) |