From dba3f37b0a562c36fdad5041de376ccd4562c4b0 Mon Sep 17 00:00:00 2001 From: ariasuni Date: Sun, 19 Apr 2020 06:33:42 +0200 Subject: [PATCH] Fix Clippy lints --- build.rs | 7 +- src/fs/feature/git.rs | 1 - src/fs/feature/xattr.rs | 57 ++++---- src/fs/file.rs | 2 - src/fs/filter.rs | 3 - src/options/misfire.rs | 2 - src/options/parser.rs | 9 +- src/options/style.rs | 5 +- src/options/view.rs | 2 +- src/output/details.rs | 4 +- src/output/grid.rs | 2 +- src/output/icons.rs | 288 ++++++++++++++++++++-------------------- src/output/table.rs | 2 - src/output/time.rs | 1 - 14 files changed, 186 insertions(+), 199 deletions(-) diff --git a/build.rs b/build.rs index 79a0174..083126e 100644 --- a/build.rs +++ b/build.rs @@ -50,9 +50,10 @@ fn write_statics() -> IOResult<()> { use std::io::Write; use std::path::PathBuf; - let ver = match is_development_version() { - true => format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()), - false => format!("exa v{}", cargo_version()), + let ver = if is_development_version() { + format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()) + } else { + format!("exa v{}", cargo_version()) }; let out = PathBuf::from(env::var("OUT_DIR").unwrap()); diff --git a/src/fs/feature/git.rs b/src/fs/feature/git.rs index c6edc67..afbf0c3 100644 --- a/src/fs/feature/git.rs +++ b/src/fs/feature/git.rs @@ -3,7 +3,6 @@ use std::path::{Path, PathBuf}; use std::sync::Mutex; -use git2; use log::{debug, error, info, warn}; use crate::fs::fields as f; diff --git a/src/fs/feature/xattr.rs b/src/fs/feature/xattr.rs index 8f57d67..333f3ff 100644 --- a/src/fs/feature/xattr.rs +++ b/src/fs/feature/xattr.rs @@ -2,6 +2,7 @@ #![allow(trivial_casts)] // for ARM extern crate libc; +use std::cmp::Ordering; use std::io; use std::path::Path; @@ -58,44 +59,44 @@ pub fn list_attrs(lister: &lister::Lister, path: &Path) -> io::Result return Err(io::Error::new(io::ErrorKind::Other, "Error: path somehow contained a NUL?")), }; - let mut names = Vec::new(); let bufsize = lister.listxattr_first(&c_path); - - if bufsize < 0 { - return Err(io::Error::last_os_error()); + match bufsize.cmp(&0) { + Ordering::Less => return Err(io::Error::last_os_error()), + Ordering::Equal => return Ok(Vec::new()), + Ordering::Greater => {}, } - else if bufsize > 0 { - let mut buf = vec![0u8; bufsize as usize]; - let err = lister.listxattr_second(&c_path, &mut buf, bufsize); - if err < 0 { - return Err(io::Error::last_os_error()); - } + let mut buf = vec![0u8; bufsize as usize]; + let err = lister.listxattr_second(&c_path, &mut buf, bufsize); - if err > 0 { - // End indices of the attribute names - // the buffer contains 0-terminated c-strings - let idx = buf.iter().enumerate().filter_map(|(i, v)| - if *v == 0 { Some(i) } else { None } - ); - let mut start = 0; + match err.cmp(&0) { + Ordering::Less => return Err(io::Error::last_os_error()), + Ordering::Equal => return Ok(Vec::new()), + Ordering::Greater => {}, + } - for end in idx { - let c_end = end + 1; // end of the c-string (including 0) - let size = lister.getxattr(&c_path, &buf[start..c_end]); + let mut names = Vec::new(); + if err > 0 { + // End indices of the attribute names + // the buffer contains 0-terminated c-strings + let idx = buf.iter().enumerate().filter_map(|(i, v)| + if *v == 0 { Some(i) } else { None } + ); + let mut start = 0; - if size > 0 { - names.push(Attribute { - name: lister.translate_attribute_name(&buf[start..end]), - size: size as usize - }); - } + for end in idx { + let c_end = end + 1; // end of the c-string (including 0) + let size = lister.getxattr(&c_path, &buf[start..c_end]); - start = c_end; + if size > 0 { + names.push(Attribute { + name: lister.translate_attribute_name(&buf[start..end]), + size: size as usize + }); } + start = c_end; } - } Ok(names) } diff --git a/src/fs/file.rs b/src/fs/file.rs index 0d42d54..96d8957 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -474,8 +474,6 @@ impl<'dir> FileTarget<'dir> { /// More readable aliases for the permission bits exposed by libc. #[allow(trivial_numeric_casts)] mod modes { - use libc; - pub type Mode = u32; // The `libc::mode_t` type’s actual type varies, but the value returned // from `metadata.permissions().mode()` is always `u32`. diff --git a/src/fs/filter.rs b/src/fs/filter.rs index 44944c3..c7e2169 100644 --- a/src/fs/filter.rs +++ b/src/fs/filter.rs @@ -5,9 +5,6 @@ use std::iter::FromIterator; use std::os::unix::fs::MetadataExt; use std::path::Path; -use glob; -use natord; - use crate::fs::File; use crate::fs::DotFilter; diff --git a/src/options/misfire.rs b/src/options/misfire.rs index 00c0073..f0bf9f4 100644 --- a/src/options/misfire.rs +++ b/src/options/misfire.rs @@ -2,8 +2,6 @@ use std::ffi::OsString; use std::fmt; use std::num::ParseIntError; -use glob; - use crate::options::{flags, HelpString, VersionString}; use crate::options::parser::{Arg, Flag, ParseError}; diff --git a/src/options/parser.rs b/src/options/parser.rs index f6a219a..909538c 100644 --- a/src/options/parser.rs +++ b/src/options/parser.rs @@ -267,7 +267,7 @@ impl Args { // -abx => error // else { - for (index, byte) in bytes.into_iter().enumerate().skip(1) { + for (index, byte) in bytes.iter().enumerate().skip(1) { let arg = self.lookup_short(*byte)?; let flag = Flag::Short(*byte); match arg.takes_value { @@ -283,7 +283,7 @@ impl Args { } else { match arg.takes_value { - Forbidden => assert!(false), + Forbidden => unreachable!(), Necessary(_) => { return Err(ParseError::NeedsValue { flag, values }); }, @@ -292,7 +292,6 @@ impl Args { } } } - } } } @@ -309,14 +308,14 @@ impl Args { } fn lookup_short(&self, short: ShortArg) -> Result<&Arg, ParseError> { - match self.0.into_iter().find(|arg| arg.short == Some(short)) { + match self.0.iter().find(|arg| arg.short == Some(short)) { Some(arg) => Ok(arg), None => Err(ParseError::UnknownShortArgument { attempt: short }) } } fn lookup_long<'b>(&self, long: &'b OsStr) -> Result<&Arg, ParseError> { - match self.0.into_iter().find(|arg| arg.long == long) { + match self.0.iter().find(|arg| arg.long == long) { Some(arg) => Ok(arg), None => Err(ParseError::UnknownArgument { attempt: long.to_os_string() }) } diff --git a/src/options/style.rs b/src/options/style.rs index c62ae63..177cb12 100644 --- a/src/options/style.rs +++ b/src/options/style.rs @@ -1,5 +1,4 @@ use ansi_term::Style; -use glob; use crate::fs::File; use crate::options::{flags, Vars, Misfire}; @@ -124,7 +123,7 @@ impl Styles { /// type mappings or not. The `reset` code needs to be the first one. fn parse_color_vars(vars: &V, colours: &mut Colours) -> (ExtensionMappings, bool) { use log::warn; - + use crate::options::vars; use crate::style::LSColors; @@ -366,7 +365,7 @@ mod customs_test { #[test] fn $name() { let mappings: Vec<(glob::Pattern, Style)> - = $mappings.into_iter() + = $mappings.iter() .map(|t| (glob::Pattern::new(t.0).unwrap(), t.1)) .collect(); diff --git a/src/options/view.rs b/src/options/view.rs index eaebecf..77adef1 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -290,7 +290,7 @@ impl TimeFormat { Ok(TimeFormat::FullISO) } else { - Err(Misfire::BadArgument(&flags::TIME_STYLE, word.into())) + Err(Misfire::BadArgument(&flags::TIME_STYLE, word)) } } } diff --git a/src/output/details.rs b/src/output/details.rs index 217b401..dd687ea 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -138,7 +138,7 @@ struct Egg<'a> { errors: Vec<(IOError, Option)>, dir: Option, file: &'a File<'a>, - icon: Option, + icon: Option, } impl<'a> AsRef> for Egg<'a> { @@ -263,7 +263,7 @@ impl<'a> Render<'a> { } }; - let icon = if self.opts.icons { + let icon = if self.opts.icons { Some(painted_icon(&file, &self.style)) } else { None }; diff --git a/src/output/grid.rs b/src/output/grid.rs index f271f56..b1c671c 100644 --- a/src/output/grid.rs +++ b/src/output/grid.rs @@ -50,7 +50,7 @@ impl<'a> Render<'a> { }; grid.add(tg::Cell { - contents: format!("{icon}{filename}", icon=&icon.unwrap_or("".to_string()), filename=filename.strings().to_string()), + contents: format!("{icon}{filename}", icon=&icon.unwrap_or_default(), filename=filename.strings().to_string()), width: *width, }); } diff --git a/src/output/icons.rs b/src/output/icons.rs index 736d09d..00f90aa 100644 --- a/src/output/icons.rs +++ b/src/output/icons.rs @@ -28,7 +28,7 @@ pub fn painted_icon(file: &File, style: &FileStyle) -> String { let file_icon = icon(&file).to_string(); let painted = style.exts .colour_file(&file) - .map_or(file_icon.to_string(), |c| { + .map_or(file_icon.to_string(), |c| { // Remove underline from icon if c.is_underline { match c.foreground { @@ -36,7 +36,7 @@ pub fn painted_icon(file: &File, style: &FileStyle) -> String { None => Style::default().paint(file_icon).to_string(), } } else { - c.paint(file_icon).to_string() + c.paint(file_icon).to_string() } }); format!("{} ", painted) @@ -46,149 +46,147 @@ fn icon(file: &File) -> char { let extensions = Box::new(FileExtensions); if file.is_directory() { '\u{f115}' } else if let Some(icon) = extensions.icon_file(file) { icon } - else { - if let Some(ext) = file.ext.as_ref() { - match ext.as_str() { - "ai" => '\u{e7b4}', - "android" => '\u{e70e}', - "apple" => '\u{f179}', - "avro" => '\u{e60b}', - "clj" => '\u{e768}', - "coffee" => '\u{f0f4}', - "cpp" => '\u{e61d}', - "hpp" => '\u{e61d}', - "c" => '\u{e61e}', - "h" => '\u{e61e}', - "cs" => '\u{f81a}', - "css" => '\u{e749}', - "d" => '\u{e7af}', - "dart" => '\u{e798}', - "db" => '\u{f1c0}', - "diff" => '\u{f440}', - "patch" => '\u{f440}', - "rtf" => '\u{f1c2}', - "doc" => '\u{f1c2}', - "docx" => '\u{f1c2}', - "odt" => '\u{f1c2}', - "ebook" => '\u{e28b}', - "env" => '\u{f462}', - "epub" => '\u{e28a}', - "erl" => '\u{e7b1}', - "font" => '\u{f031}', - "gform" => '\u{f298}', - "git" => '\u{f1d3}', - "go" => '\u{e626}', - "hs" => '\u{e777}', - "htm" => '\u{f13b}', - "html" => '\u{f13b}', - "xhtml" => '\u{f13b}', - "iml" => '\u{e7b5}', - "java" => '\u{e204}', - "js" => '\u{e74e}', - "mjs" => '\u{e74e}', - "json" => '\u{e60b}', - "jsx" => '\u{e7ba}', - "vue" => '\u{fd42}', - "node" => '\u{f898}', - "less" => '\u{e758}', - "log" => '\u{f18d}', - "lua" => '\u{e620}', - "md" => '\u{f48a}', - "markdown" => '\u{f48a}', - "mustache" => '\u{e60f}', - "npmignore" => '\u{e71e}', - "pdf" => '\u{f1c1}', - "djvu" => '\u{f02d}', - "mobi" => '\u{f02d}', - "php" => '\u{e73d}', - "pl" => '\u{e769}', - "ppt" => '\u{f1c4}', - "pptx" => '\u{f1c4}', - "odp" => '\u{f1c4}', - "psd" => '\u{e7b8}', - "py" => '\u{e606}', - "r" => '\u{f25d}', - "rb" => '\u{e21e}', - "ru" => '\u{e21e}', - "erb" => '\u{e21e}', - "gem" => '\u{e21e}', - "rdb" => '\u{e76d}', - "rs" => '\u{e7a8}', - "rss" => '\u{f09e}', - "rubydoc" => '\u{e73b}', - "sass" => '\u{e74b}', - "stylus" => '\u{e759}', - "scala" => '\u{e737}', - "shell" => '\u{f489}', - "sqlite3" => '\u{e7c4}', - "styl" => '\u{e600}', - "latex" => '\u{e600}', - "tex" => '\u{e600}', - "ts" => '\u{e628}', - "tsx" => '\u{e628}', - "twig" => '\u{e61c}', - "txt" => '\u{f15c}', - "video" => '\u{f03d}', - "vim" => '\u{e62b}', - "xml" => '\u{e619}', - "yml" => '\u{f481}', - "yaml" => '\u{f481}', - "rar" => '\u{f410}', - "zip" => '\u{f410}', - "bz" => '\u{f410}', - "bz2" => '\u{f410}', - "xz" => '\u{f410}', - "taz" => '\u{f410}', - "tbz" => '\u{f410}', - "tbz2" => '\u{f410}', - "tz" => '\u{f410}', - "tar" => '\u{f410}', - "tzo" => '\u{f410}', - "lz" => '\u{f410}', - "lzh" => '\u{f410}', - "lzma" => '\u{f410}', - "lzo" => '\u{f410}', - "gz" => '\u{f410}', - "deb" => '\u{e77d}', - "rpm" => '\u{e7bb}', - "exe" => '\u{e70f}', - "msi" => '\u{e70f}', - "dll" => '\u{e70f}', - "cab" => '\u{e70f}', - "bat" => '\u{e70f}', - "cmd" => '\u{e70f}', - "sh" => '\u{e795}', - "bash" => '\u{e795}', - "zsh" => '\u{e795}', - "fish" => '\u{e795}', - "csh" => '\u{e795}', - "ini" => '\u{e615}', - "toml" => '\u{e615}', - "cfg" => '\u{e615}', - "conf" => '\u{e615}', - "apk" => '\u{e70e}', - "ttf" => '\u{f031}', - "woff" => '\u{f031}', - "woff2" => '\u{f031}', - "otf" => '\u{f031}', - "csv" => '\u{f1c3}', - "tsv" => '\u{f1c3}', - "xls" => '\u{f1c3}', - "xlsx" => '\u{f1c3}', - "ods" => '\u{f1c3}', - "so" => '\u{f17c}', - "sql" => '\u{f1c0}', - "jar" => '\u{e256}', - "jad" => '\u{e256}', - "class" => '\u{e256}', - "war" => '\u{e256}', - "groovy" => '\u{e775}', - "iso" => '\u{e271}', - "lock" => '\u{f023}', - _ => '\u{f15b}' - } - } else { - '\u{f15b}' + else if let Some(ext) = file.ext.as_ref() { + match ext.as_str() { + "ai" => '\u{e7b4}', + "android" => '\u{e70e}', + "apple" => '\u{f179}', + "avro" => '\u{e60b}', + "clj" => '\u{e768}', + "coffee" => '\u{f0f4}', + "cpp" => '\u{e61d}', + "hpp" => '\u{e61d}', + "c" => '\u{e61e}', + "h" => '\u{e61e}', + "cs" => '\u{f81a}', + "css" => '\u{e749}', + "d" => '\u{e7af}', + "dart" => '\u{e798}', + "db" => '\u{f1c0}', + "diff" => '\u{f440}', + "patch" => '\u{f440}', + "rtf" => '\u{f1c2}', + "doc" => '\u{f1c2}', + "docx" => '\u{f1c2}', + "odt" => '\u{f1c2}', + "ebook" => '\u{e28b}', + "env" => '\u{f462}', + "epub" => '\u{e28a}', + "erl" => '\u{e7b1}', + "font" => '\u{f031}', + "gform" => '\u{f298}', + "git" => '\u{f1d3}', + "go" => '\u{e626}', + "hs" => '\u{e777}', + "htm" => '\u{f13b}', + "html" => '\u{f13b}', + "xhtml" => '\u{f13b}', + "iml" => '\u{e7b5}', + "java" => '\u{e204}', + "js" => '\u{e74e}', + "mjs" => '\u{e74e}', + "json" => '\u{e60b}', + "jsx" => '\u{e7ba}', + "vue" => '\u{fd42}', + "node" => '\u{f898}', + "less" => '\u{e758}', + "log" => '\u{f18d}', + "lua" => '\u{e620}', + "md" => '\u{f48a}', + "markdown" => '\u{f48a}', + "mustache" => '\u{e60f}', + "npmignore" => '\u{e71e}', + "pdf" => '\u{f1c1}', + "djvu" => '\u{f02d}', + "mobi" => '\u{f02d}', + "php" => '\u{e73d}', + "pl" => '\u{e769}', + "ppt" => '\u{f1c4}', + "pptx" => '\u{f1c4}', + "odp" => '\u{f1c4}', + "psd" => '\u{e7b8}', + "py" => '\u{e606}', + "r" => '\u{f25d}', + "rb" => '\u{e21e}', + "ru" => '\u{e21e}', + "erb" => '\u{e21e}', + "gem" => '\u{e21e}', + "rdb" => '\u{e76d}', + "rs" => '\u{e7a8}', + "rss" => '\u{f09e}', + "rubydoc" => '\u{e73b}', + "sass" => '\u{e74b}', + "stylus" => '\u{e759}', + "scala" => '\u{e737}', + "shell" => '\u{f489}', + "sqlite3" => '\u{e7c4}', + "styl" => '\u{e600}', + "latex" => '\u{e600}', + "tex" => '\u{e600}', + "ts" => '\u{e628}', + "tsx" => '\u{e628}', + "twig" => '\u{e61c}', + "txt" => '\u{f15c}', + "video" => '\u{f03d}', + "vim" => '\u{e62b}', + "xml" => '\u{e619}', + "yml" => '\u{f481}', + "yaml" => '\u{f481}', + "rar" => '\u{f410}', + "zip" => '\u{f410}', + "bz" => '\u{f410}', + "bz2" => '\u{f410}', + "xz" => '\u{f410}', + "taz" => '\u{f410}', + "tbz" => '\u{f410}', + "tbz2" => '\u{f410}', + "tz" => '\u{f410}', + "tar" => '\u{f410}', + "tzo" => '\u{f410}', + "lz" => '\u{f410}', + "lzh" => '\u{f410}', + "lzma" => '\u{f410}', + "lzo" => '\u{f410}', + "gz" => '\u{f410}', + "deb" => '\u{e77d}', + "rpm" => '\u{e7bb}', + "exe" => '\u{e70f}', + "msi" => '\u{e70f}', + "dll" => '\u{e70f}', + "cab" => '\u{e70f}', + "bat" => '\u{e70f}', + "cmd" => '\u{e70f}', + "sh" => '\u{e795}', + "bash" => '\u{e795}', + "zsh" => '\u{e795}', + "fish" => '\u{e795}', + "csh" => '\u{e795}', + "ini" => '\u{e615}', + "toml" => '\u{e615}', + "cfg" => '\u{e615}', + "conf" => '\u{e615}', + "apk" => '\u{e70e}', + "ttf" => '\u{f031}', + "woff" => '\u{f031}', + "woff2" => '\u{f031}', + "otf" => '\u{f031}', + "csv" => '\u{f1c3}', + "tsv" => '\u{f1c3}', + "xls" => '\u{f1c3}', + "xlsx" => '\u{f1c3}', + "ods" => '\u{f1c3}', + "so" => '\u{f17c}', + "sql" => '\u{f1c0}', + "jar" => '\u{e256}', + "jad" => '\u{e256}', + "class" => '\u{e256}', + "war" => '\u{e256}', + "groovy" => '\u{e775}', + "iso" => '\u{e271}', + "lock" => '\u{f023}', + _ => '\u{f15b}' } + } else { + '\u{f15b}' } } diff --git a/src/output/table.rs b/src/output/table.rs index 90fb236..a4afaca 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -6,8 +6,6 @@ use std::sync::{Mutex, MutexGuard}; use datetime::TimeZone; use zoneinfo_compiled::{CompiledData, Result as TZResult}; -use locale; - use log::debug; use users::UsersCache; diff --git a/src/output/time.rs b/src/output/time.rs index 49b6930..701fdf7 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -4,7 +4,6 @@ use std::time::Duration; use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece}; use datetime::fmt::DateFormat; -use locale; use std::cmp;