Skip to content

Commit ea44706

Browse files
committed
fix: Don't assert paths being utf8 when filtering them in the watcher
1 parent fe28e47 commit ea44706

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

crates/paths/src/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
pub use camino::*;
1414

1515
/// Wrapper around an absolute [`Utf8PathBuf`].
16-
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
16+
#[derive(Debug, Clone, Ord, PartialOrd, Eq, Hash)]
1717
pub struct AbsPathBuf(Utf8PathBuf);
1818

1919
impl From<AbsPathBuf> for Utf8PathBuf {
@@ -92,9 +92,9 @@ impl TryFrom<&str> for AbsPathBuf {
9292
}
9393
}
9494

95-
impl PartialEq<AbsPath> for AbsPathBuf {
96-
fn eq(&self, other: &AbsPath) -> bool {
97-
self.as_path() == other
95+
impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPathBuf {
96+
fn eq(&self, other: &P) -> bool {
97+
self.0.as_std_path() == other.as_ref()
9898
}
9999
}
100100

@@ -144,10 +144,16 @@ impl fmt::Display for AbsPathBuf {
144144
}
145145

146146
/// Wrapper around an absolute [`Utf8Path`].
147-
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
147+
#[derive(Debug, Ord, PartialOrd, Eq, Hash)]
148148
#[repr(transparent)]
149149
pub struct AbsPath(Utf8Path);
150150

151+
impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPath {
152+
fn eq(&self, other: &P) -> bool {
153+
self.0.as_std_path() == other.as_ref()
154+
}
155+
}
156+
151157
impl AsRef<Utf8Path> for AbsPath {
152158
fn as_ref(&self) -> &Utf8Path {
153159
&self.0

crates/project-model/src/cargo_workspace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl CargoWorkspace {
406406
pub fn target_by_root(&self, root: &AbsPath) -> Option<Target> {
407407
self.packages()
408408
.filter(|&pkg| self[pkg].is_member)
409-
.find_map(|pkg| self[pkg].targets.iter().find(|&&it| &self[it].root == root))
409+
.find_map(|pkg| self[pkg].targets.iter().find(|&&it| self[it].root == root))
410410
.copied()
411411
}
412412

crates/vfs-notify/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fs;
1313

1414
use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
1515
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
16-
use paths::{AbsPath, AbsPathBuf, Utf8Path};
16+
use paths::{AbsPath, AbsPathBuf};
1717
use vfs::loader;
1818
use walkdir::WalkDir;
1919

@@ -205,7 +205,7 @@ impl NotifyActor {
205205
if !entry.file_type().is_dir() {
206206
return true;
207207
}
208-
let path = AbsPath::assert(Utf8Path::from_path(entry.path()).unwrap());
208+
let path = entry.path();
209209
root == path
210210
|| dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
211211
});

0 commit comments

Comments
 (0)