Fix all remaining clippy warnings

- Allow clippy::cast_*: generated warnings are mostly useless
- Fix the other warnings so using clippy is actually useful
This commit is contained in:
ariasuni 2021-05-08 16:37:53 +02:00
parent f8610d05ae
commit 045172bd9e
6 changed files with 24 additions and 22 deletions

View File

@ -246,7 +246,7 @@ mod lister {
unsafe { unsafe {
listxattr( listxattr(
c_path.as_ptr() as *const _, c_path.as_ptr().cast(),
ptr::null_mut(), ptr::null_mut(),
0, 0,
) )
@ -261,8 +261,8 @@ mod lister {
unsafe { unsafe {
listxattr( listxattr(
c_path.as_ptr() as *const _, c_path.as_ptr().cast(),
buf.as_mut_ptr() as *mut c_char, buf.as_mut_ptr().cast::<i8>(),
bufsize as size_t, bufsize as size_t,
) )
} }
@ -276,8 +276,8 @@ mod lister {
unsafe { unsafe {
getxattr( getxattr(
c_path.as_ptr() as *const _, c_path.as_ptr().cast(),
buf.as_ptr() as *const c_char, buf.as_ptr().cast::<i8>(),
ptr::null_mut(), ptr::null_mut(),
0, 0,
) )

View File

@ -78,11 +78,11 @@ impl<'dir> File<'dir> {
let metadata = std::fs::symlink_metadata(&path)?; let metadata = std::fs::symlink_metadata(&path)?;
let is_all_all = false; let is_all_all = false;
Ok(File { path, parent_dir, metadata, ext, name, is_all_all }) Ok(File { name, ext, path, metadata, parent_dir, is_all_all })
} }
pub fn new_aa_current(parent_dir: &'dir Dir) -> io::Result<File<'dir>> { pub fn new_aa_current(parent_dir: &'dir Dir) -> io::Result<File<'dir>> {
let path = parent_dir.path.to_path_buf(); let path = parent_dir.path.clone();
let ext = File::ext(&path); let ext = File::ext(&path);
debug!("Statting file {:?}", &path); debug!("Statting file {:?}", &path);

View File

@ -7,6 +7,10 @@
#![warn(unused)] #![warn(unused)]
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::cast_precision_loss)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_possible_wrap)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::enum_glob_use)] #![allow(clippy::enum_glob_use)]
#![allow(clippy::map_unwrap_or)] #![allow(clippy::map_unwrap_or)]
#![allow(clippy::match_same_arms)] #![allow(clippy::match_same_arms)]
@ -282,7 +286,7 @@ impl<'args> Exa<'args> {
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref(); let git = self.git.as_ref();
let r = details::Render { dir, files, theme, file_style, opts, filter, recurse, git_ignoring, git }; let r = details::Render { dir, files, theme, file_style, opts, recurse, filter, git_ignoring, git };
r.render(&mut self.writer) r.render(&mut self.writer)
} }
@ -306,7 +310,7 @@ impl<'args> Exa<'args> {
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref(); let git = self.git.as_ref();
let r = details::Render { dir, files, theme, file_style, opts, filter, recurse, git_ignoring, git }; let r = details::Render { dir, files, theme, file_style, opts, recurse, filter, git_ignoring, git };
r.render(&mut self.writer) r.render(&mut self.writer)
} }
} }

View File

@ -32,13 +32,10 @@ impl Mode {
let flag = matches.has_where_any(|f| f.matches(&flags::LONG) || f.matches(&flags::ONE_LINE) let flag = matches.has_where_any(|f| f.matches(&flags::LONG) || f.matches(&flags::ONE_LINE)
|| f.matches(&flags::GRID) || f.matches(&flags::TREE)); || f.matches(&flags::GRID) || f.matches(&flags::TREE));
let flag = match flag { let flag = if let Some(f) = flag { f } else {
Some(f) => f, Self::strict_check_long_flags(matches)?;
None => { let grid = grid::Options::deduce(matches)?;
Self::strict_check_long_flags(matches)?; return Ok(Self::Grid(grid));
let grid = grid::Options::deduce(matches)?;
return Ok(Self::Grid(grid));
}
}; };
if flag.matches(&flags::LONG) if flag.matches(&flags::LONG)
@ -194,7 +191,7 @@ impl TableOptions {
let size_format = SizeFormat::deduce(matches)?; let size_format = SizeFormat::deduce(matches)?;
let user_format = UserFormat::deduce(matches)?; let user_format = UserFormat::deduce(matches)?;
let columns = Columns::deduce(matches)?; let columns = Columns::deduce(matches)?;
Ok(Self { time_format, size_format, columns , user_format}) Ok(Self { size_format, time_format, user_format, columns })
} }
} }
@ -214,7 +211,7 @@ impl Columns {
let filesize = ! matches.has(&flags::NO_FILESIZE)?; let filesize = ! matches.has(&flags::NO_FILESIZE)?;
let user = ! matches.has(&flags::NO_USER)?; let user = ! matches.has(&flags::NO_USER)?;
Ok(Self { time_types, git, octal, blocks, group, inode, links, permissions, filesize, user }) Ok(Self { time_types, inode, links, blocks, group, git, octal, permissions, filesize, user })
} }
} }

View File

@ -350,9 +350,10 @@ impl<'a> Render<'a> {
fn render_error(&self, error: &io::Error, tree: TreeParams, path: Option<PathBuf>) -> Row { fn render_error(&self, error: &io::Error, tree: TreeParams, path: Option<PathBuf>) -> Row {
use crate::output::file_name::Colours; use crate::output::file_name::Colours;
let error_message = match path { let error_message = if let Some(path) = path {
Some(path) => format!("<{}: {}>", path.display(), error), format!("<{}: {}>", path.display(), error)
None => format!("<{}>", error), } else {
format!("<{}>", error)
}; };
// TODO: broken_symlink() doesnt quite seem like the right name for // TODO: broken_symlink() doesnt quite seem like the right name for

View File

@ -298,7 +298,7 @@ impl Environment {
let users = Mutex::new(UsersCache::new()); let users = Mutex::new(UsersCache::new());
Self { tz, numeric, users } Self { numeric, tz, users }
} }
} }