Skip to content

Commit fc230b9

Browse files
committed
Simplify Sysroot
1 parent 516fe29 commit fc230b9

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

crates/ra_project_model/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl ProjectWorkspace {
143143
roots.push(PackageRoot::new(root, member));
144144
}
145145
for krate in sysroot.crates() {
146-
roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false))
146+
roots.push(PackageRoot::new(sysroot[krate].root_dir().to_path_buf(), false))
147147
}
148148
roots
149149
}
@@ -260,7 +260,7 @@ impl ProjectWorkspace {
260260
ProjectWorkspace::Cargo { cargo, sysroot } => {
261261
let mut sysroot_crates = FxHashMap::default();
262262
for krate in sysroot.crates() {
263-
if let Some(file_id) = load(krate.root(&sysroot)) {
263+
if let Some(file_id) = load(&sysroot[krate].root) {
264264
// Crates from sysroot have `cfg(test)` disabled
265265
let cfg_options = {
266266
let mut opts = default_cfg_options.clone();
@@ -274,7 +274,7 @@ impl ProjectWorkspace {
274274
file_id,
275275
Edition::Edition2018,
276276
Some(
277-
CrateName::new(krate.name(&sysroot))
277+
CrateName::new(&sysroot[krate].name)
278278
.expect("Sysroot crate names should not contain dashes"),
279279
),
280280
cfg_options,
@@ -285,8 +285,8 @@ impl ProjectWorkspace {
285285
}
286286
}
287287
for from in sysroot.crates() {
288-
for to in from.deps(&sysroot) {
289-
let name = to.name(&sysroot);
288+
for &to in sysroot[from].deps.iter() {
289+
let name = &sysroot[to].name;
290290
if let (Some(&from), Some(&to)) =
291291
(sysroot_crates.get(&from), sysroot_crates.get(&to))
292292
{

crates/ra_project_model/src/sysroot.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use anyhow::{bail, Context, Result};
44
use std::{
5-
env,
5+
env, ops,
66
path::{Path, PathBuf},
77
process::{Command, Output},
88
};
@@ -19,10 +19,17 @@ pub struct SysrootCrate(RawId);
1919
impl_arena_id!(SysrootCrate);
2020

2121
#[derive(Debug, Clone)]
22-
struct SysrootCrateData {
23-
name: String,
24-
root: PathBuf,
25-
deps: Vec<SysrootCrate>,
22+
pub struct SysrootCrateData {
23+
pub name: String,
24+
pub root: PathBuf,
25+
pub deps: Vec<SysrootCrate>,
26+
}
27+
28+
impl ops::Index<SysrootCrate> for Sysroot {
29+
type Output = SysrootCrateData;
30+
fn index(&self, index: SysrootCrate) -> &SysrootCrateData {
31+
&self.crates[index]
32+
}
2633
}
2734

2835
impl Sysroot {
@@ -129,18 +136,9 @@ fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> {
129136
Ok(src_path)
130137
}
131138

132-
impl SysrootCrate {
133-
pub fn name(self, sysroot: &Sysroot) -> &str {
134-
&sysroot.crates[self].name
135-
}
136-
pub fn root(self, sysroot: &Sysroot) -> &Path {
137-
sysroot.crates[self].root.as_path()
138-
}
139-
pub fn root_dir(self, sysroot: &Sysroot) -> &Path {
140-
self.root(sysroot).parent().unwrap()
141-
}
142-
pub fn deps<'a>(self, sysroot: &'a Sysroot) -> impl Iterator<Item = SysrootCrate> + 'a {
143-
sysroot.crates[self].deps.iter().copied()
139+
impl SysrootCrateData {
140+
pub fn root_dir(&self) -> &Path {
141+
self.root.parent().unwrap()
144142
}
145143
}
146144

0 commit comments

Comments
 (0)