mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Make edition handling a bit nicer and allow specifying edition in crate_graph macro
This commit is contained in:
parent
d5ad38cbb8
commit
70839b7ef8
5 changed files with 28 additions and 25 deletions
|
@ -4,6 +4,7 @@ use cargo_metadata::{MetadataCommand, CargoOpt};
|
|||
use ra_arena::{Arena, RawId, impl_arena_id};
|
||||
use rustc_hash::FxHashMap;
|
||||
use failure::format_err;
|
||||
use ra_db::Edition;
|
||||
|
||||
use crate::Result;
|
||||
|
||||
|
@ -35,7 +36,7 @@ struct PackageData {
|
|||
targets: Vec<Target>,
|
||||
is_member: bool,
|
||||
dependencies: Vec<PackageDependency>,
|
||||
edition: String,
|
||||
edition: Edition,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -85,8 +86,8 @@ impl Package {
|
|||
pub fn root(self, ws: &CargoWorkspace) -> &Path {
|
||||
ws.packages[self].manifest.parent().unwrap()
|
||||
}
|
||||
pub fn edition(self, ws: &CargoWorkspace) -> &str {
|
||||
&ws.packages[self].edition
|
||||
pub fn edition(self, ws: &CargoWorkspace) -> Edition {
|
||||
ws.packages[self].edition
|
||||
}
|
||||
pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a {
|
||||
ws.packages[self].targets.iter().cloned()
|
||||
|
@ -139,7 +140,7 @@ impl CargoWorkspace {
|
|||
manifest: meta_pkg.manifest_path.clone(),
|
||||
targets: Vec::new(),
|
||||
is_member,
|
||||
edition: meta_pkg.edition,
|
||||
edition: Edition::from_string(&meta_pkg.edition),
|
||||
dependencies: Vec::new(),
|
||||
});
|
||||
let pkg_data = &mut packages[pkg];
|
||||
|
|
|
@ -63,11 +63,7 @@ impl ProjectWorkspace {
|
|||
for tgt in pkg.targets(&self.cargo) {
|
||||
let root = tgt.root(&self.cargo);
|
||||
if let Some(file_id) = load(root) {
|
||||
let edition = if pkg.edition(&self.cargo) == "2015" {
|
||||
Edition::Edition2015
|
||||
} else {
|
||||
Edition::Edition2018
|
||||
};
|
||||
let edition = pkg.edition(&self.cargo);
|
||||
let crate_id = crate_graph.add_crate_root(file_id, edition);
|
||||
if tgt.kind(&self.cargo) == TargetKind::Lib {
|
||||
lib_tgt = Some(crate_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue