From d634364462931c0a4944de29b38681a482817b6b Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Sun, 10 Nov 2019 13:15:47 -0800 Subject: Overwrite the prelude with one defined in a later dependency This removes the special casing for the "core" prelude. Whenever a later dependency also exports a prelude, it will replace the formerly imported prelude. The utilized prelude then depends purely on import order. --- crates/ra_hir_def/src/nameres/collector.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir_def/src') 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) -> let crate_graph = db.crate_graph(); // populate external prelude - let mut prelude_is_core = false; for dep in crate_graph.dependencies(def_map.krate) { let dep_def_map = db.crate_def_map(dep.crate_id); 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) -> ); // look for the prelude - // If the prelude is the "core" prelude, try to replace it with a higher - // level prelude (e.g. "std") if available. - if def_map.prelude.is_none() || prelude_is_core { - let map = db.crate_def_map(dep.crate_id); - if map.prelude.is_some() { - def_map.prelude = map.prelude; - prelude_is_core = dep.name == "core"; - } + // If the dependency defines a prelude, we overwrite an already defined + // prelude. This is necessary to import the "std" prelude if a crate + // depends on both "core" and "std". + let dep_def_map = db.crate_def_map(dep.crate_id); + if dep_def_map.prelude.is_some() { + def_map.prelude = dep_def_map.prelude; } } -- cgit v1.2.3