Skip to content

Move paths to lib #12415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/flycheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jod-thread = "0.1.2"

toolchain = { path = "../toolchain", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
2 changes: 1 addition & 1 deletion crates/proc-macro-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tracing = "0.1.35"
memmap2 = "0.5.4"
snap = "1.0.5"

paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
tt = { path = "../tt", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/proc-macro-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ memmap2 = "0.5.4"

tt = { path = "../tt", version = "0.0.0" }
mbe = { path = "../mbe", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
proc-macro-api = { path = "../proc-macro-api", version = "0.0.0" }
crossbeam = "0.8.1"

Expand Down
2 changes: 1 addition & 1 deletion crates/proc-macro-srv/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn list_test_macros() {

#[test]
fn test_version_check() {
let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
let path = AbsPathBuf::try_from(fixtures::proc_macro_test_dylib_path()).unwrap();
let info = proc_macro_api::read_dylib_info(&path).unwrap();
assert!(info.version.1 >= 50);
}
2 changes: 1 addition & 1 deletion crates/project-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
cfg = { path = "../cfg", version = "0.0.0" }
base-db = { path = "../base-db", version = "0.0.0" }
toolchain = { path = "../toolchain", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
stdx = { path = "../stdx", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }
6 changes: 4 additions & 2 deletions crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ impl WorkspaceBuildScripts {
let out_dir = message.out_dir.into_os_string();
if !out_dir.is_empty() {
let data = outputs[package].get_or_insert_with(Default::default);
data.out_dir = Some(AbsPathBuf::assert(PathBuf::from(out_dir)));
data.out_dir =
Some(AbsPathBuf::try_from(PathBuf::from(out_dir)).unwrap());
data.cfgs = cfgs;
}
if !message.env.is_empty() {
Expand All @@ -168,7 +169,8 @@ impl WorkspaceBuildScripts {
if let Some(filename) =
message.filenames.iter().find(|name| is_dylib(name))
{
let filename = AbsPathBuf::assert(PathBuf::from(&filename));
let filename =
AbsPathBuf::try_from(PathBuf::from(&filename)).unwrap();
outputs[package]
.get_or_insert_with(Default::default)
.proc_macro_dylib_path = Some(filename);
Expand Down
9 changes: 6 additions & 3 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ impl CargoWorkspace {
id: id.repr.clone(),
name: name.clone(),
version: version.clone(),
manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)).try_into().unwrap(),
manifest: AbsPathBuf::try_from(PathBuf::from(&manifest_path))
.unwrap()
.try_into()
.unwrap(),
targets: Vec::new(),
is_local,
is_member,
Expand All @@ -354,7 +357,7 @@ impl CargoWorkspace {
let tgt = targets.alloc(TargetData {
package: pkg,
name: meta_tgt.name.clone(),
root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)),
root: AbsPathBuf::try_from(PathBuf::from(&meta_tgt.src_path)).unwrap(),
kind: TargetKind::new(meta_tgt.kind.as_slice()),
is_proc_macro,
required_features: meta_tgt.required_features.clone(),
Expand Down Expand Up @@ -397,7 +400,7 @@ impl CargoWorkspace {
}

let workspace_root =
AbsPathBuf::assert(PathBuf::from(meta.workspace_root.into_os_string()));
AbsPathBuf::try_from(PathBuf::from(meta.workspace_root.into_os_string())).unwrap();

CargoWorkspace { packages, targets, workspace_root }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ProjectManifest {
.filter_map(Result::ok)
.map(|it| it.path().join("Cargo.toml"))
.filter(|it| it.exists())
.map(AbsPathBuf::assert)
.map(|x| AbsPathBuf::try_from(x).unwrap())
.filter_map(|it| it.try_into().ok())
.collect()
}
Expand Down
7 changes: 4 additions & 3 deletions crates/project-model/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,17 @@ fn discover_sysroot_dir(current_dir: &AbsPath) -> Result<AbsPathBuf> {
rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
tracing::debug!("Discovering sysroot by {:?}", rustc);
let stdout = utf8_stdout(rustc)?;
Ok(AbsPathBuf::assert(PathBuf::from(stdout)))
Ok(AbsPathBuf::try_from(PathBuf::from(stdout)).unwrap())
}

fn discover_sysroot_src_dir(
sysroot_path: &AbsPathBuf,
current_dir: &AbsPath,
) -> Result<AbsPathBuf> {
if let Ok(path) = env::var("RUST_SRC_PATH") {
let path = AbsPathBuf::try_from(path.as_str())
.map_err(|path| format_err!("RUST_SRC_PATH must be absolute: {}", path.display()))?;
let path = AbsPathBuf::try_from(path.as_str()).map_err(|path| {
format_err!("RUST_SRC_PATH must be absolute: {}", path.into_inner().display())
})?;
let core = path.join("core");
if fs::metadata(&core).is_ok() {
tracing::debug!("Discovered sysroot by RUST_SRC_PATH: {}", path.display());
Expand Down
4 changes: 2 additions & 2 deletions crates/project-model/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn get_fake_sysroot() -> Sysroot {
let sysroot_path = get_test_path("fake-sysroot");
// there's no `libexec/` directory with a `proc-macro-srv` binary in that
// fake sysroot, so we give them both the same path:
let sysroot_dir = AbsPathBuf::assert(sysroot_path);
let sysroot_dir = AbsPathBuf::try_from(sysroot_path).unwrap();
let sysroot_src_dir = sysroot_dir.clone();
Sysroot::load(sysroot_dir, sysroot_src_dir).unwrap()
}
Expand All @@ -86,7 +86,7 @@ fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
let mut root = "$ROOT$".to_string();
replace_root(&mut root, true);
let path = Path::new(&root);
let base = AbsPath::assert(path);
let base = <&AbsPath>::try_from(path).unwrap();
ProjectJson::new(base, data)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn run_server() -> Result<()> {
Some(it) => it,
None => {
let cwd = env::current_dir()?;
AbsPathBuf::assert(cwd)
AbsPathBuf::try_from(cwd).unwrap()
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl flags::AnalysisStats {

let mut db_load_sw = self.stop_watch();

let path = AbsPathBuf::assert(env::current_dir()?.join(&self.path));
let path = AbsPathBuf::try_from(env::current_dir()?.join(&self.path)).unwrap();
let manifest = ProjectManifest::discover_single(&path)?;

let mut workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/cli/load_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn load_workspace_at(
load_config: &LoadCargoConfig,
progress: &dyn Fn(String),
) -> Result<(AnalysisHost, vfs::Vfs, Option<ProcMacroServer>)> {
let root = AbsPathBuf::assert(std::env::current_dir()?.join(root));
let root = AbsPathBuf::try_from(std::env::current_dir()?.join(root)).unwrap();
let root = ProjectManifest::discover_single(&root)?;
let mut workspace = ProjectWorkspace::load(root, cargo_config, progress)?;

Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn load_workspace(
};

let proc_macro_client = if load_config.with_proc_macro {
let path = AbsPathBuf::assert(std::env::current_exe()?);
let path = AbsPathBuf::try_from(std::env::current_exe()?).unwrap();
Ok(ProcMacroServer::spawn(path, &["proc-macro"]).unwrap())
} else {
Err("proc macro server not started".to_owned())
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/lsif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl flags::Lsif {
with_proc_macro: true,
prefill_caches: false,
};
let path = AbsPathBuf::assert(env::current_dir()?.join(&self.path));
let path = AbsPathBuf::try_from(env::current_dir()?.join(&self.path)).unwrap();
let manifest = ProjectManifest::discover_single(&path)?;

let workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl Config {
self.detached_files =
get_field::<Vec<PathBuf>>(&mut json, &mut errors, "detachedFiles", None, "[]")
.into_iter()
.map(AbsPathBuf::assert)
.map(|x| AbsPathBuf::try_from(x).unwrap())
.collect();
patch_old_style::patch_json_for_outdated_configs(&mut json);
self.data = ConfigData::from_json(json, &mut errors);
Expand Down Expand Up @@ -902,7 +902,7 @@ impl Config {
}
let path = match &self.data.procMacro_server {
Some(it) => self.root_path.join(it),
None => AbsPathBuf::assert(std::env::current_exe().ok()?),
None => AbsPathBuf::try_from(std::env::current_exe().ok()?).unwrap(),
};
Some((path, vec!["proc-macro".into()]))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/integrated_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn integrated_highlighting_benchmark() {

let file_id = {
let file = workspace_to_load.join(file);
let path = VfsPath::from(AbsPathBuf::assert(file));
let path = VfsPath::from(AbsPathBuf::try_from(file).unwrap());
vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {}", path))
};

Expand Down Expand Up @@ -101,7 +101,7 @@ fn integrated_completion_benchmark() {

let file_id = {
let file = workspace_to_load.join(file);
let path = VfsPath::from(AbsPathBuf::assert(file));
let path = VfsPath::from(AbsPathBuf::try_from(file).unwrap());
vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {}", path))
};

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/tests/slow-tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> Project<'a> {
fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
}

let tmp_dir_path = AbsPathBuf::assert(tmp_dir.path().to_path_buf());
let tmp_dir_path = AbsPathBuf::try_from(tmp_dir.path().to_path_buf()).unwrap();
let mut roots =
self.roots.into_iter().map(|root| tmp_dir_path.join(root)).collect::<Vec<_>>();
if roots.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion crates/vfs-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ crossbeam-channel = "0.5.5"
notify = "=5.0.0-pre.15"

vfs = { path = "../vfs", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
4 changes: 2 additions & 2 deletions crates/vfs-notify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ impl NotifyActor {
if !entry.file_type().is_dir() {
return true;
}
let path = AbsPath::assert(entry.path());
let path = <&AbsPath>::try_from(entry.path()).unwrap();
root == path
|| dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
});

let files = walkdir.filter_map(|it| it.ok()).filter_map(|entry| {
let is_dir = entry.file_type().is_dir();
let is_file = entry.file_type().is_file();
let abs_path = AbsPathBuf::assert(entry.into_path());
let abs_path = AbsPathBuf::try_from(entry.into_path()).unwrap();
if is_dir && watch {
self.watch(abs_path.clone());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/vfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ doctest = false
rustc-hash = "1.1.0"
fst = "0.4.7"

paths = { path = "../paths", version = "0.0.0" }
paths = { path = "../../lib/paths", version = "0.1.0" }
indexmap = "1.9.1"
2 changes: 1 addition & 1 deletion crates/vfs/src/vfs_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl VfsPath {
/// Create a path from string. Input should be a string representation of
/// an absolute path inside filesystem
pub fn new_real_path(path: String) -> VfsPath {
VfsPath::from(AbsPathBuf::assert(path.into()))
VfsPath::from(AbsPathBuf::try_from(path).unwrap())
}

/// Returns the `AbsPath` representation of `self` if `self` is on the file system.
Expand Down
3 changes: 2 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Crates in this directory are published to crates.io and obey semver.
They *could* live in a separate repo, but we want to experiment with a monorepo setup.

They _could_ live in a separate repo, but we want to experiment with a monorepo setup.
4 changes: 2 additions & 2 deletions crates/paths/Cargo.toml → lib/paths/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "paths"
version = "0.0.0"
description = "TBD"
version = "0.1.0"
description = "Wrapper types for relative and absolute paths."
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.57"
Expand Down
Loading