diff --git a/rust/hg-core/src/dirstate/dirs_multiset.rs b/rust/hg-core/src/dirstate/dirs_multiset.rs --- a/rust/hg-core/src/dirstate/dirs_multiset.rs +++ b/rust/hg-core/src/dirstate/dirs_multiset.rs @@ -62,7 +62,7 @@ impl DirsMultiset { /// Initializes the multiset from a manifest. pub fn from_manifest( manifest: &[impl AsRef], - ) -> Result { + ) -> Result { let mut multiset = DirsMultiset { inner: FastHashMap::default(), }; @@ -80,19 +80,17 @@ impl DirsMultiset { pub fn add_path( &mut self, path: impl AsRef, - ) -> Result<(), DirstateMapError> { + ) -> Result<(), HgPathError> { for subpath in files::find_dirs(path.as_ref()) { if subpath.as_bytes().last() == Some(&b'/') { // TODO Remove this once PathAuditor is certified // as the only entrypoint for path data let second_slash_index = subpath.len() - 1; - return Err(DirstateMapError::InvalidPath( - HgPathError::ConsecutiveSlashes { - bytes: path.as_ref().as_bytes().to_owned(), - second_slash_index, - }, - )); + return Err(HgPathError::ConsecutiveSlashes { + bytes: path.as_ref().as_bytes().to_owned(), + second_slash_index, + }); } if let Some(val) = self.inner.get_mut(subpath) { *val += 1; diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs --- a/rust/hg-core/src/lib.rs +++ b/rust/hg-core/src/lib.rs @@ -66,6 +66,12 @@ pub enum DirstateMapError { InvalidPath(HgPathError), } +impl From for DirstateMapError { + fn from(error: HgPathError) -> Self { + Self::InvalidPath(error) + } +} + impl fmt::Display for DirstateMapError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -83,6 +89,12 @@ pub enum DirstateError { Common(errors::HgError), } +impl From for DirstateError { + fn from(error: HgPathError) -> Self { + Self::Map(DirstateMapError::InvalidPath(error)) + } +} + impl fmt::Display for DirstateError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs --- a/rust/hg-core/src/matchers.rs +++ b/rust/hg-core/src/matchers.rs @@ -15,11 +15,10 @@ use crate::{ }, utils::{ files::find_dirs, - hg_path::{HgPath, HgPathBuf}, + hg_path::{HgPath, HgPathBuf, HgPathError}, Escaped, }, - DirsMultiset, DirstateMapError, FastHashMap, IgnorePattern, PatternError, - PatternSyntax, + DirsMultiset, FastHashMap, IgnorePattern, PatternError, PatternSyntax, }; use crate::dirstate::status::IgnoreFnType; @@ -177,7 +176,7 @@ pub struct FileMatcher { } impl FileMatcher { - pub fn new(files: Vec) -> Result { + pub fn new(files: Vec) -> Result { let dirs = DirsMultiset::from_manifest(&files)?; Ok(Self { files: HashSet::from_iter(files.into_iter()), @@ -760,20 +759,12 @@ fn roots_dirs_and_parents( let mut parents = HashSet::new(); parents.extend( - DirsMultiset::from_manifest(&dirs) - .map_err(|e| match e { - DirstateMapError::InvalidPath(e) => e, - _ => unreachable!(), - })? + DirsMultiset::from_manifest(&dirs)? .iter() .map(ToOwned::to_owned), ); parents.extend( - DirsMultiset::from_manifest(&roots) - .map_err(|e| match e { - DirstateMapError::InvalidPath(e) => e, - _ => unreachable!(), - })? + DirsMultiset::from_manifest(&roots)? .iter() .map(ToOwned::to_owned), );