diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 0cfbf1d9a16..e0c20a4143b 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -140,6 +140,11 @@ pub fn parent(&self) -> Option<&AbsPath> { self.0.parent().map(AbsPath::assert) } + /// Equivalent of [`Path::join`] for `AbsPath` with an additional normalize step afterwards. + pub fn absolutize(&self, path: impl AsRef) -> AbsPathBuf { + self.join(path).normalize() + } + /// Equivalent of [`Path::join`] for `AbsPath`. pub fn join(&self, path: impl AsRef) -> AbsPathBuf { self.as_ref().join(path).try_into().unwrap() diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index ede2dc769e3..80897f7478c 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -98,24 +98,23 @@ impl ProjectJson { /// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via /// configuration. pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { - let absolutize = - |p| AbsPathBuf::try_from(p).unwrap_or_else(|path| base.join(&path)).normalize(); + let absolutize_on_base = |p| base.absolutize(p); ProjectJson { - sysroot: data.sysroot.map(absolutize), - sysroot_src: data.sysroot_src.map(absolutize), + sysroot: data.sysroot.map(absolutize_on_base), + sysroot_src: data.sysroot_src.map(absolutize_on_base), project_root: base.to_path_buf(), crates: data .crates .into_iter() .map(|crate_data| { - let root_module = absolutize(crate_data.root_module); + let root_module = absolutize_on_base(crate_data.root_module); let is_workspace_member = crate_data .is_workspace_member .unwrap_or_else(|| root_module.starts_with(base)); let (include, exclude) = match crate_data.source { Some(src) => { let absolutize = |dirs: Vec| { - dirs.into_iter().map(absolutize).collect::>() + dirs.into_iter().map(absolutize_on_base).collect::>() }; (absolutize(src.include_dirs), absolutize(src.exclude_dirs)) } @@ -142,7 +141,9 @@ pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { cfg: crate_data.cfg, target: crate_data.target, env: crate_data.env, - proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(absolutize), + proc_macro_dylib_path: crate_data + .proc_macro_dylib_path + .map(absolutize_on_base), is_workspace_member, include, exclude,