From 799903ba16dd0d80ca975a2e0e58e81f71ddc023 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Sat, 9 Nov 2019 15:22:19 -0800 Subject: Resolve core types This adds support for completion and goto definition of types defined within the "core" crate. The core crate is added as a dependency to each crate in the project. The core crate exported it's own prelude. This caused now all crates to inherit the core crates prelude instead of the std crates. In order to avoid the problem the prelude resolution has been changed to overwrite an already resolved prelude if this was set to a crate named core - in order to pick a better prelude like std. Fixes #2199 --- crates/ra_project_model/src/lib.rs | 8 +++++++- crates/ra_project_model/src/sysroot.rs | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/ra_project_model') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 8b8663a78..b1268f29b 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -199,6 +199,7 @@ impl ProjectWorkspace { } } + let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); let mut pkg_to_lib_crate = FxHashMap::default(); @@ -226,7 +227,7 @@ impl ProjectWorkspace { } } - // Set deps to the std and to the lib target of the current package + // Set deps to the core, std and to the lib target of the current package for &from in pkg_crates.get(&pkg).into_iter().flatten() { if let Some(to) = lib_tgt { if to != from { @@ -240,6 +241,11 @@ impl ProjectWorkspace { } } } + if let Some(core) = libcore { + if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { + log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) + } + } if let Some(std) = libstd { if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 35d6df5cb..3d827809e 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -27,6 +27,10 @@ struct SysrootCrateData { } impl Sysroot { + pub fn core(&self) -> Option { + self.by_name("core") + } + pub fn std(&self) -> Option { self.by_name("std") } -- cgit v1.2.3 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_project_model/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_project_model') 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 { } } } + // core is added as a dependency before std in order to + // mimic rustcs dependency order if let Some(core) = libcore { if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) -- cgit v1.2.3