From 002080cde8d2f727c5b1e12aff91c268922f59eb Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Tue, 13 Oct 2020 01:46:17 +0100 Subject: [PATCH] Clippy pedantic lints This commit fixes a couple of Clippy warnings, and adds the list of lints we're OK with. It does raise some important warnings, such as those to do with casting, which aren't allowed so they can be fixed later. --- src/fs/feature/git.rs | 18 ++++++++---------- src/fs/fields.rs | 1 + src/fs/file.rs | 10 +++++----- src/main.rs | 15 +++++++++++++++ src/options/mod.rs | 2 +- src/options/view.rs | 9 ++++----- src/output/render/times.rs | 4 ++-- src/output/table.rs | 7 ++++--- src/output/time.rs | 4 ++-- 9 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/fs/feature/git.rs b/src/fs/feature/git.rs index 88fcbc0..4bbe07a 100644 --- a/src/fs/feature/git.rs +++ b/src/fs/feature/git.rs @@ -167,16 +167,14 @@ impl GitRepo { } }; - match repo.workdir() { - Some(workdir) => { - let workdir = workdir.to_path_buf(); - let contents = Mutex::new(GitContents::Before { repo }); - Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() }) - } - None => { - warn!("Repository has no workdir?"); - Err(path) - } + if let Some(workdir) = repo.workdir() { + let workdir = workdir.to_path_buf(); + let contents = Mutex::new(GitContents::Before { repo }); + Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() }) + } + else { + warn!("Repository has no workdir?"); + Err(path) } } } diff --git a/src/fs/fields.rs b/src/fs/fields.rs index 434a164..7320afa 100644 --- a/src/fs/fields.rs +++ b/src/fs/fields.rs @@ -13,6 +13,7 @@ // C-style `blkcnt_t` types don’t follow Rust’s rules! #![allow(non_camel_case_types)] +#![allow(clippy::struct_excessive_bools)] /// The type of a file’s block count. diff --git a/src/fs/file.rs b/src/fs/file.rs index cad93d2..0df998c 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -337,19 +337,19 @@ impl<'dir> File<'dir> { /// This file’s last changed timestamp, if available on this platform. pub fn changed_time(&self) -> Option { - let (mut sec, mut nsec) = (self.metadata.ctime(), self.metadata.ctime_nsec()); + let (mut sec, mut nanosec) = (self.metadata.ctime(), self.metadata.ctime_nsec()); if sec < 0 { - if nsec > 0 { + if nanosec > 0 { sec += 1; - nsec -= 1_000_000_000; + nanosec -= 1_000_000_000; } - let duration = Duration::new(sec.abs() as u64, nsec.abs() as u32); + let duration = Duration::new(sec.abs() as u64, nanosec.abs() as u32); Some(UNIX_EPOCH - duration) } else { - let duration = Duration::new(sec as u64, nsec as u32); + let duration = Duration::new(sec as u64, nanosec as u32); Some(UNIX_EPOCH + duration) } } diff --git a/src/main.rs b/src/main.rs index 5e4e249..3e0d1d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,21 @@ #![warn(trivial_casts, trivial_numeric_casts)] #![warn(unused)] +#![warn(clippy::all, clippy::pedantic)] +#![allow(clippy::enum_glob_use)] +#![allow(clippy::find_map)] +#![allow(clippy::map_unwrap_or)] +#![allow(clippy::match_same_arms)] +#![allow(clippy::missing_const_for_fn)] +#![allow(clippy::missing_errors_doc)] +#![allow(clippy::module_name_repetitions)] +#![allow(clippy::must_use_candidate)] +#![allow(clippy::non_ascii_literal)] +#![allow(clippy::option_if_let_else)] +#![allow(clippy::too_many_lines)] +#![allow(clippy::unused_self)] +#![allow(clippy::wildcard_imports)] + use std::env; use std::ffi::{OsStr, OsString}; use std::io::{self, Write, ErrorKind}; diff --git a/src/options/mod.rs b/src/options/mod.rs index 49b8f6a..324bfe8 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -128,7 +128,7 @@ impl Options { let strictness = match vars.get(vars::EXA_STRICT) { None => Strictness::UseLastArguments, Some(ref t) if t.is_empty() => Strictness::UseLastArguments, - _ => Strictness::ComplainAboutRedundantArguments, + Some(_) => Strictness::ComplainAboutRedundantArguments, }; let Matches { flags, frees } = match flags::ALL_ARGS.parse(args, strictness) { diff --git a/src/options/view.rs b/src/options/view.rs index 7f692b1..5b56a3b 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -262,18 +262,17 @@ impl TimeFormat { /// Determine how time should be formatted in timestamp columns. fn deduce(matches: &MatchedFlags<'_>, vars: &V) -> Result { - let word = match matches.get(&flags::TIME_STYLE)? { - Some(w) => { + let word = + if let Some(w) = matches.get(&flags::TIME_STYLE)? { w.to_os_string() } - None => { + else { use crate::options::vars; match vars.get(vars::TIME_STYLE) { Some(ref t) if ! t.is_empty() => t.clone(), _ => return Ok(Self::DefaultFormat) } - }, - }; + }; if &word == "default" { Ok(Self::DefaultFormat) diff --git a/src/output/render/times.rs b/src/output/render/times.rs index a48dce9..72374f9 100644 --- a/src/output/render/times.rs +++ b/src/output/render/times.rs @@ -8,11 +8,11 @@ use crate::output::time::TimeFormat; pub trait Render { - fn render(self, style: Style, tz: &Option, format: &TimeFormat) -> TextCell; + fn render(self, style: Style, tz: &Option, format: TimeFormat) -> TextCell; } impl Render for Option { - fn render(self, style: Style, tz: &Option, format: &TimeFormat) -> TextCell { + fn render(self, style: Style, tz: &Option, format: TimeFormat) -> TextCell { let datestamp = if let Some(time) = self { if let Some(ref tz) = tz { format.format_zoned(time, tz) diff --git a/src/output/table.rs b/src/output/table.rs index 4377229..42bdfaf 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -225,6 +225,7 @@ impl TimeType { /// There should always be at least one of these — there’s no way to disable /// the time columns entirely (yet). #[derive(PartialEq, Debug, Copy, Clone)] +#[allow(clippy::struct_excessive_bools)] pub struct TimeTypes { pub modified: bool, pub changed: bool, @@ -308,7 +309,7 @@ pub struct Table<'a> { colours: &'a Colours, env: &'a Environment, widths: TableWidths, - time_format: &'a TimeFormat, + time_format: TimeFormat, size_format: SizeFormat, git: Option<&'a GitCache>, } @@ -330,8 +331,8 @@ impl<'a, 'f> Table<'a> { columns, git, env, - time_format: &options.time_format, - size_format: options.size_format, + time_format: options.time_format, + size_format: options.size_format, } } diff --git a/src/output/time.rs b/src/output/time.rs index c613921..79b3554 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -52,7 +52,7 @@ pub enum TimeFormat { // timestamps are separate types. impl TimeFormat { - pub fn format_local(&self, time: SystemTime) -> String { + pub fn format_local(self, time: SystemTime) -> String { match self { Self::DefaultFormat => default_local(time), Self::ISOFormat => iso_local(time), @@ -61,7 +61,7 @@ impl TimeFormat { } } - pub fn format_zoned(&self, time: SystemTime, zone: &TimeZone) -> String { + pub fn format_zoned(self, time: SystemTime, zone: &TimeZone) -> String { match self { Self::DefaultFormat => default_zoned(time, zone), Self::ISOFormat => iso_zoned(time, zone),