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.
This commit is contained in:
Benjamin Sago 2020-10-13 01:46:17 +01:00
parent 3dc86c99ad
commit 002080cde8
9 changed files with 42 additions and 28 deletions

View File

@ -167,16 +167,14 @@ impl GitRepo {
} }
}; };
match repo.workdir() { if let Some(workdir) = repo.workdir() {
Some(workdir) => { let workdir = workdir.to_path_buf();
let workdir = workdir.to_path_buf(); let contents = Mutex::new(GitContents::Before { repo });
let contents = Mutex::new(GitContents::Before { repo }); Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() })
Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() }) }
} else {
None => { warn!("Repository has no workdir?");
warn!("Repository has no workdir?"); Err(path)
Err(path)
}
} }
} }
} }

View File

@ -13,6 +13,7 @@
// C-style `blkcnt_t` types dont follow Rusts rules! // C-style `blkcnt_t` types dont follow Rusts rules!
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(clippy::struct_excessive_bools)]
/// The type of a files block count. /// The type of a files block count.

View File

@ -337,19 +337,19 @@ impl<'dir> File<'dir> {
/// This files last changed timestamp, if available on this platform. /// This files last changed timestamp, if available on this platform.
pub fn changed_time(&self) -> Option<SystemTime> { pub fn changed_time(&self) -> Option<SystemTime> {
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 sec < 0 {
if nsec > 0 { if nanosec > 0 {
sec += 1; 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) Some(UNIX_EPOCH - duration)
} }
else { 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) Some(UNIX_EPOCH + duration)
} }
} }

View File

@ -6,6 +6,21 @@
#![warn(trivial_casts, trivial_numeric_casts)] #![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused)] #![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::env;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::io::{self, Write, ErrorKind}; use std::io::{self, Write, ErrorKind};

View File

@ -128,7 +128,7 @@ impl Options {
let strictness = match vars.get(vars::EXA_STRICT) { let strictness = match vars.get(vars::EXA_STRICT) {
None => Strictness::UseLastArguments, None => Strictness::UseLastArguments,
Some(ref t) if t.is_empty() => 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) { let Matches { flags, frees } = match flags::ALL_ARGS.parse(args, strictness) {

View File

@ -262,18 +262,17 @@ impl TimeFormat {
/// Determine how time should be formatted in timestamp columns. /// Determine how time should be formatted in timestamp columns.
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> { fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
let word = match matches.get(&flags::TIME_STYLE)? { let word =
Some(w) => { if let Some(w) = matches.get(&flags::TIME_STYLE)? {
w.to_os_string() w.to_os_string()
} }
None => { else {
use crate::options::vars; use crate::options::vars;
match vars.get(vars::TIME_STYLE) { match vars.get(vars::TIME_STYLE) {
Some(ref t) if ! t.is_empty() => t.clone(), Some(ref t) if ! t.is_empty() => t.clone(),
_ => return Ok(Self::DefaultFormat) _ => return Ok(Self::DefaultFormat)
} }
}, };
};
if &word == "default" { if &word == "default" {
Ok(Self::DefaultFormat) Ok(Self::DefaultFormat)

View File

@ -8,11 +8,11 @@ use crate::output::time::TimeFormat;
pub trait Render { pub trait Render {
fn render(self, style: Style, tz: &Option<TimeZone>, format: &TimeFormat) -> TextCell; fn render(self, style: Style, tz: &Option<TimeZone>, format: TimeFormat) -> TextCell;
} }
impl Render for Option<SystemTime> { impl Render for Option<SystemTime> {
fn render(self, style: Style, tz: &Option<TimeZone>, format: &TimeFormat) -> TextCell { fn render(self, style: Style, tz: &Option<TimeZone>, format: TimeFormat) -> TextCell {
let datestamp = if let Some(time) = self { let datestamp = if let Some(time) = self {
if let Some(ref tz) = tz { if let Some(ref tz) = tz {
format.format_zoned(time, tz) format.format_zoned(time, tz)

View File

@ -225,6 +225,7 @@ impl TimeType {
/// There should always be at least one of these — theres no way to disable /// There should always be at least one of these — theres no way to disable
/// the time columns entirely (yet). /// the time columns entirely (yet).
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Debug, Copy, Clone)]
#[allow(clippy::struct_excessive_bools)]
pub struct TimeTypes { pub struct TimeTypes {
pub modified: bool, pub modified: bool,
pub changed: bool, pub changed: bool,
@ -308,7 +309,7 @@ pub struct Table<'a> {
colours: &'a Colours, colours: &'a Colours,
env: &'a Environment, env: &'a Environment,
widths: TableWidths, widths: TableWidths,
time_format: &'a TimeFormat, time_format: TimeFormat,
size_format: SizeFormat, size_format: SizeFormat,
git: Option<&'a GitCache>, git: Option<&'a GitCache>,
} }
@ -330,8 +331,8 @@ impl<'a, 'f> Table<'a> {
columns, columns,
git, git,
env, env,
time_format: &options.time_format, time_format: options.time_format,
size_format: options.size_format, size_format: options.size_format,
} }
} }

View File

@ -52,7 +52,7 @@ pub enum TimeFormat {
// timestamps are separate types. // timestamps are separate types.
impl TimeFormat { impl TimeFormat {
pub fn format_local(&self, time: SystemTime) -> String { pub fn format_local(self, time: SystemTime) -> String {
match self { match self {
Self::DefaultFormat => default_local(time), Self::DefaultFormat => default_local(time),
Self::ISOFormat => iso_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 { match self {
Self::DefaultFormat => default_zoned(time, zone), Self::DefaultFormat => default_zoned(time, zone),
Self::ISOFormat => iso_zoned(time, zone), Self::ISOFormat => iso_zoned(time, zone),