Explorar o código

style: fix various clippy warnings for rust 1.86

OpenBSD 7.6 tests are failing because it only comes with
rust 1.81 while we need 1.82 at least. OpenBSD 7.7 comes with
rust 1.86, but its clippy complains about various issues.
This fixes said things to make OpenBSD CI green again, and
also as preparation for the future.

Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
Sandro-Alessio Gierens hai 8 meses
pai
achega
67970d6346

+ 2 - 2
src/fs/dir.rs

@@ -111,7 +111,7 @@ pub struct Files<'dir, 'ig> {
     total_size: bool,
 }
 
-impl<'dir, 'ig> Files<'dir, 'ig> {
+impl<'dir> Files<'dir, '_> {
     fn parent(&self) -> PathBuf {
         // We can’t use `Path#parent` here because all it does is remove the
         // last path component, which is no good for us if the path is
@@ -183,7 +183,7 @@ enum DotsNext {
     Files,
 }
 
-impl<'dir, 'ig> Iterator for Files<'dir, 'ig> {
+impl<'dir> Iterator for Files<'dir, '_> {
     type Item = File<'dir>;
 
     fn next(&mut self) -> Option<Self::Item> {

+ 6 - 6
src/fs/feature/git.rs

@@ -74,9 +74,9 @@ impl FromIterator<PathBuf> for GitCache {
 
         for path in iter {
             if git.misses.contains(&path) {
-                debug!("Skipping {:?} because it already came back Gitless", path);
+                debug!("Skipping {path:?} because it already came back Gitless");
             } else if git.repos.iter().any(|e| e.has_path(&path)) {
-                debug!("Skipping {:?} because we already queried it", path);
+                debug!("Skipping {path:?} because we already queried it");
             } else {
                 let flags = git2::RepositoryOpenFlags::FROM_ENV;
                 match GitRepo::discover(path, flags) {
@@ -181,7 +181,7 @@ impl GitRepo {
     /// the repository's "gitdir" (or a "gitlink" to the gitdir), or the
     /// path is the start of a rootwards search for the repository.
     fn discover(path: PathBuf, flags: git2::RepositoryOpenFlags) -> Result<Self, PathBuf> {
-        info!("Opening Git repository for {:?} ({:?})", path, flags);
+        info!("Opening Git repository for {path:?} ({flags:?})");
         let unused: [&OsStr; 0] = [];
         let repo = match git2::Repository::open_ext(&path, flags, unused) {
             Ok(r) => r,
@@ -227,7 +227,7 @@ impl GitContents {
 fn repo_to_statuses(repo: &git2::Repository, workdir: &Path) -> Git {
     let mut statuses = Vec::new();
 
-    info!("Getting Git statuses for repo with workdir {:?}", workdir);
+    info!("Getting Git statuses for repo with workdir {workdir:?}");
     match repo.statuses(None) {
         Ok(es) => {
             for e in es.iter() {
@@ -241,7 +241,7 @@ fn repo_to_statuses(repo: &git2::Repository, workdir: &Path) -> Git {
             statuses.push((workdir.join(".git"), git2::Status::IGNORED));
         }
         Err(e) => {
-            error!("Error looking up Git statuses: {:?}", e);
+            error!("Error looking up Git statuses: {e:?}");
         }
     }
 
@@ -403,7 +403,7 @@ fn current_branch(repo: &git2::Repository) -> Option<String> {
             return None;
         }
         Err(e) => {
-            error!("Error looking up Git branch: {:?}", e);
+            error!("Error looking up Git branch: {e:?}");
             return None;
         }
     };

+ 1 - 1
src/fs/feature/xattr.rs

@@ -672,7 +672,7 @@ struct BorrowedWriter<'a> {
     pub buffer: &'a mut Vec<u8>,
 }
 
-impl<'a> io::Write for BorrowedWriter<'a> {
+impl io::Write for BorrowedWriter<'_> {
     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
         self.buffer.write(buf)
     }

+ 11 - 11
src/fs/file.rs

@@ -142,14 +142,14 @@ impl<'dir> File<'dir> {
             RecursiveSize::None
         };
 
-        debug!("deref_links {}", deref_links);
+        debug!("deref_links {deref_links}");
 
         let filetype = match filetype {
             Some(f) => OnceLock::from(Some(f)),
             None => OnceLock::new(),
         };
 
-        debug!("deref_links {}", deref_links);
+        debug!("deref_links {deref_links}");
 
         let mut file = File {
             name,
@@ -228,7 +228,7 @@ impl<'dir> File<'dir> {
             back.as_os_str().to_string_lossy().to_string()
         } else {
             // use the path as fallback
-            error!("Path {:?} has no last component", path);
+            error!("Path {path:?} has no last component");
             path.display().to_string()
         }
     }
@@ -294,7 +294,7 @@ impl<'dir> File<'dir> {
 
     /// Whether this file is a directory on the filesystem.
     pub fn is_directory(&self) -> bool {
-        self.filetype().map_or(false, std::fs::FileType::is_dir)
+        self.filetype().is_some_and(std::fs::FileType::is_dir)
     }
 
     /// Whether this file is a directory, or a symlink pointing to a directory.
@@ -327,7 +327,7 @@ impl<'dir> File<'dir> {
     /// Whether this file is a regular file on the filesystem — that is, not a
     /// directory, a link, or anything else treated specially.
     pub fn is_file(&self) -> bool {
-        self.filetype().map_or(false, std::fs::FileType::is_file)
+        self.filetype().is_some_and(std::fs::FileType::is_file)
     }
 
     /// Whether this file is both a regular file *and* executable for the
@@ -347,31 +347,31 @@ impl<'dir> File<'dir> {
 
     /// Whether this file is a symlink on the filesystem.
     pub fn is_link(&self) -> bool {
-        self.filetype().map_or(false, FileType::is_symlink)
+        self.filetype().is_some_and(FileType::is_symlink)
     }
 
     /// Whether this file is a named pipe on the filesystem.
     #[cfg(unix)]
     pub fn is_pipe(&self) -> bool {
-        self.filetype().map_or(false, FileTypeExt::is_fifo)
+        self.filetype().is_some_and(FileTypeExt::is_fifo)
     }
 
     /// Whether this file is a char device on the filesystem.
     #[cfg(unix)]
     pub fn is_char_device(&self) -> bool {
-        self.filetype().map_or(false, FileTypeExt::is_char_device)
+        self.filetype().is_some_and(FileTypeExt::is_char_device)
     }
 
     /// Whether this file is a block device on the filesystem.
     #[cfg(unix)]
     pub fn is_block_device(&self) -> bool {
-        self.filetype().map_or(false, FileTypeExt::is_block_device)
+        self.filetype().is_some_and(FileTypeExt::is_block_device)
     }
 
     /// Whether this file is a socket on the filesystem.
     #[cfg(unix)]
     pub fn is_socket(&self) -> bool {
-        self.filetype().map_or(false, FileTypeExt::is_socket)
+        self.filetype().is_some_and(FileTypeExt::is_socket)
     }
 
     /// Determine the full path resolving all symbolic links on demand.
@@ -1016,7 +1016,7 @@ pub enum FileTarget<'dir> {
     // error — we just display the error message and move on.
 }
 
-impl<'dir> FileTarget<'dir> {
+impl FileTarget<'_> {
     /// Whether this link doesn’t lead to a file, for whatever reason. This
     /// gets used to determine how to highlight the link in grid views.
     #[must_use]

+ 1 - 1
src/info/sources.rs

@@ -8,7 +8,7 @@ use std::path::PathBuf;
 
 use crate::fs::File;
 
-impl<'a> File<'a> {
+impl File<'_> {
     /// For this file, return a vector of alternate file paths that, if any of
     /// them exist, mean that *this* file should be coloured as “compiled”.
     ///

+ 1 - 1
src/main.rs

@@ -256,7 +256,7 @@ fn git_repos(options: &Options, args: &[&OsStr]) -> bool {
     }
 }
 
-impl<'args> Exa<'args> {
+impl Exa<'_> {
     /// # Errors
     ///
     /// Will return `Err` if printing to stderr fails.

+ 3 - 3
src/options/parser.rs

@@ -399,7 +399,7 @@ pub struct MatchedFlags<'args> {
     strictness: Strictness,
 }
 
-impl<'a> MatchedFlags<'a> {
+impl MatchedFlags<'_> {
     /// Whether the given argument was specified.
     /// Returns `true` if it was, `false` if it wasn’t, and an error in
     /// strict mode if it was specified more than once.
@@ -554,14 +554,14 @@ impl fmt::Display for ParseError {
 fn os_str_to_bytes(s: &OsStr) -> &[u8] {
     use std::os::unix::ffi::OsStrExt;
 
-    return s.as_bytes();
+    s.as_bytes()
 }
 
 #[cfg(unix)]
 fn bytes_to_os_str(b: &[u8]) -> &OsStr {
     use std::os::unix::ffi::OsStrExt;
 
-    return OsStr::from_bytes(b);
+    OsStr::from_bytes(b)
 }
 
 #[cfg(windows)]

+ 1 - 1
src/options/vars.rs

@@ -153,6 +153,6 @@ impl MockVars {
             "COLUMNS" => self.columns = value.clone(),
             "NO_COLOR" => self.no_colors = value.clone(),
             _ => (),
-        };
+        }
     }
 }

+ 1 - 1
src/options/view.rs

@@ -513,7 +513,7 @@ impl ColorScaleOptions {
                     &flags::COLOR_SCALE,
                     OsString::from(word),
                 ))?,
-            };
+            }
         }
 
         Ok(options)

+ 3 - 3
src/output/color_scale.rs

@@ -185,7 +185,7 @@ fn update_information_recursively(
                 }
                 Err(e) => trace!("Unable to access directory {}: {}", file.name, e),
             }
-        };
+        }
     }
 }
 
@@ -203,7 +203,7 @@ impl Extremes {
                     range.max = value;
                 } else if value < range.min {
                     range.min = value;
-                };
+                }
             }
             (Some(value), rel) => {
                 let _ = rel.insert({
@@ -214,7 +214,7 @@ impl Extremes {
                 });
             }
             _ => (),
-        };
+        }
     }
 }
 

+ 3 - 3
src/output/details.rs

@@ -313,7 +313,7 @@ impl<'a> Render<'a> {
                             }
                         }
                     }
-                };
+                }
 
                 Egg {
                     table_row,
@@ -344,7 +344,7 @@ impl<'a> Render<'a> {
                 .paint()
                 .promote();
 
-            debug!("file_name {:?}", file_name);
+            debug!("file_name {file_name:?}");
 
             let row = Row {
                 tree: tree_params,
@@ -491,7 +491,7 @@ pub struct TableIter<'a> {
     tree_trunk:  TreeTrunk,
 }
 
-impl<'a> Iterator for TableIter<'a> {
+impl Iterator for TableIter<'_> {
     type Item = TextCell;
 
     fn next(&mut self) -> Option<Self::Item> {

+ 2 - 2
src/output/file_name.rs

@@ -165,7 +165,7 @@ pub struct FileName<'a, 'dir, C> {
     mount_style: MountStyle,
 }
 
-impl<'a, 'dir, C> FileName<'a, 'dir, C> {
+impl<C> FileName<'_, '_, C> {
     /// Sets the flag on this file name to display link targets with an
     /// arrow followed by their path.
     #[must_use]
@@ -189,7 +189,7 @@ impl<'a, 'dir, C> FileName<'a, 'dir, C> {
     }
 }
 
-impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
+impl<C: Colours> FileName<'_, '_, C> {
     /// Paints the name of the file using the colours, resulting in a vector
     /// of coloured cells that can be printed to the terminal.
     ///

+ 1 - 1
src/output/grid.rs

@@ -38,7 +38,7 @@ pub struct Render<'a> {
     pub filter: &'a FileFilter,
 }
 
-impl<'a> Render<'a> {
+impl Render<'_> {
     pub fn render<W: Write>(mut self, w: &mut W) -> io::Result<()> {
         self.filter.sort_files(&mut self.files);
 

+ 2 - 2
src/output/render/permissions.rs

@@ -36,7 +36,7 @@ impl PermissionsPlusRender for Option<f::PermissionsPlus> {
                 contents: chars.into(),
             }
         } else {
-            let chars: Vec<_> = iter::repeat(colours.dash().paint("-")).take(10).collect();
+            let chars: Vec<_> = iter::repeat_n(colours.dash().paint("-"), 10).collect();
             TextCell {
                 width: DisplayWidth::from(chars.len()),
                 contents: chars.into(),
@@ -93,7 +93,7 @@ impl RenderPermissions for Option<f::Permissions> {
                     p.other_execute_bit(colours),
                 ]
             }
-            None => iter::repeat(colours.dash().paint("-")).take(9).collect(),
+            None => iter::repeat_n(colours.dash().paint("-"), 9).collect(),
         }
     }
 }

+ 1 - 1
src/output/table.rs

@@ -436,7 +436,7 @@ impl<'a> Table<'a> {
         let widths = TableWidths::zero(columns.len());
         let env = &*ENVIRONMENT;
 
-        debug!("Creating table with columns: {:?}", columns);
+        debug!("Creating table with columns: {columns:?}");
 
         Table {
             theme,

+ 1 - 1
src/theme/lsc.rs

@@ -100,7 +100,7 @@ pub struct Pair<'var> {
     pub value: &'var str,
 }
 
-impl<'var> Pair<'var> {
+impl Pair<'_> {
     pub fn to_style(&self) -> Style {
         let mut style = Style::default();
         let mut iter = self.value.split(';').peekable();

+ 2 - 2
src/theme/mod.rs

@@ -75,7 +75,7 @@ impl Options {
             let ui = UiStyles::plain();
             let exts = Box::new(NoFileStyle);
             return Theme { ui, exts };
-        };
+        }
 
         #[cfg(windows)]
         if nu_ansi_term::enable_ansi_support().is_err() {
@@ -166,7 +166,7 @@ impl Definitions {
                             warn!("Couldn't parse glob pattern {:?}: {}", pair.key, e);
                         }
                     }
-                };
+                }
             });
         }
 

+ 4 - 4
src/theme/ui_styles.rs

@@ -511,8 +511,8 @@ impl UiStyles {
     /// Sets a value on this set of colours using one of the keys understood
     /// by the `LS_COLORS` environment variable. Invalid keys set nothing, but
     /// return false.
+    #[rustfmt::skip]
     pub fn set_ls(&mut self, pair: &Pair<'_>) -> bool {
-        #[rustfmt::skip]
         match pair.key {
             "di" => self.filekinds().directory    = Some(pair.to_style()),  // DIR
             "ex" => self.filekinds().executable   = Some(pair.to_style()),  // EXEC
@@ -527,7 +527,7 @@ impl UiStyles {
              // Codes we don’t do anything with:
              // MULTIHARDLINK, DOOR, SETUID, SETGID, CAPABILITY,
              // STICKY_OTHER_WRITABLE, OTHER_WRITABLE, STICKY, MISSING
-        };
+        }
         true
     }
 
@@ -535,8 +535,8 @@ impl UiStyles {
     /// by the `EZA_COLORS` environment variable. Invalid keys set nothing,
     /// but return false. This doesn’t take the `LS_COLORS` keys into account,
     /// so `set_ls` should have been run first.
+    #[rustfmt::skip]
     pub fn set_exa(&mut self, pair: &Pair<'_>) -> bool {
-        #[rustfmt::skip]
         match pair.key {
             "ur" => self.perms().user_read                = Some(pair.to_style()),
             "uw" => self.perms().user_write               = Some(pair.to_style()),
@@ -622,7 +622,7 @@ impl UiStyles {
             "Sl" => self.security_context().selinux().range = Some(pair.to_style()),
 
              _   => return false,
-        };
+        }
 
         true
     }