Fix Clippy lints

This commit is contained in:
ariasuni 2020-04-19 06:33:42 +02:00
parent 5a84953b4e
commit dba3f37b0a
14 changed files with 186 additions and 199 deletions

View File

@ -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());

View File

@ -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;

View File

@ -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<Vec<Attrib
None => 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)
}

View File

@ -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` types actual type varies, but the value returned
// from `metadata.permissions().mode()` is always `u32`.

View File

@ -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;

View File

@ -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};

View File

@ -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() })
}

View File

@ -1,5 +1,4 @@
use ansi_term::Style;
use glob;
use crate::fs::File;
use crate::options::{flags, Vars, Misfire};
@ -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();

View File

@ -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))
}
}
}

View File

@ -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,
});
}

View File

@ -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}'
}
}

View File

@ -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;

View File

@ -4,7 +4,6 @@ use std::time::Duration;
use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece};
use datetime::fmt::DateFormat;
use locale;
use std::cmp;