Skip to content

Commit

Permalink
Auto merge of rust-lang#16918 - Veykril:utf8-paths, r=Veykril
Browse files Browse the repository at this point in the history
fix: Don't assert paths being utf8 when filtering them in the watcher

Closes rust-lang/rust-analyzer#16914
  • Loading branch information
bors committed Mar 22, 2024
2 parents 7ef7f44 + ea44706 commit 5577612
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/vfs-notify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
});
Expand Down

0 comments on commit 5577612

Please sign in to comment.