diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-13 20:14:39 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-13 20:14:39 +0000 |
commit | cb4327b3a9f0858235dc20b7c5c7e25c6c330aab (patch) | |
tree | 489b3497b2762dcabf60d2674031585431e16959 /crates/ra_project_model/src/lib.rs | |
parent | 65266c644a31e6b321e5afb3c5a2ee75be76cb0c (diff) | |
parent | 911e32bca9b73e66eceb6bbee3768c82e94597d5 (diff) |
Merge #816
816: Prelude & Edition 2015 import resolution r=matklad a=flodiebold
I implemented the prelude import, but it turned out to be useless without being able to resolve any of the imports in the prelude :sweat_smile: So I had to add some edition handling and handle 2015-style imports (at least the simplified scheme proposed in rust-lang/rust#57745). So now finally `Option` resolves :smile:
One remaining problem is that we don't actually know the edition for sysroot crates. They're currently hardcoded to 2015, but there's already a bunch of PRs upgrading the editions of various rustc crates, so we'll have to detect the edition somehow, or just change the hardcoding to 2018 later, I guess...
~Also currently missing is completion for prelude names, though that shouldn't be hard to add. And `Vec` still doesn't resolve, so I need to look into that.~
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 3b1e07149..1b18ac836 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; | |||
6 | use failure::bail; | 6 | use failure::bail; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | 8 | ||
9 | use ra_db::{CrateGraph, FileId}; | 9 | use ra_db::{CrateGraph, FileId, Edition}; |
10 | 10 | ||
11 | pub use crate::{ | 11 | pub use crate::{ |
12 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, | 12 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, |
@@ -36,7 +36,8 @@ impl ProjectWorkspace { | |||
36 | let mut sysroot_crates = FxHashMap::default(); | 36 | let mut sysroot_crates = FxHashMap::default(); |
37 | for krate in self.sysroot.crates() { | 37 | for krate in self.sysroot.crates() { |
38 | if let Some(file_id) = load(krate.root(&self.sysroot)) { | 38 | if let Some(file_id) = load(krate.root(&self.sysroot)) { |
39 | sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id)); | 39 | sysroot_crates |
40 | .insert(krate, crate_graph.add_crate_root(file_id, Edition::Edition2015)); | ||
40 | } | 41 | } |
41 | } | 42 | } |
42 | for from in self.sysroot.crates() { | 43 | for from in self.sysroot.crates() { |
@@ -62,7 +63,8 @@ impl ProjectWorkspace { | |||
62 | for tgt in pkg.targets(&self.cargo) { | 63 | for tgt in pkg.targets(&self.cargo) { |
63 | let root = tgt.root(&self.cargo); | 64 | let root = tgt.root(&self.cargo); |
64 | if let Some(file_id) = load(root) { | 65 | if let Some(file_id) = load(root) { |
65 | let crate_id = crate_graph.add_crate_root(file_id); | 66 | let edition = pkg.edition(&self.cargo); |
67 | let crate_id = crate_graph.add_crate_root(file_id, edition); | ||
66 | if tgt.kind(&self.cargo) == TargetKind::Lib { | 68 | if tgt.kind(&self.cargo) == TargetKind::Lib { |
67 | lib_tgt = Some(crate_id); | 69 | lib_tgt = Some(crate_id); |
68 | pkg_to_lib_crate.insert(pkg, crate_id); | 70 | pkg_to_lib_crate.insert(pkg, crate_id); |