Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/utils.rs @ 44973: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 | aa0fc32ece9e |
children | 9eb07ab3f2d4 |
comparison
equal
deleted
inserted
replaced
44962:ef8dcee272ac | 44973:26114bd6ec60 |
---|---|
66 fn trim_start(&self) -> &Self; | 66 fn trim_start(&self) -> &Self; |
67 fn trim(&self) -> &Self; | 67 fn trim(&self) -> &Self; |
68 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; | 68 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; |
69 } | 69 } |
70 | 70 |
71 #[allow(clippy::trivially_copy_pass_by_ref)] | |
71 fn is_not_whitespace(c: &u8) -> bool { | 72 fn is_not_whitespace(c: &u8) -> bool { |
72 !(*c as char).is_whitespace() | 73 !(*c as char).is_whitespace() |
73 } | 74 } |
74 | 75 |
75 impl SliceExt for [u8] { | 76 impl SliceExt for [u8] { |
76 fn trim_end(&self) -> &[u8] { | 77 fn trim_end(&self) -> &[u8] { |
77 if let Some(last) = self.iter().rposition(is_not_whitespace) { | 78 if let Some(last) = self.iter().rposition(is_not_whitespace) { |
78 &self[..last + 1] | 79 &self[..=last] |
79 } else { | 80 } else { |
80 &[] | 81 &[] |
81 } | 82 } |
82 } | 83 } |
83 fn trim_start(&self) -> &[u8] { | 84 fn trim_start(&self) -> &[u8] { |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 impl<'a, T: Escaped> Escaped for &'a [T] { | 153 impl<'a, T: Escaped> Escaped for &'a [T] { |
153 fn escaped_bytes(&self) -> Vec<u8> { | 154 fn escaped_bytes(&self) -> Vec<u8> { |
154 self.iter().flat_map(|item| item.escaped_bytes()).collect() | 155 self.iter().flat_map(Escaped::escaped_bytes).collect() |
155 } | 156 } |
156 } | 157 } |
157 | 158 |
158 impl<T: Escaped> Escaped for Vec<T> { | 159 impl<T: Escaped> Escaped for Vec<T> { |
159 fn escaped_bytes(&self) -> Vec<u8> { | 160 fn escaped_bytes(&self) -> Vec<u8> { |