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
|
@ -33,12 +33,11 @@ use std::{
|
|||
collections::{hash_map::Entry, HashMap},
|
||||
env,
|
||||
ffi::OsString,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
thread,
|
||||
fs, thread,
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use paths::{Utf8Path, Utf8PathBuf};
|
||||
use proc_macro_api::{
|
||||
msg::{
|
||||
self, deserialize_span_data_index_map, serialize_span_data_index_map, ExpnGlobals,
|
||||
|
@ -81,7 +80,7 @@ impl ProcMacroSrvSpan for Span {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct ProcMacroSrv {
|
||||
expanders: HashMap<(PathBuf, SystemTime), dylib::Expander>,
|
||||
expanders: HashMap<(Utf8PathBuf, SystemTime), dylib::Expander>,
|
||||
span_mode: SpanMode,
|
||||
}
|
||||
|
||||
|
@ -149,23 +148,22 @@ impl ProcMacroSrv {
|
|||
|
||||
pub fn list_macros(
|
||||
&mut self,
|
||||
dylib_path: &Path,
|
||||
dylib_path: &Utf8Path,
|
||||
) -> Result<Vec<(String, ProcMacroKind)>, String> {
|
||||
let expander = self.expander(dylib_path)?;
|
||||
Ok(expander.list_macros())
|
||||
}
|
||||
|
||||
fn expander(&mut self, path: &Path) -> Result<&dylib::Expander, String> {
|
||||
fn expander(&mut self, path: &Utf8Path) -> Result<&dylib::Expander, String> {
|
||||
let time = fs::metadata(path)
|
||||
.and_then(|it| it.modified())
|
||||
.map_err(|err| format!("Failed to get file metadata for {}: {err}", path.display()))?;
|
||||
.map_err(|err| format!("Failed to get file metadata for {path}: {err}",))?;
|
||||
|
||||
Ok(match self.expanders.entry((path.to_path_buf(), time)) {
|
||||
Entry::Vacant(v) => {
|
||||
v.insert(dylib::Expander::new(path).map_err(|err| {
|
||||
format!("Cannot create expander for {}: {err}", path.display())
|
||||
})?)
|
||||
}
|
||||
Entry::Vacant(v) => v.insert(
|
||||
dylib::Expander::new(path)
|
||||
.map_err(|err| format!("Cannot create expander for {path}: {err}",))?,
|
||||
),
|
||||
Entry::Occupied(e) => e.into_mut(),
|
||||
})
|
||||
}
|
||||
|
@ -306,6 +304,6 @@ impl Drop for EnvSnapshot {
|
|||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn proc_macro_test_dylib_path() -> std::path::PathBuf {
|
||||
pub fn proc_macro_test_dylib_path() -> paths::Utf8PathBuf {
|
||||
proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue