From 6bc5d51579dae5b0d7d6209ca1c465aa0462ed4d Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Wed, 8 Jun 2022 19:38:30 +0200 Subject: [PATCH] Add more lints --- src/archiver/archiver_impl.rs | 2 +- src/backend/ignore.rs | 2 +- src/main.rs | 30 ++++++++++++++++++++++++++++++ src/repo/snapshotfile.rs | 14 ++++---------- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/archiver/archiver_impl.rs b/src/archiver/archiver_impl.rs index 4a1447d..ba873af 100644 --- a/src/archiver/archiver_impl.rs +++ b/src/archiver/archiver_impl.rs @@ -118,7 +118,7 @@ impl Archiver { while !path.starts_with(&self.path) { // save tree and go back to parent dir let mut chunk = self.tree.serialize()?; - chunk.push('\n' as u8); // for whatever reason, restic adds a newline, so to be compatible... + chunk.push(b'\n'); // for whatever reason, restic adds a newline, so to be compatible... let id = hash(&chunk); let (mut node, tree, parent) = self diff --git a/src/backend/ignore.rs b/src/backend/ignore.rs index df5e610..ef9b66a 100644 --- a/src/backend/ignore.rs +++ b/src/backend/ignore.rs @@ -143,7 +143,7 @@ impl ReadSource for LocalSource { impl Iterator for LocalSource { type Item = Result<(PathBuf, Node)>; - fn next(&mut self) -> std::option::Option { + fn next(&mut self) -> Option { self.walker .next() .map(|e| map_entry(e?, self.with_atime, &self.cache)) diff --git a/src/main.rs b/src/main.rs index 7893721..c990639 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,33 @@ +// TODO: add +// missing_docs, +// unused_results, +// trivial_casts?? +#![warn( + bad_style, + const_err, + dead_code, + improper_ctypes, + missing_copy_implementations, + missing_debug_implementations, + non_shorthand_field_patterns, + no_mangle_generic_items, + overflowing_literals, + path_statements, + patterns_in_fns_without_body, + private_in_public, + trivial_numeric_casts, + unsafe_code, + unused_extern_crates, + unused_import_braces, + unused_qualifications, + unconditional_recursion, + unused, + unused_allocation, + unused_comparisons, + unused_parens, + while_true +)] + use anyhow::Result; mod archiver; diff --git a/src/repo/snapshotfile.rs b/src/repo/snapshotfile.rs index 5280a75..1d1929a 100644 --- a/src/repo/snapshotfile.rs +++ b/src/repo/snapshotfile.rs @@ -57,10 +57,7 @@ pub enum DeleteOption { impl DeleteOption { fn is_not_set(&self) -> bool { - match self { - Self::NotSet => true, - _ => false, - } + matches!(self, Self::NotSet) } } @@ -280,10 +277,7 @@ impl SnapshotFile { /// Returns whether a snapshot must be deleted now pub fn must_delete(&self, now: DateTime) -> bool { - match self.delete { - DeleteOption::After(time) if time < now => true, - _ => false, - } + matches!(self.delete,DeleteOption::After(time) if time < now) } /// Returns whether a snapshot must be kept now @@ -304,12 +298,12 @@ impl PartialEq for SnapshotFile { impl Eq for SnapshotFile {} impl PartialOrd for SnapshotFile { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { self.time.partial_cmp(&other.time) } } impl Ord for SnapshotFile { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.time.cmp(&other.time) } }