Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/utils/hg_path.rs @ 44998:26114bd6ec60
rust: do a clippy pass
This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing
the lints that do not require too much code churn (and would warrant a separate
commit/complete refactor) and only come from our code (a lot of warnings in
hg-cpython come from `rust-cpython`).
Most of those were good lints, two of them was the linter not being smart
enough (or compiler to get up to `clippy`'s level depending on how you see it).
Maybe in the future we could have `clippy` be part of the CI.
Differential Revision: https://phab.mercurial-scm.org/D8635
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 15 Jun 2020 18:26:40 +0200 |
parents | 0e9ac3968b56 |
children | 2d5dfc8fed55 |
line wrap: on
line diff
--- a/rust/hg-core/src/utils/hg_path.rs Mon Jun 15 15:14:16 2020 -0400 +++ b/rust/hg-core/src/utils/hg_path.rs Mon Jun 15 18:26:40 2020 +0200 @@ -208,7 +208,7 @@ } pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf { let mut inner = self.inner.to_owned(); - if inner.len() != 0 && inner.last() != Some(&b'/') { + if !inner.is_empty() && inner.last() != Some(&b'/') { inner.push(b'/'); } inner.extend(other.as_ref().bytes()); @@ -315,7 +315,7 @@ /// This generates fine-grained errors useful for debugging. /// To simply check if the path is valid during tests, use `is_valid`. pub fn check_state(&self) -> Result<(), HgPathError> { - if self.len() == 0 { + if self.is_empty() { return Ok(()); } let bytes = self.as_bytes(); @@ -366,14 +366,14 @@ } } -#[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Hash)] +#[derive(Default, Eq, Ord, Clone, PartialEq, PartialOrd, Hash)] pub struct HgPathBuf { inner: Vec<u8>, } impl HgPathBuf { pub fn new() -> Self { - Self { inner: Vec::new() } + Default::default() } pub fn push(&mut self, byte: u8) { self.inner.push(byte); @@ -384,9 +384,6 @@ pub fn into_vec(self) -> Vec<u8> { self.inner } - pub fn as_ref(&self) -> &[u8] { - self.inner.as_ref() - } } impl fmt::Debug for HgPathBuf {