From 045172bd9ea7e1284bb4e0dc440bd26bceaccce0 Mon Sep 17 00:00:00 2001 From: ariasuni Date: Sat, 8 May 2021 16:37:53 +0200 Subject: [PATCH] Fix all remaining clippy warnings - Allow clippy::cast_*: generated warnings are mostly useless - Fix the other warnings so using clippy is actually useful --- src/fs/feature/xattr.rs | 10 +++++----- src/fs/file.rs | 4 ++-- src/main.rs | 8 ++++++-- src/options/view.rs | 15 ++++++--------- src/output/details.rs | 7 ++++--- src/output/table.rs | 2 +- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/fs/feature/xattr.rs b/src/fs/feature/xattr.rs index b819d24..542d205 100644 --- a/src/fs/feature/xattr.rs +++ b/src/fs/feature/xattr.rs @@ -246,7 +246,7 @@ mod lister { unsafe { listxattr( - c_path.as_ptr() as *const _, + c_path.as_ptr().cast(), ptr::null_mut(), 0, ) @@ -261,8 +261,8 @@ mod lister { unsafe { listxattr( - c_path.as_ptr() as *const _, - buf.as_mut_ptr() as *mut c_char, + c_path.as_ptr().cast(), + buf.as_mut_ptr().cast::(), bufsize as size_t, ) } @@ -276,8 +276,8 @@ mod lister { unsafe { getxattr( - c_path.as_ptr() as *const _, - buf.as_ptr() as *const c_char, + c_path.as_ptr().cast(), + buf.as_ptr().cast::(), ptr::null_mut(), 0, ) diff --git a/src/fs/file.rs b/src/fs/file.rs index b57777d..ea83f08 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -78,11 +78,11 @@ impl<'dir> File<'dir> { let metadata = std::fs::symlink_metadata(&path)?; 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> { - let path = parent_dir.path.to_path_buf(); + let path = parent_dir.path.clone(); let ext = File::ext(&path); debug!("Statting file {:?}", &path); diff --git a/src/main.rs b/src/main.rs index 92a9424..b8d1b21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,10 @@ #![warn(unused)] #![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::map_unwrap_or)] #![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 = 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) } @@ -306,7 +310,7 @@ impl<'args> Exa<'args> { let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; 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) } } diff --git a/src/options/view.rs b/src/options/view.rs index fe42838..41816fb 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -32,13 +32,10 @@ impl Mode { let flag = matches.has_where_any(|f| f.matches(&flags::LONG) || f.matches(&flags::ONE_LINE) || f.matches(&flags::GRID) || f.matches(&flags::TREE)); - let flag = match flag { - Some(f) => f, - None => { - Self::strict_check_long_flags(matches)?; - let grid = grid::Options::deduce(matches)?; - return Ok(Self::Grid(grid)); - } + let flag = if let Some(f) = flag { f } else { + Self::strict_check_long_flags(matches)?; + let grid = grid::Options::deduce(matches)?; + return Ok(Self::Grid(grid)); }; if flag.matches(&flags::LONG) @@ -194,7 +191,7 @@ impl TableOptions { let size_format = SizeFormat::deduce(matches)?; let user_format = UserFormat::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 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 }) } } diff --git a/src/output/details.rs b/src/output/details.rs index 1d029ec..9dca7d4 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -350,9 +350,10 @@ impl<'a> Render<'a> { fn render_error(&self, error: &io::Error, tree: TreeParams, path: Option) -> Row { use crate::output::file_name::Colours; - let error_message = match path { - Some(path) => format!("<{}: {}>", path.display(), error), - None => format!("<{}>", error), + let error_message = if let Some(path) = path { + format!("<{}: {}>", path.display(), error) + } else { + format!("<{}>", error) }; // TODO: broken_symlink() doesn’t quite seem like the right name for diff --git a/src/output/table.rs b/src/output/table.rs index 1680ec7..cf8b6cf 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -298,7 +298,7 @@ impl Environment { let users = Mutex::new(UsersCache::new()); - Self { tz, numeric, users } + Self { numeric, tz, users } } }