Skip to content

Commit b68ef12

Browse files
committed
More Rustic API for Env
1 parent eb613c7 commit b68ef12

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

crates/ra_db/src/fixture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl From<Fixture> for FileMeta {
222222
.edition
223223
.as_ref()
224224
.map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()),
225-
env: Env::from(f.env.iter()),
225+
env: f.env.into_iter().collect(),
226226
}
227227
}
228228
}

crates/ra_db/src/input.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77
//! actual IO is done and lowered to input.
88
9-
use std::{fmt, ops, str::FromStr, sync::Arc};
9+
use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
1010

1111
use ra_cfg::CfgOptions;
1212
use ra_syntax::SmolStr;
@@ -298,18 +298,9 @@ impl fmt::Display for Edition {
298298
}
299299
}
300300

301-
impl<'a, T> From<T> for Env
302-
where
303-
T: Iterator<Item = (&'a String, &'a String)>,
304-
{
305-
fn from(iter: T) -> Self {
306-
let mut result = Self::default();
307-
308-
for (k, v) in iter {
309-
result.entries.insert(k.to_owned(), v.to_owned());
310-
}
311-
312-
result
301+
impl FromIterator<(String, String)> for Env {
302+
fn from_iter<T: IntoIterator<Item = (String, String)>>(iter: T) -> Self {
303+
Env { entries: FromIterator::from_iter(iter) }
313304
}
314305
}
315306

crates/ra_ide/src/mock_analysis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::sync::Arc;
33

44
use ra_cfg::CfgOptions;
5-
use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath};
5+
use ra_db::{CrateName, FileSet, SourceRoot, VfsPath};
66
use test_utils::{
77
extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER,
88
};
@@ -110,7 +110,7 @@ impl MockAnalysis {
110110
data.edition.and_then(|it| it.parse().ok()).unwrap_or(Edition::Edition2018);
111111

112112
let file_id = FileId(i as u32 + 1);
113-
let env = Env::from(data.env.iter());
113+
let env = data.env.into_iter().collect();
114114
if path == "/lib.rs" || path == "/main.rs" {
115115
root_crate = Some(crate_graph.add_crate_root(
116116
file_id,

crates/ra_project_model/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,7 @@ impl ProjectWorkspace {
258258
let file_path = &krate.root_module;
259259
let file_id = load(&file_path)?;
260260

261-
let mut env = Env::default();
262-
for (k, v) in &krate.env {
263-
env.set(k, v.clone());
264-
}
261+
let env = krate.env.clone().into_iter().collect();
265262
let proc_macro = krate
266263
.proc_macro_dylib_path
267264
.clone()

0 commit comments

Comments
 (0)