Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade both Rust version and edition (and fix some lints) #1125

Merged
merged 18 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
rust: [1.56.1, stable, beta, nightly]
rust: [1.63.0, stable, beta, nightly]

steps:
- name: Checkout repository
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "exa"
description = "A modern replacement for ls"
authors = ["Benjamin Sago <[email protected]>"]
categories = ["command-line-utilities"]
edition = "2018"
rust-version = "1.56.1"
edition = "2021"
rust-version = "1.63.0"
exclude = ["/devtools/*", "/Justfile", "/Vagrantfile", "/screenshots.png"]
readme = "README.md"
homepage = "https://the.exa.website/"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ To build without Git support, run `cargo install --no-default-features exa` is a
<a id="development">
<h1>Development

<a href="https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html">
<img src="https://img.shields.io/badge/rustc-1.56.1+-lightgray.svg" alt="Rust 1.56.1+" />
<a href="https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html">
<img src="https://img.shields.io/badge/rustc-1.63.0+-lightgray.svg" alt="Rust 1.63.0+" />
</a>

<a href="https://github.com/ogham/exa/blob/master/LICENCE">
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() -> io::Result<()> {
let path = &out.join("version_string.txt");

// Bland version text
let mut f = File::create(path).expect(&path.to_string_lossy());
let mut f = File::create(path).unwrap_or_else(|_| { panic!("{}", path.to_string_lossy().to_string()) });
writeln!(f, "{}", strip_codes(&ver))?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.56.1"
channel = "1.63.0"
2 changes: 1 addition & 1 deletion src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'dir, 'ig> Iterator for Files<'dir, 'ig> {
/// Usually files in Unix use a leading dot to be hidden or visible, but two
/// entries in particular are “extra-hidden”: `.` and `..`, which only become
/// visible after an extra `-a` option.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum DotFilter {

/// Shows files, dotfiles, and `.` and `..`.
Expand Down
4 changes: 2 additions & 2 deletions src/fs/dir_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// into them and print out their contents. The recurse mode does this by
/// having extra output blocks at the end, while the tree mode will show
/// directories inline, with their contents immediately underneath.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum DirAction {

/// This directory should be listed along with the regular files, instead
Expand Down Expand Up @@ -58,7 +58,7 @@ impl DirAction {


/// The options that determine how to recurse into a directory.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct RecurseOptions {

/// Whether recursion should be done as a tree or as multiple individual
Expand Down
4 changes: 2 additions & 2 deletions src/fs/feature/xattr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod lister {
unsafe {
listxattr(
c_path.as_ptr(),
buf.as_mut_ptr() as *mut c_char,
buf.as_mut_ptr().cast::<c_char>(),
bufsize as size_t,
self.c_flags,
)
Expand All @@ -178,7 +178,7 @@ mod lister {
unsafe {
getxattr(
c_path.as_ptr(),
buf.as_ptr() as *const c_char,
buf.as_ptr().cast::<c_char>(),
ptr::null_mut(),
0,
0,
Expand Down
2 changes: 1 addition & 1 deletion src/fs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub struct Time {
/// A file’s status in a Git repository. Whether a file is in a repository or
/// not is handled by the Git module, rather than having a “null” variant in
/// this enum.
#[derive(PartialEq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone)]
pub enum GitStatus {

/// This file hasn’t changed since the last commit.
Expand Down
8 changes: 4 additions & 4 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ impl<'dir> File<'dir> {
path.to_path_buf()
}
else if let Some(dir) = self.parent_dir {
dir.join(&*path)
dir.join(path)
}
else if let Some(parent) = self.path.parent() {
parent.join(&*path)
parent.join(path)
}
else {
self.path.join(&*path)
self.path.join(path)
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'dir> File<'dir> {
nanosec -= 1_000_000_000;
}

let duration = Duration::new(sec.abs() as u64, nanosec.abs() as u32);
let duration = Duration::new(sec.unsigned_abs(), nanosec.unsigned_abs() as u32);
Some(UNIX_EPOCH - duration)
}
else {
Expand Down
28 changes: 14 additions & 14 deletions src/fs/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::fs::File;
/// The filter also governs sorting the list. After being filtered, pairs of
/// files are compared and sorted based on the result, with the sort field
/// performing the comparison.
#[derive(PartialEq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct FileFilter {

/// Whether directories should be listed first, and other types of file
Expand Down Expand Up @@ -89,7 +89,7 @@ impl FileFilter {
}

/// Sort the files in the given vector based on the sort field option.
pub fn sort_files<'a, F>(&self, files: &mut Vec<F>)
pub fn sort_files<'a, F>(&self, files: &mut [F])
where F: AsRef<File<'a>>
{
files.sort_by(|a, b| {
Expand All @@ -113,7 +113,7 @@ impl FileFilter {


/// User-supplied field to sort by.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SortField {

/// Don’t apply any sorting. This is usually used as an optimisation in
Expand Down Expand Up @@ -194,7 +194,7 @@ pub enum SortField {
/// lowercase letters because it takes the difference between the two cases
/// into account? I gave up and just named these two variants after the
/// effects they have.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SortCase {

/// Sort files case-sensitively with uppercase first, with ‘A’ coming
Expand Down Expand Up @@ -271,7 +271,7 @@ impl SortField {
/// The **ignore patterns** are a list of globs that are tested against
/// each filename, and if any of them match, that file isn’t displayed.
/// This lets a user hide, say, text files by ignoring `*.txt`.
#[derive(PartialEq, Default, Debug, Clone)]
#[derive(PartialEq, Eq, Default, Debug, Clone)]
pub struct IgnorePatterns {
patterns: Vec<glob::Pattern>,
}
Expand Down Expand Up @@ -327,7 +327,7 @@ impl IgnorePatterns {


/// Whether to ignore or display files that Git would ignore.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum GitIgnore {

/// Ignore files that Git would ignore.
Expand All @@ -346,31 +346,31 @@ mod test_ignores {
#[test]
fn empty_matches_nothing() {
let pats = IgnorePatterns::empty();
assert_eq!(false, pats.is_ignored("nothing"));
assert_eq!(false, pats.is_ignored("test.mp3"));
assert!(!pats.is_ignored("nothing"));
assert!(!pats.is_ignored("test.mp3"));
}

#[test]
fn ignores_a_glob() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "*.mp3" ]);
assert!(fails.is_empty());
assert_eq!(false, pats.is_ignored("nothing"));
assert_eq!(true, pats.is_ignored("test.mp3"));
assert!(!pats.is_ignored("nothing"));
assert!(pats.is_ignored("test.mp3"));
}

#[test]
fn ignores_an_exact_filename() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing" ]);
assert!(fails.is_empty());
assert_eq!(true, pats.is_ignored("nothing"));
assert_eq!(false, pats.is_ignored("test.mp3"));
assert!(pats.is_ignored("nothing"));
assert!(!pats.is_ignored("test.mp3"));
}

#[test]
fn ignores_both() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing", "*.mp3" ]);
assert!(fails.is_empty());
assert_eq!(true, pats.is_ignored("nothing"));
assert_eq!(true, pats.is_ignored("test.mp3"));
assert!(pats.is_ignored("nothing"));
assert!(pats.is_ignored("test.mp3"));
}
}
2 changes: 1 addition & 1 deletion src/info/filetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::output::icons::FileIcon;
use crate::theme::FileColours;


#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Eq)]
pub struct FileExtensions;

impl FileExtensions {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() {
}

let args: Vec<_> = env::args_os().skip(1).collect();
match Options::parse(args.iter().map(|e| e.as_ref()), &LiveVars) {
match Options::parse(args.iter().map(std::convert::AsRef::as_ref), &LiveVars) {
OptionsResult::Ok(options, mut input_paths) => {

// List the current directory by default.
Expand Down
6 changes: 3 additions & 3 deletions src/options/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::options::parser::{Arg, Flag, ParseError};


/// Something wrong with the combination of options the user has picked.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub enum OptionsError {

/// There was an error (from `getopts`) parsing the arguments.
Expand Down Expand Up @@ -44,7 +44,7 @@ pub enum OptionsError {
}

/// The source of a string that failed to be parsed as a number.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub enum NumberSource {

/// It came... from a command-line argument!
Expand Down Expand Up @@ -119,7 +119,7 @@ impl OptionsError {


/// A list of legal choices for an argument-taking option.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub struct Choices(pub &'static [&'static str]);

impl fmt::Display for Choices {
Expand Down
1 change: 0 additions & 1 deletion src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ mod test {
mod ignore_patterns {
use super::*;
use std::iter::FromIterator;
use glob;

fn pat(string: &'static str) -> glob::Pattern {
glob::Pattern::new(string).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/options/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static EXTENDED_HELP: &str = " -@, --extended list each file's extended
/// All the information needed to display the help text, which depends
/// on which features are enabled and whether the user only wants to
/// see one section’s help.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct HelpString;

impl HelpString {
Expand Down
6 changes: 3 additions & 3 deletions src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub mod test {
use crate::options::parser::{Arg, MatchedFlags};
use std::ffi::OsStr;

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub enum Strictnesses {
Last,
Complain,
Expand All @@ -228,14 +228,14 @@ pub mod test {
/// both, then both should resolve to the same result.
///
/// It returns a vector with one or two elements in.
/// These elements can then be tested with assert_eq or what have you.
/// These elements can then be tested with `assert_eq` or what have you.
pub fn parse_for_test<T, F>(inputs: &[&str], args: &'static [&'static Arg], strictnesses: Strictnesses, get: F) -> Vec<T>
where F: Fn(&MatchedFlags<'_>) -> T
{
use self::Strictnesses::*;
use crate::options::parser::{Args, Strictness};

let bits = inputs.into_iter().map(OsStr::new).collect::<Vec<_>>();
let bits = inputs.iter().map(OsStr::new).collect::<Vec<_>>();
let mut result = Vec::new();

if strictnesses == Last || strictnesses == Both {
Expand Down
18 changes: 9 additions & 9 deletions src/options/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub type Values = &'static [&'static str];

/// A **flag** is either of the two argument types, because they have to
/// be in the same array together.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Flag {
Short(ShortArg),
Long(LongArg),
Expand All @@ -77,7 +77,7 @@ impl fmt::Display for Flag {
}

/// Whether redundant arguments should be considered a problem.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Strictness {

/// Throw an error when an argument doesn’t do anything, either because
Expand All @@ -91,7 +91,7 @@ pub enum Strictness {

/// Whether a flag takes a value. This is applicable to both long and short
/// arguments.
#[derive(Copy, Clone, PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TakesValue {

/// This flag has to be followed by a value.
Expand All @@ -108,7 +108,7 @@ pub enum TakesValue {


/// An **argument** can be matched by one of the user’s input strings.
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct Arg {

/// The short argument that matches it, if any.
Expand Down Expand Up @@ -136,7 +136,7 @@ impl fmt::Display for Arg {


/// Literally just several args.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub struct Args(pub &'static [&'static Arg]);

impl Args {
Expand Down Expand Up @@ -340,7 +340,7 @@ impl Args {


/// The **matches** are the result of parsing the user’s command-line strings.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub struct Matches<'args> {

/// The flags that were parsed from the user’s input.
Expand All @@ -351,7 +351,7 @@ pub struct Matches<'args> {
pub frees: Vec<&'args OsStr>,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub struct MatchedFlags<'args> {

/// The individual flags from the user’s input, in the order they were
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a> MatchedFlags<'a> {

/// A problem with the user’s input that meant it couldn’t be parsed into a
/// coherent list of arguments.
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub enum ParseError {

/// A flag that has to take a value was not given one.
Expand Down Expand Up @@ -743,6 +743,6 @@ mod matches_test {
fn no_count() {
let flags = MatchedFlags { flags: Vec::new(), strictness: Strictness::UseLastArguments };

assert_eq!(flags.has(&COUNT).unwrap(), false);
assert!(!flags.has(&COUNT).unwrap());
}
}
Loading