Mercurial > forks > mercurial
changeset 53255:405ad4ef6088
rust: apply clippy fixes from Rust 1.85
These are mostly changes that make the code less busy, particularly around
lifetimes that are never used in the body, or conversely lifetimes that
are hidden when they should be explicit.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 26 Mar 2025 11:27:25 +0100 |
parents | bec05cb1d78b |
children | 777b43804490 |
files | rust/hg-core/src/config/layer.rs rust/hg-core/src/config/mod.rs rust/hg-core/src/config/plain_info.rs rust/hg-core/src/config/values.rs rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/dirstate/on_disk.rs rust/hg-core/src/dirstate/status.rs rust/hg-core/src/discovery.rs rust/hg-core/src/matchers.rs rust/hg-core/src/revlog/index.rs rust/hg-core/src/revlog/inner_revlog.rs rust/hg-core/src/revlog/nodemap.rs rust/hg-core/src/update.rs rust/hg-core/src/utils/files.rs rust/hg-core/src/utils/strings.rs rust/hg-core/src/vfs.rs rust/hg-pyo3/src/revlog/mod.rs rust/pyo3-sharedref/src/lib.rs rust/pyo3-sharedref/tests/test_sharedref.rs rust/rhg/src/ui.rs |
diffstat | 20 files changed, 48 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/config/layer.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/config/layer.rs Wed Mar 26 11:27:25 2025 +0100 @@ -141,7 +141,7 @@ pub fn has_non_empty_section(&self, section: &[u8]) -> bool { self.sections .get(section) - .map_or(false, |section| !section.is_empty()) + .is_some_and(|section| !section.is_empty()) } pub fn is_empty(&self) -> bool {
--- a/rust/hg-core/src/config/mod.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/config/mod.rs Wed Mar 26 11:27:25 2025 +0100 @@ -741,7 +741,7 @@ pub fn iter_section<'a>( &'a self, section: &'a [u8], - ) -> impl Iterator<Item = (&[u8], &[u8])> + 'a { + ) -> impl Iterator<Item = (&'a [u8], &'a [u8])> + 'a { // Deduplicate keys redefined in multiple layers let mut keys_already_seen = HashSet::new(); let mut key_is_new =
--- a/rust/hg-core/src/config/plain_info.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/config/plain_info.rs Wed Mar 26 11:27:25 2025 +0100 @@ -53,11 +53,11 @@ } pub fn is_feature_plain(&self, feature: &str) -> bool { - return self.is_plain + self.is_plain && !self .except .iter() - .any(|exception| exception.as_slice() == feature.as_bytes()); + .any(|exception| exception.as_slice() == feature.as_bytes()) } pub fn is_plain(&self) -> bool {
--- a/rust/hg-core/src/config/values.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/config/values.rs Wed Mar 26 11:27:25 2025 +0100 @@ -42,16 +42,15 @@ value.parse().ok() } +// Note: keep behavior in sync with the Python one. +// Note: this could return `Vec<Cow<[u8]>>` instead and borrow `input` when +// possible (when there’s no backslash-escapes) but this is probably not worth +// the complexity as config is presumably not accessed inside +// performance-sensitive loops. + /// Parse a config value as a list of sub-values. /// /// Ported from `parselist` in `mercurial/utils/stringutil.py` - -// Note: keep behavior in sync with the Python one. - -// Note: this could return `Vec<Cow<[u8]>>` instead and borrow `input` when -// possible (when there’s no backslash-escapes) but this is probably not worth -// the complexity as config is presumably not accessed inside -// preformance-sensitive loops. pub(super) fn parse_list(input: &[u8]) -> Vec<Vec<u8>> { // Port of Python’s `value.lstrip(b' ,\n')` // TODO: is this really what we want?
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Wed Mar 26 11:27:25 2025 +0100 @@ -185,7 +185,7 @@ OnDisk(&'on_disk on_disk::Node), } -impl<'tree, 'on_disk> BorrowedPath<'tree, 'on_disk> { +impl<'on_disk> BorrowedPath<'_, 'on_disk> { pub fn detach_from_tree(&self) -> Cow<'on_disk, HgPath> { match *self { BorrowedPath::InMemory(in_memory) => Cow::Owned(in_memory.clone()), @@ -194,7 +194,7 @@ } } -impl<'tree, 'on_disk> std::ops::Deref for BorrowedPath<'tree, 'on_disk> { +impl std::ops::Deref for BorrowedPath<'_, '_> { type Target = HgPath; fn deref(&self) -> &HgPath { @@ -823,7 +823,7 @@ filename: &HgPath, old_entry_opt: Option<DirstateEntry>, ) -> Result<bool, DirstateV2ParseError> { - let was_tracked = old_entry_opt.map_or(false, |e| e.tracked()); + let was_tracked = old_entry_opt.is_some_and(|e| e.tracked()); let had_entry = old_entry_opt.is_some(); let tracked_count_increment = u32::from(!was_tracked); let mut new = false; @@ -1168,7 +1168,7 @@ &mut self, filename: &HgPath, ) -> Result<(), DirstateError> { - let was_tracked = self.get(filename)?.map_or(false, |e| e.tracked()); + let was_tracked = self.get(filename)?.is_some_and(|e| e.tracked()); struct Dropped { was_tracked: bool, had_entry: bool, @@ -1233,7 +1233,7 @@ } } else { let entry = node.data.as_entry(); - let was_tracked = entry.map_or(false, |entry| entry.tracked()); + let was_tracked = entry.is_some_and(|entry| entry.tracked()); let had_entry = entry.is_some(); if had_entry { node.data = NodeData::None
--- a/rust/hg-core/src/dirstate/on_disk.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/dirstate/on_disk.rs Wed Mar 26 11:27:25 2025 +0100 @@ -212,7 +212,7 @@ } } -impl<'on_disk> Docket<'on_disk> { +impl Docket<'_> { /// Generate the identifier for a new data file /// /// TODO: support the `HGTEST_UUIDFILE` environment variable.
--- a/rust/hg-core/src/dirstate/status.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/dirstate/status.rs Wed Mar 26 11:27:25 2025 +0100 @@ -397,7 +397,7 @@ } } -impl<'a, 'tree, 'on_disk> StatusCommon<'a, 'tree, 'on_disk> { +impl<'tree, 'on_disk> StatusCommon<'_, 'tree, 'on_disk> { fn push_outcome( &self, which: Outcome, @@ -1103,7 +1103,7 @@ file_type: FakeFileType, } -impl<'a> DirEntry<'a> { +impl DirEntry<'_> { /// Returns **unsorted** entries in the given directory, with name, /// metadata and file type. ///
--- a/rust/hg-core/src/discovery.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/discovery.rs Wed Mar 26 11:27:25 2025 +0100 @@ -284,7 +284,7 @@ /// Did we acquire full knowledge of our Revisions that the peer has? pub fn is_complete(&self) -> bool { - self.undecided.as_ref().map_or(false, HashSet::is_empty) + self.undecided.as_ref().is_some_and(HashSet::is_empty) } /// Return the heads of the currently known common set of revisions.
--- a/rust/hg-core/src/matchers.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/matchers.rs Wed Mar 26 11:27:25 2025 +0100 @@ -104,7 +104,7 @@ fn is_exact(&self) -> bool; } -impl<'a, T: Matcher + ?Sized> Matcher for &'a T { +impl<T: Matcher + ?Sized> Matcher for &T { fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { (*self).file_set() } @@ -423,7 +423,7 @@ } } -impl<'a> PatternMatcher<'a> { +impl PatternMatcher<'_> { pub fn new(ignore_patterns: Vec<IgnorePattern>) -> PatternResult<Self> { let RootsDirsAndParents { roots, @@ -454,7 +454,7 @@ } } -impl<'a> Matcher for PatternMatcher<'a> { +impl Matcher for PatternMatcher<'_> { fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { Some(&self.files) } @@ -571,7 +571,7 @@ } } -impl<'a> Matcher for IncludeMatcher<'a> { +impl Matcher for IncludeMatcher<'_> { fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { None } @@ -695,7 +695,7 @@ } fn exact_match(&self, filename: &HgPath) -> bool { - self.files.as_ref().map_or(false, |f| f.contains(filename)) + self.files.as_ref().is_some_and(|f| f.contains(filename)) } fn matches(&self, filename: &HgPath) -> bool { @@ -793,7 +793,7 @@ } fn exact_match(&self, filename: &HgPath) -> bool { - self.files.as_ref().map_or(false, |f| f.contains(filename)) + self.files.as_ref().is_some_and(|f| f.contains(filename)) } fn matches(&self, filename: &HgPath) -> bool { @@ -1226,7 +1226,7 @@ }) } -impl<'a> IncludeMatcher<'a> { +impl IncludeMatcher<'_> { fn new_gen( ignore_patterns: Vec<IgnorePattern>, regex_config: RegexCompleteness, @@ -1274,7 +1274,7 @@ } } -impl<'a> Display for IncludeMatcher<'a> { +impl Display for IncludeMatcher<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { // XXX What about exact matches? // I'm not sure it's worth it to clone the HashSet and keep it
--- a/rust/hg-core/src/revlog/index.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/revlog/index.rs Wed Mar 26 11:27:25 2025 +0100 @@ -246,7 +246,8 @@ } pub fn into_v1(self) -> RevisionDataV1 { - let data_offset_or_flags = self.data_offset << 16 | self.flags as u64; + let data_offset_or_flags = + (self.data_offset << 16) | self.flags as u64; let mut node_id = [0; STORED_NODE_ID_BYTES]; node_id[..NODE_BYTES_LENGTH].copy_from_slice(&self.node_id); RevisionDataV1 { @@ -1072,7 +1073,7 @@ revs: &'a [(Revision, IndexEntry)], start: usize, mut end: usize, - ) -> &'a [(Revision, IndexEntry)] { + ) -> &'a [(Revision, IndexEntry<'a>)] { // Trim empty revs at the end, except the very first rev of a chain let last_rev = revs[end - 1].0; if last_rev.0 < self.len() as BaseRevision {
--- a/rust/hg-core/src/revlog/inner_revlog.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/revlog/inner_revlog.rs Wed Mar 26 11:27:25 2025 +0100 @@ -323,7 +323,7 @@ pub fn decompress<'a>( &'a self, data: &'a [u8], - ) -> Result<Cow<[u8]>, RevlogError> { + ) -> Result<Cow<'a, [u8]>, RevlogError> { if data.is_empty() { return Ok(data.into()); } @@ -428,7 +428,7 @@ self.enter_reading_context()?; let res = func(); self.exit_reading_context(); - res.map_err(Into::into) + res } /// `pub` only for use in hg-pyo3
--- a/rust/hg-core/src/revlog/nodemap.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/revlog/nodemap.rs Wed Mar 26 11:27:25 2025 +0100 @@ -668,7 +668,7 @@ element: Element, } -impl<'n> Iterator for NodeTreeVisitor<'n> { +impl Iterator for NodeTreeVisitor<'_> { type Item = NodeTreeVisitItem; fn next(&mut self) -> Option<Self::Item> {
--- a/rust/hg-core/src/update.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/update.rs Wed Mar 26 11:27:25 2025 +0100 @@ -513,7 +513,7 @@ #[test] fn test_chunk_tracked_files() { - fn chunk(v: Vec<&'static str>) -> Vec<ExpandedManifestEntry> { + fn chunk(v: Vec<&'static str>) -> Vec<ExpandedManifestEntry<'static>> { v.into_iter() .map(|f| (HgPath::new(f.as_bytes()), NULL_NODE, None)) .collect()
--- a/rust/hg-core/src/utils/files.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/utils/files.rs Wed Mar 26 11:27:25 2025 +0100 @@ -86,7 +86,7 @@ } } -impl<'a> FusedIterator for Ancestors<'a> {} +impl FusedIterator for Ancestors<'_> {} /// An iterator over repository path yielding itself and its ancestors. #[derive(Copy, Clone, Debug)] @@ -108,7 +108,7 @@ } } -impl<'a> FusedIterator for AncestorsWithBase<'a> {} +impl FusedIterator for AncestorsWithBase<'_> {} /// Returns an iterator yielding ancestor directories of the given repository /// path.
--- a/rust/hg-core/src/utils/strings.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/utils/strings.rs Wed Mar 26 11:27:25 2025 +0100 @@ -157,7 +157,7 @@ } } -impl<'a, T: Escaped> Escaped for &'a [T] { +impl<T: Escaped> Escaped for &[T] { fn escaped_bytes(&self) -> Vec<u8> { self.iter().flat_map(Escaped::escaped_bytes).collect() } @@ -169,7 +169,7 @@ } } -impl<'a> Escaped for &'a HgPath { +impl Escaped for &HgPath { fn escaped_bytes(&self) -> Vec<u8> { self.as_bytes().escaped_bytes() }
--- a/rust/hg-core/src/vfs.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-core/src/vfs.rs Wed Mar 26 11:27:25 2025 +0100 @@ -966,11 +966,11 @@ } pub(crate) fn is_dir(path: impl AsRef<Path>) -> Result<bool, HgError> { - Ok(fs_metadata(path)?.map_or(false, |meta| meta.is_dir())) + Ok(fs_metadata(path)?.is_some_and(|meta| meta.is_dir())) } pub(crate) fn is_file(path: impl AsRef<Path>) -> Result<bool, HgError> { - Ok(fs_metadata(path)?.map_or(false, |meta| meta.is_file())) + Ok(fs_metadata(path)?.is_some_and(|meta| meta.is_file())) } /// Returns whether the given `path` is on a network file system.
--- a/rust/hg-pyo3/src/revlog/mod.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/hg-pyo3/src/revlog/mod.rs Wed Mar 26 11:27:25 2025 +0100 @@ -140,7 +140,7 @@ struct PySnapshotsCache<'a, 'py: 'a>(&'a Bound<'py, PyDict>); -impl<'a, 'py> PySnapshotsCache<'a, 'py> { +impl PySnapshotsCache<'_, '_> { fn insert_for_with_py_result( &self, rev: BaseRevision, @@ -156,7 +156,7 @@ } } -impl<'a, 'py> SnapshotsCache for PySnapshotsCache<'a, 'py> { +impl SnapshotsCache for PySnapshotsCache<'_, '_> { fn insert_for( &mut self, rev: BaseRevision,
--- a/rust/pyo3-sharedref/src/lib.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/pyo3-sharedref/src/lib.rs Wed Mar 26 11:27:25 2025 +0100 @@ -451,7 +451,7 @@ } } -impl<'a> Drop for BorrowPyShared<'a> { +impl Drop for BorrowPyShared<'_> { fn drop(&mut self) { self.state.decrease_borrow_count(self.py); } @@ -719,7 +719,7 @@ data: &'a T, } -impl<'a, T: ?Sized> Deref for SharedByPyObjectRef<'a, T> { +impl<T: ?Sized> Deref for SharedByPyObjectRef<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -733,7 +733,7 @@ data: &'a mut T, } -impl<'a, T: ?Sized> Deref for SharedByPyObjectRefMut<'a, T> { +impl<T: ?Sized> Deref for SharedByPyObjectRefMut<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -741,7 +741,7 @@ } } -impl<'a, T: ?Sized> DerefMut for SharedByPyObjectRefMut<'a, T> { +impl<T: ?Sized> DerefMut for SharedByPyObjectRefMut<'_, T> { fn deref_mut(&mut self) -> &mut T { self.data }
--- a/rust/pyo3-sharedref/tests/test_sharedref.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/pyo3-sharedref/tests/test_sharedref.rs Wed Mar 26 11:27:25 2025 +0100 @@ -50,7 +50,7 @@ fn mutate_string<'py>( owner: &'py Bound<'py, Owner>, f: impl FnOnce(&mut String), -) -> () { +) { let shareable = &owner.borrow_mut().string; let shared_ref = unsafe { shareable.borrow_with_owner(owner) }; f(&mut shared_ref.write());
--- a/rust/rhg/src/ui.rs Thu May 15 09:50:03 2025 +0200 +++ b/rust/rhg/src/ui.rs Wed Mar 26 11:27:25 2025 +0100 @@ -97,7 +97,7 @@ stdout: W, } -impl<'a, W: Write> StdoutBuffer<'a, W> { +impl<W: Write> StdoutBuffer<'_, W> { /// Write bytes to stdout with the given label /// /// Like the optional `label` parameter in `mercurial/ui.py`,