mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Less mutability
This commit is contained in:
parent
a90401aeed
commit
bef899aa78
1 changed files with 23 additions and 19 deletions
|
@ -185,10 +185,12 @@ impl ProjectWorkspace {
|
||||||
let mut crate_graph = CrateGraph::default();
|
let mut crate_graph = CrateGraph::default();
|
||||||
match self {
|
match self {
|
||||||
ProjectWorkspace::Json { project } => {
|
ProjectWorkspace::Json { project } => {
|
||||||
let mut crates = FxHashMap::default();
|
let crates: FxHashMap<_, _> = project
|
||||||
for (id, krate) in project.crates.iter().enumerate() {
|
.crates
|
||||||
let crate_id = json_project::CrateId(id);
|
.iter()
|
||||||
if let Some(file_id) = load(&krate.root_module) {
|
.enumerate()
|
||||||
|
.filter_map(|(seq_index, krate)| {
|
||||||
|
let file_id = load(&krate.root_module)?;
|
||||||
let edition = match krate.edition {
|
let edition = match krate.edition {
|
||||||
json_project::Edition::Edition2015 => Edition::Edition2015,
|
json_project::Edition::Edition2015 => Edition::Edition2015,
|
||||||
json_project::Edition::Edition2018 => Edition::Edition2018,
|
json_project::Edition::Edition2018 => Edition::Edition2018,
|
||||||
|
@ -218,8 +220,8 @@ impl ProjectWorkspace {
|
||||||
.clone()
|
.clone()
|
||||||
.map(|it| proc_macro_client.by_dylib_path(&it));
|
.map(|it| proc_macro_client.by_dylib_path(&it));
|
||||||
// FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
|
// FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
|
||||||
crates.insert(
|
Some((
|
||||||
crate_id,
|
json_project::CrateId(seq_index),
|
||||||
crate_graph.add_crate_root(
|
crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
edition,
|
edition,
|
||||||
|
@ -230,9 +232,9 @@ impl ProjectWorkspace {
|
||||||
extern_source,
|
extern_source,
|
||||||
proc_macro.unwrap_or_default(),
|
proc_macro.unwrap_or_default(),
|
||||||
),
|
),
|
||||||
);
|
))
|
||||||
}
|
})
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
for (id, krate) in project.crates.iter().enumerate() {
|
for (id, krate) in project.crates.iter().enumerate() {
|
||||||
for dep in &krate.deps {
|
for dep in &krate.deps {
|
||||||
|
@ -256,9 +258,11 @@ impl ProjectWorkspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProjectWorkspace::Cargo { cargo, sysroot } => {
|
ProjectWorkspace::Cargo { cargo, sysroot } => {
|
||||||
let mut sysroot_crates = FxHashMap::default();
|
let sysroot_crates: FxHashMap<_, _> = sysroot
|
||||||
for krate in sysroot.crates() {
|
.crates()
|
||||||
if let Some(file_id) = load(&sysroot[krate].root) {
|
.filter_map(|krate| {
|
||||||
|
let file_id = load(&sysroot[krate].root)?;
|
||||||
|
|
||||||
// Crates from sysroot have `cfg(test)` disabled
|
// Crates from sysroot have `cfg(test)` disabled
|
||||||
let cfg_options = {
|
let cfg_options = {
|
||||||
let mut opts = default_cfg_options.clone();
|
let mut opts = default_cfg_options.clone();
|
||||||
|
@ -269,22 +273,22 @@ impl ProjectWorkspace {
|
||||||
let env = Env::default();
|
let env = Env::default();
|
||||||
let extern_source = ExternSource::default();
|
let extern_source = ExternSource::default();
|
||||||
let proc_macro = vec![];
|
let proc_macro = vec![];
|
||||||
|
let crate_name = CrateName::new(&sysroot[krate].name)
|
||||||
|
.expect("Sysroot crate names should not contain dashes");
|
||||||
|
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
Edition::Edition2018,
|
Edition::Edition2018,
|
||||||
Some(
|
Some(crate_name),
|
||||||
CrateName::new(&sysroot[krate].name)
|
|
||||||
.expect("Sysroot crate names should not contain dashes"),
|
|
||||||
),
|
|
||||||
cfg_options,
|
cfg_options,
|
||||||
env,
|
env,
|
||||||
extern_source,
|
extern_source,
|
||||||
proc_macro,
|
proc_macro,
|
||||||
);
|
);
|
||||||
sysroot_crates.insert(krate, crate_id);
|
Some((krate, crate_id))
|
||||||
}
|
})
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
for from in sysroot.crates() {
|
for from in sysroot.crates() {
|
||||||
for &to in sysroot[from].deps.iter() {
|
for &to in sysroot[from].deps.iter() {
|
||||||
let name = &sysroot[to].name;
|
let name = &sysroot[to].name;
|
||||||
|
|
Loading…
Reference in a new issue