Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/utils/hg_path.rs @ 49930:e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
All of these are simple changes that for the most part are clear improvements
and the rest are at most equivalent.
The remaining warnings have to be fixed either with a bigger refactor like for
the nested "revlog" module, or in the dependency `bytes-cast`, which we own.
This will be done sometime in the future.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 19:18:43 +0100 |
parents | c7fb9b74e753 |
children | 331a3cbe1c9e |
line wrap: on
line diff
--- a/rust/hg-core/src/utils/hg_path.rs Mon Jan 09 19:14:14 2023 +0100 +++ b/rust/hg-core/src/utils/hg_path.rs Mon Jan 09 19:18:43 2023 +0100 @@ -205,7 +205,7 @@ /// ``` pub fn split_filename(&self) -> (&Self, &Self) { match &self.inner.iter().rposition(|c| *c == b'/') { - None => (HgPath::new(""), &self), + None => (HgPath::new(""), self), Some(size) => ( HgPath::new(&self.inner[..*size]), HgPath::new(&self.inner[*size + 1..]), @@ -326,7 +326,7 @@ #[cfg(unix)] /// Split a pathname into drive and path. On Posix, drive is always empty. pub fn split_drive(&self) -> (&HgPath, &HgPath) { - (HgPath::new(b""), &self) + (HgPath::new(b""), self) } /// Checks for errors in the path, short-circuiting at the first one. @@ -396,7 +396,7 @@ Default::default() } - pub fn push<T: ?Sized + AsRef<HgPath>>(&mut self, other: &T) -> () { + pub fn push<T: ?Sized + AsRef<HgPath>>(&mut self, other: &T) { if !self.inner.is_empty() && self.inner.last() != Some(&b'/') { self.inner.push(b'/'); } @@ -431,7 +431,7 @@ #[inline] fn deref(&self) -> &HgPath { - &HgPath::new(&self.inner) + HgPath::new(&self.inner) } } @@ -441,15 +441,15 @@ } } -impl Into<Vec<u8>> for HgPathBuf { - fn into(self) -> Vec<u8> { - self.inner +impl From<HgPathBuf> for Vec<u8> { + fn from(val: HgPathBuf) -> Self { + val.inner } } impl Borrow<HgPath> for HgPathBuf { fn borrow(&self) -> &HgPath { - &HgPath::new(self.as_bytes()) + HgPath::new(self.as_bytes()) } } @@ -491,7 +491,7 @@ #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; - os_str = std::ffi::OsStr::from_bytes(&hg_path.as_ref().as_bytes()); + os_str = std::ffi::OsStr::from_bytes(hg_path.as_ref().as_bytes()); } // TODO Handle other platforms // TODO: convert from WTF8 to Windows MBCS (ANSI encoding). @@ -511,7 +511,7 @@ #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; - buf = HgPathBuf::from_bytes(&os_string.as_ref().as_bytes()); + buf = HgPathBuf::from_bytes(os_string.as_ref().as_bytes()); } // TODO Handle other platforms // TODO: convert from WTF8 to Windows MBCS (ANSI encoding). @@ -528,7 +528,7 @@ #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; - buf = HgPathBuf::from_bytes(&os_str.as_bytes()); + buf = HgPathBuf::from_bytes(os_str.as_bytes()); } // TODO Handle other platforms // TODO: convert from WTF8 to Windows MBCS (ANSI encoding).