about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-22 07:06:13 +0000
committerbors <bors@rust-lang.org>2024-03-22 07:06:13 +0000
commit5577612fd0007e5eee9bd4cd8170dbc7cb8a92f7 (patch)
treef748c9813d97a2e5c8cf5ff973cf902aed95774e
parent7ef7f442fc34b5eadb1c6ad6433bd6d0c51b056b (diff)
parentea447062c4b3725a64558dd8b9b11eb223dc68d7 (diff)
downloadrust-5577612fd0007e5eee9bd4cd8170dbc7cb8a92f7.tar.gz
rust-5577612fd0007e5eee9bd4cd8170dbc7cb8a92f7.zip
Auto merge of #16918 - Veykril:utf8-paths, r=Veykril
fix: Don't assert paths being utf8 when filtering them in the watcher

Closes https://github.com/rust-lang/rust-analyzer/issues/16914
-rw-r--r--crates/paths/src/lib.rs16
-rw-r--r--crates/project-model/src/cargo_workspace.rs2
-rw-r--r--crates/vfs-notify/src/lib.rs4
3 files changed, 14 insertions, 8 deletions
diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs
index 3ffe4e11e96..2d3653401d2 100644
--- a/crates/paths/src/lib.rs
+++ b/crates/paths/src/lib.rs
@@ -13,7 +13,7 @@ use std::{
 pub use camino::*;
 
 /// Wrapper around an absolute [`Utf8PathBuf`].
-#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Ord, PartialOrd, Eq, Hash)]
 pub struct AbsPathBuf(Utf8PathBuf);
 
 impl From<AbsPathBuf> for Utf8PathBuf {
@@ -92,9 +92,9 @@ impl TryFrom<&str> for AbsPathBuf {
     }
 }
 
-impl PartialEq<AbsPath> for AbsPathBuf {
-    fn eq(&self, other: &AbsPath) -> bool {
-        self.as_path() == other
+impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPathBuf {
+    fn eq(&self, other: &P) -> bool {
+        self.0.as_std_path() == other.as_ref()
     }
 }
 
@@ -144,10 +144,16 @@ impl fmt::Display for AbsPathBuf {
 }
 
 /// Wrapper around an absolute [`Utf8Path`].
-#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[derive(Debug, Ord, PartialOrd, Eq, Hash)]
 #[repr(transparent)]
 pub struct AbsPath(Utf8Path);
 
+impl<P: AsRef<Path> + ?Sized> PartialEq<P> for AbsPath {
+    fn eq(&self, other: &P) -> bool {
+        self.0.as_std_path() == other.as_ref()
+    }
+}
+
 impl AsRef<Utf8Path> for AbsPath {
     fn as_ref(&self) -> &Utf8Path {
         &self.0
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 957366b6104..51c1b094f7b 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -406,7 +406,7 @@ impl CargoWorkspace {
     pub fn target_by_root(&self, root: &AbsPath) -> Option<Target> {
         self.packages()
             .filter(|&pkg| self[pkg].is_member)
-            .find_map(|pkg| self[pkg].targets.iter().find(|&&it| &self[it].root == root))
+            .find_map(|pkg| self[pkg].targets.iter().find(|&&it| self[it].root == root))
             .copied()
     }
 
diff --git a/crates/vfs-notify/src/lib.rs b/crates/vfs-notify/src/lib.rs
index 1f25b0e5346..4cfdec2b5c5 100644
--- a/crates/vfs-notify/src/lib.rs
+++ b/crates/vfs-notify/src/lib.rs
@@ -13,7 +13,7 @@ use std::fs;
 
 use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
 use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
-use paths::{AbsPath, AbsPathBuf, Utf8Path};
+use paths::{AbsPath, AbsPathBuf};
 use vfs::loader;
 use walkdir::WalkDir;
 
@@ -205,7 +205,7 @@ impl NotifyActor {
                             if !entry.file_type().is_dir() {
                                 return true;
                             }
-                            let path = AbsPath::assert(Utf8Path::from_path(entry.path()).unwrap());
+                            let path = entry.path();
                             root == path
                                 || dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
                         });