mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: Enforce utf8 paths
This commit is contained in:
parent
ba339596bf
commit
399dbc074b
46 changed files with 383 additions and 319 deletions
|
@ -1,12 +1,9 @@
|
|||
use std::{
|
||||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use std::ops::Deref;
|
||||
|
||||
use base_db::{CrateGraph, FileId, ProcMacroPaths};
|
||||
use cfg::{CfgAtom, CfgDiff};
|
||||
use expect_test::{expect_file, ExpectFile};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
use paths::{AbsPath, AbsPathBuf, Utf8Path, Utf8PathBuf};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::de::DeserializeOwned;
|
||||
use triomphe::Arc;
|
||||
|
@ -113,17 +110,16 @@ fn replace_root(s: &mut String, direction: bool) {
|
|||
fn replace_fake_sys_root(s: &mut String) {
|
||||
let fake_sysroot_path = get_test_path("fake-sysroot");
|
||||
let fake_sysroot_path = if cfg!(windows) {
|
||||
let normalized_path =
|
||||
fake_sysroot_path.to_str().expect("expected str").replace('\\', r#"\\"#);
|
||||
let normalized_path = fake_sysroot_path.as_str().replace('\\', r#"\\"#);
|
||||
format!(r#"{}\\"#, normalized_path)
|
||||
} else {
|
||||
format!("{}/", fake_sysroot_path.to_str().expect("expected str"))
|
||||
format!("{}/", fake_sysroot_path.as_str())
|
||||
};
|
||||
*s = s.replace(&fake_sysroot_path, "$FAKESYSROOT$")
|
||||
}
|
||||
|
||||
fn get_test_path(file: &str) -> PathBuf {
|
||||
let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
fn get_test_path(file: &str) -> Utf8PathBuf {
|
||||
let base = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
base.join("test_data").join(file)
|
||||
}
|
||||
|
||||
|
@ -139,7 +135,7 @@ fn get_fake_sysroot() -> Sysroot {
|
|||
fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
|
||||
let mut root = "$ROOT$".to_owned();
|
||||
replace_root(&mut root, true);
|
||||
let path = Path::new(&root);
|
||||
let path = Utf8Path::new(&root);
|
||||
let base = AbsPath::assert(path);
|
||||
ProjectJson::new(base, data)
|
||||
}
|
||||
|
@ -268,7 +264,7 @@ fn smoke_test_real_sysroot_cargo() {
|
|||
|
||||
let cargo_workspace = CargoWorkspace::new(meta);
|
||||
let sysroot = Ok(Sysroot::discover(
|
||||
AbsPath::assert(Path::new(env!("CARGO_MANIFEST_DIR"))),
|
||||
AbsPath::assert(Utf8Path::new(env!("CARGO_MANIFEST_DIR"))),
|
||||
&Default::default(),
|
||||
true,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue