diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a98a2f56..f75882d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: include: - build: pinned os: ubuntu-latest - rust: 1.70.0 + rust: 1.72.1 - build: stable os: ubuntu-latest rust: stable diff --git a/Cargo.toml b/Cargo.toml index fa697a22..3a905569 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,8 @@ exclude = [ ] build = "build.rs" autotests = false -edition = "2018" -rust-version = "1.70" +edition = "2021" +rust-version = "1.72" [[bin]] bench = false diff --git a/crates/core/args.rs b/crates/core/args.rs index b4d2997b..0da9f00f 100644 --- a/crates/core/args.rs +++ b/crates/core/args.rs @@ -1,49 +1,52 @@ -use std::cmp; -use std::env; -use std::ffi::{OsStr, OsString}; -use std::fs; -use std::io::{self, IsTerminal, Write}; -use std::path::{Path, PathBuf}; -use std::process; -use std::str::FromStr; -use std::sync::Arc; -use std::time::SystemTime; +use std::{ + env, + ffi::{OsStr, OsString}, + io::{self, IsTerminal, Write}, + path::{Path, PathBuf}, + sync::Arc, +}; + +use { + clap, + grep::{ + cli, + matcher::LineTerminator, + printer::{ + default_color_specs, ColorSpecs, HyperlinkConfig, + HyperlinkEnvironment, HyperlinkFormat, JSONBuilder, PathPrinter, + PathPrinterBuilder, Standard, StandardBuilder, Stats, Summary, + SummaryBuilder, SummaryKind, JSON, + }, + regex::{ + RegexMatcher as RustRegexMatcher, + RegexMatcherBuilder as RustRegexMatcherBuilder, + }, + searcher::{ + BinaryDetection, Encoding, MmapChoice, Searcher, SearcherBuilder, + }, + }, + ignore::{ + overrides::{Override, OverrideBuilder}, + types::{FileTypeDef, Types, TypesBuilder}, + {Walk, WalkBuilder, WalkParallel}, + }, + termcolor::{BufferWriter, ColorChoice, WriteColor}, +}; -use clap; -use grep::cli; -use grep::matcher::LineTerminator; #[cfg(feature = "pcre2")] use grep::pcre2::{ RegexMatcher as PCRE2RegexMatcher, RegexMatcherBuilder as PCRE2RegexMatcherBuilder, }; -use grep::printer::{ - default_color_specs, ColorSpecs, HyperlinkConfig, HyperlinkEnvironment, - HyperlinkFormat, JSONBuilder, PathPrinter, PathPrinterBuilder, Standard, - StandardBuilder, Stats, Summary, SummaryBuilder, SummaryKind, JSON, -}; -use grep::regex::{ - RegexMatcher as RustRegexMatcher, - RegexMatcherBuilder as RustRegexMatcherBuilder, -}; -use grep::searcher::{ - BinaryDetection, Encoding, MmapChoice, Searcher, SearcherBuilder, -}; -use ignore::overrides::{Override, OverrideBuilder}; -use ignore::types::{FileTypeDef, Types, TypesBuilder}; -use ignore::{Walk, WalkBuilder, WalkParallel}; -use log; -use termcolor::{BufferWriter, ColorChoice, WriteColor}; -use crate::app; -use crate::config; -use crate::logger::Logger; -use crate::messages::{set_ignore_messages, set_messages}; -use crate::search::{ - PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder, +use crate::{ + app, config, + logger::Logger, + messages::{set_ignore_messages, set_messages}, + search::{PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder}, + subject::{Subject, SubjectBuilder}, + Result, }; -use crate::subject::{Subject, SubjectBuilder}; -use crate::Result; /// The command that ripgrep should execute based on the command line /// configuration. @@ -1130,16 +1133,17 @@ impl ArgMatches { let mut env = HyperlinkEnvironment::new(); env.host(hostname(self.value_of_os("hostname-bin"))) .wsl_prefix(wsl_prefix()); - let fmt = match self.value_of_lossy("hyperlink-format") { - None => HyperlinkFormat::from_str("default").unwrap(), - Some(format) => match HyperlinkFormat::from_str(&format) { - Ok(format) => format, - Err(err) => { - let msg = format!("invalid hyperlink format: {err}"); - return Err(msg.into()); - } - }, - }; + let fmt: HyperlinkFormat = + match self.value_of_lossy("hyperlink-format") { + None => "default".parse().unwrap(), + Some(format) => match format.parse() { + Ok(format) => format, + Err(err) => { + let msg = format!("invalid hyperlink format: {err}"); + return Err(msg.into()); + } + }, + }; log::debug!("hyperlink format: {:?}", fmt.to_string()); Ok(HyperlinkConfig::new(env, fmt)) } @@ -1589,7 +1593,7 @@ impl ArgMatches { let threads = self.usize_of("threads")?.unwrap_or(0); let available = std::thread::available_parallelism().map_or(1, |n| n.get()); - Ok(if threads == 0 { cmp::min(12, available) } else { threads }) + Ok(if threads == 0 { std::cmp::min(12, available) } else { threads }) } /// Builds a file type matcher from the command line flags. @@ -1790,11 +1794,11 @@ fn sort_by_option( p1: &Option, p2: &Option, reverse: bool, -) -> cmp::Ordering { +) -> std::cmp::Ordering { match (p1, p2, reverse) { (Some(p1), Some(p2), true) => p1.cmp(&p2).reverse(), (Some(p1), Some(p2), false) => p1.cmp(&p2), - _ => cmp::Ordering::Equal, + _ => std::cmp::Ordering::Equal, } } @@ -1823,7 +1827,7 @@ where // (This is the point of this helper function. clap's functionality for // doing this will panic on a broken pipe error.) let _ = write!(io::stdout(), "{}", err); - process::exit(0); + std::process::exit(0); } /// Attempts to discover the current working directory. This mostly just defers @@ -1871,8 +1875,8 @@ fn hostname(bin: Option<&OsStr>) -> Option { return platform_hostname(); } }; - let mut cmd = process::Command::new(&bin); - cmd.stdin(process::Stdio::null()); + let mut cmd = std::process::Command::new(&bin); + cmd.stdin(std::process::Stdio::null()); let rdr = match grep::cli::CommandReader::new(&mut cmd) { Ok(rdr) => rdr, Err(err) => { @@ -1955,9 +1959,9 @@ fn wsl_prefix() -> Option { fn load_timestamps( subjects: impl Iterator, get_time: G, -) -> Vec<(Option, Subject)> +) -> Vec<(Option, Subject)> where - G: Fn(&fs::Metadata) -> io::Result, + G: Fn(&std::fs::Metadata) -> io::Result, { subjects .map(|s| (s.path().metadata().and_then(|m| get_time(&m)).ok(), s)) diff --git a/crates/core/config.rs b/crates/core/config.rs index f55c1cae..a0b3e9b3 100644 --- a/crates/core/config.rs +++ b/crates/core/config.rs @@ -2,21 +2,16 @@ // primary output of these routines is a sequence of arguments, where each // argument corresponds precisely to one shell argument. -use std::env; -use std::error::Error; -use std::ffi::OsString; -use std::fs::File; -use std::io; -use std::path::{Path, PathBuf}; +use std::{ + ffi::OsString, + path::{Path, PathBuf}, +}; use bstr::{io::BufReadExt, ByteSlice}; -use log; - -use crate::Result; /// Return a sequence of arguments derived from ripgrep rc configuration files. pub fn args() -> Vec { - let config_path = match env::var_os("RIPGREP_CONFIG_PATH") { + let config_path = match std::env::var_os("RIPGREP_CONFIG_PATH") { None => return vec![], Some(config_path) => { if config_path.is_empty() { @@ -58,9 +53,9 @@ pub fn args() -> Vec { /// for each line in addition to successfully parsed arguments. fn parse>( path: P, -) -> Result<(Vec, Vec>)> { +) -> crate::Result<(Vec, Vec>)> { let path = path.as_ref(); - match File::open(&path) { + match std::fs::File::open(&path) { Ok(file) => parse_reader(file), Err(err) => Err(From::from(format!("{}: {}", path.display(), err))), } @@ -77,10 +72,10 @@ fn parse>( /// If the reader could not be read, then an error is returned. If there was a /// problem parsing one or more lines, then errors are returned for each line /// in addition to successfully parsed arguments. -fn parse_reader( +fn parse_reader( rdr: R, -) -> Result<(Vec, Vec>)> { - let mut bufrdr = io::BufReader::new(rdr); +) -> crate::Result<(Vec, Vec>)> { + let mut bufrdr = std::io::BufReader::new(rdr); let (mut args, mut errs) = (vec![], vec![]); let mut line_number = 0; bufrdr.for_byte_line_with_terminator(|line| { diff --git a/crates/core/main.rs b/crates/core/main.rs index 5088cf08..8cb49435 100644 --- a/crates/core/main.rs +++ b/crates/core/main.rs @@ -1,13 +1,11 @@ -use std::error; -use std::io::{self, Write}; -use std::process; -use std::sync::Mutex; -use std::time::Instant; +use std::{ + io::{self, Write}, + time::Instant, +}; use ignore::WalkState; -use args::Args; -use subject::Subject; +use crate::{args::Args, subject::Subject}; #[macro_use] mod messages; @@ -42,12 +40,12 @@ mod subject; #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -type Result = ::std::result::Result>; +type Result = std::result::Result>; fn main() { if let Err(err) = Args::parse().and_then(try_main) { eprintln_locked!("{}", err); - process::exit(2); + std::process::exit(2); } } @@ -64,11 +62,11 @@ fn try_main(args: Args) -> Result<()> { PCRE2Version => pcre2_version(&args), }?; if matched && (args.quiet() || !messages::errored()) { - process::exit(0) + std::process::exit(0) } else if messages::errored() { - process::exit(2) + std::process::exit(2) } else { - process::exit(1) + std::process::exit(1) } } @@ -148,7 +146,7 @@ fn search_parallel(args: &Args) -> Result { let started_at = Instant::now(); let subject_builder = args.subject_builder(); let bufwtr = args.buffer_writer()?; - let stats = args.stats()?.map(Mutex::new); + let stats = args.stats()?.map(std::sync::Mutex::new); let matched = AtomicBool::new(false); let searched = AtomicBool::new(false); let mut searcher_err = None; diff --git a/crates/core/search.rs b/crates/core/search.rs index 6dc51cfe..23d9ed2f 100644 --- a/crates/core/search.rs +++ b/crates/core/search.rs @@ -1,20 +1,24 @@ -use std::fs::File; -use std::io; -use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; -use std::time::Duration; +use std::{ + io, + path::{Path, PathBuf}, + time::Duration, +}; + +use { + grep::{ + cli, + matcher::Matcher, + printer::{Standard, Stats, Summary, JSON}, + regex::RegexMatcher as RustRegexMatcher, + searcher::{BinaryDetection, Searcher}, + }, + ignore::overrides::Override, + serde_json::{self as json, json}, + termcolor::WriteColor, +}; -use grep::cli; -use grep::matcher::Matcher; #[cfg(feature = "pcre2")] use grep::pcre2::RegexMatcher as PCRE2RegexMatcher; -use grep::printer::{Standard, Stats, Summary, JSON}; -use grep::regex::RegexMatcher as RustRegexMatcher; -use grep::searcher::{BinaryDetection, Searcher}; -use ignore::overrides::Override; -use serde_json as json; -use serde_json::json; -use termcolor::WriteColor; use crate::subject::Subject; @@ -396,8 +400,9 @@ impl SearchWorker { path: &Path, ) -> io::Result { let bin = self.config.preprocessor.as_ref().unwrap(); - let mut cmd = Command::new(bin); - cmd.arg(path).stdin(Stdio::from(File::open(path)?)); + let mut cmd = std::process::Command::new(bin); + cmd.arg(path) + .stdin(std::process::Stdio::from(std::fs::File::open(path)?)); let mut rdr = self.command_builder.build(&mut cmd).map_err(|err| { io::Error::new( diff --git a/crates/core/subject.rs b/crates/core/subject.rs index 06511c5d..07715521 100644 --- a/crates/core/subject.rs +++ b/crates/core/subject.rs @@ -1,8 +1,5 @@ use std::path::Path; -use ignore::{self, DirEntry}; -use log; - /// A configuration for describing how subjects should be built. #[derive(Clone, Debug)] struct Config { @@ -34,7 +31,7 @@ impl SubjectBuilder { /// deemed searchable, then it is returned. pub fn build_from_result( &self, - result: Result, + result: Result, ) -> Option { match result { Ok(dent) => self.build(dent), @@ -49,7 +46,7 @@ impl SubjectBuilder { /// /// If a subject could not be created or should otherwise not be searched, /// then this returns `None` after emitting any relevant log messages. - pub fn build(&self, dent: DirEntry) -> Option { + pub fn build(&self, dent: ignore::DirEntry) -> Option { let subj = Subject { dent, strip_dot_prefix: self.config.strip_dot_prefix }; if let Some(ignore_err) = subj.dent.error() { @@ -96,7 +93,7 @@ impl SubjectBuilder { /// file or stdin. #[derive(Clone, Debug)] pub struct Subject { - dent: DirEntry, + dent: ignore::DirEntry, strip_dot_prefix: bool, }