From b68ef1231daf6eb1abeb06a30dc89af1254b833d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 21 Jul 2020 17:17:21 +0200 Subject: [PATCH] More Rustic API for Env --- crates/ra_db/src/fixture.rs | 2 +- crates/ra_db/src/input.rs | 17 ++++------------- crates/ra_ide/src/mock_analysis.rs | 4 ++-- crates/ra_project_model/src/lib.rs | 5 +---- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 2097139877..2aafb99654 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -222,7 +222,7 @@ impl From for FileMeta { .edition .as_ref() .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), - env: Env::from(f.env.iter()), + env: f.env.into_iter().collect(), } } } diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index aaa4927596..6f2e5cfc76 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -6,7 +6,7 @@ //! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how //! actual IO is done and lowered to input. -use std::{fmt, ops, str::FromStr, sync::Arc}; +use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; use ra_cfg::CfgOptions; use ra_syntax::SmolStr; @@ -298,18 +298,9 @@ impl fmt::Display for Edition { } } -impl<'a, T> From for Env -where - T: Iterator, -{ - fn from(iter: T) -> Self { - let mut result = Self::default(); - - for (k, v) in iter { - result.entries.insert(k.to_owned(), v.to_owned()); - } - - result +impl FromIterator<(String, String)> for Env { + fn from_iter>(iter: T) -> Self { + Env { entries: FromIterator::from_iter(iter) } } } diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index b280546887..c7e0f4b58f 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; -use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; +use ra_db::{CrateName, FileSet, SourceRoot, VfsPath}; use test_utils::{ extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, }; @@ -110,7 +110,7 @@ impl MockAnalysis { data.edition.and_then(|it| it.parse().ok()).unwrap_or(Edition::Edition2018); let file_id = FileId(i as u32 + 1); - let env = Env::from(data.env.iter()); + let env = data.env.into_iter().collect(); if path == "/lib.rs" || path == "/main.rs" { root_crate = Some(crate_graph.add_crate_root( file_id, diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 2bb1566105..6da4d7928a 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -258,10 +258,7 @@ impl ProjectWorkspace { let file_path = &krate.root_module; let file_id = load(&file_path)?; - let mut env = Env::default(); - for (k, v) in &krate.env { - env.set(k, v.clone()); - } + let env = krate.env.clone().into_iter().collect(); let proc_macro = krate .proc_macro_dylib_path .clone()