mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-01-19 05:49:14 +02:00
style: fix deprecations
Use `dyn` for trait objects and use `..=` for inclusive ranges.
This commit is contained in:
parent
9f000c2910
commit
7b9972c308
@ -111,7 +111,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
HexFirst => {
|
HexFirst => {
|
||||||
match c {
|
match c {
|
||||||
'0'...'9' | 'A'...'F' | 'a'...'f' => {
|
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
||||||
state = HexSecond(c);
|
state = HexSecond(c);
|
||||||
}
|
}
|
||||||
c => {
|
c => {
|
||||||
@ -122,7 +122,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
HexSecond(first) => {
|
HexSecond(first) => {
|
||||||
match c {
|
match c {
|
||||||
'0'...'9' | 'A'...'F' | 'a'...'f' => {
|
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
||||||
let ordinal = format!("{}{}", first, c);
|
let ordinal = format!("{}{}", first, c);
|
||||||
let byte = u8::from_str_radix(&ordinal, 16).unwrap();
|
let byte = u8::from_str_radix(&ordinal, 16).unwrap();
|
||||||
bytes.push(byte);
|
bytes.push(byte);
|
||||||
@ -174,7 +174,7 @@ fn escape_char(cp: char, into: &mut String) {
|
|||||||
/// Adds the given byte to the given string, escaping it if necessary.
|
/// Adds the given byte to the given string, escaping it if necessary.
|
||||||
fn escape_byte(byte: u8, into: &mut String) {
|
fn escape_byte(byte: u8, into: &mut String) {
|
||||||
match byte {
|
match byte {
|
||||||
0x21...0x5B | 0x5D...0x7D => into.push(byte as char),
|
0x21..=0x5B | 0x5D..=0x7D => into.push(byte as char),
|
||||||
b'\n' => into.push_str(r"\n"),
|
b'\n' => into.push_str(r"\n"),
|
||||||
b'\r' => into.push_str(r"\r"),
|
b'\r' => into.push_str(r"\r"),
|
||||||
b'\t' => into.push_str(r"\t"),
|
b'\t' => into.push_str(r"\t"),
|
||||||
|
@ -134,7 +134,7 @@ fn find_cap_ref(replacement: &[u8]) -> Option<CaptureRef> {
|
|||||||
/// Returns true if and only if the given byte is allowed in a capture name.
|
/// Returns true if and only if the given byte is allowed in a capture name.
|
||||||
fn is_valid_cap_letter(b: &u8) -> bool {
|
fn is_valid_cap_letter(b: &u8) -> bool {
|
||||||
match *b {
|
match *b {
|
||||||
b'0' ... b'9' | b'a' ... b'z' | b'A' ... b'Z' | b'_' => true,
|
b'0' ..= b'9' | b'a' ..= b'z' | b'A' ..= b'Z' | b'_' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
@ -49,9 +50,9 @@ impl SinkError for io::Error {
|
|||||||
|
|
||||||
/// A `Box<std::error::Error>` can be used as an error for `Sink`
|
/// A `Box<std::error::Error>` can be used as an error for `Sink`
|
||||||
/// implementations out of the box.
|
/// implementations out of the box.
|
||||||
impl SinkError for Box<::std::error::Error> {
|
impl SinkError for Box<dyn error::Error> {
|
||||||
fn error_message<T: fmt::Display>(message: T) -> Box<::std::error::Error> {
|
fn error_message<T: fmt::Display>(message: T) -> Box<dyn error::Error> {
|
||||||
Box::<::std::error::Error>::from(message.to_string())
|
Box::<dyn error::Error>::from(message.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,8 +481,8 @@ pub struct WalkBuilder {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum Sorter {
|
enum Sorter {
|
||||||
ByName(Arc<Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static>),
|
ByName(Arc<dyn Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static>),
|
||||||
ByPath(Arc<Fn(&Path, &Path) -> cmp::Ordering + Send + Sync + 'static>),
|
ByPath(Arc<dyn Fn(&Path, &Path) -> cmp::Ordering + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for WalkBuilder {
|
impl fmt::Debug for WalkBuilder {
|
||||||
@ -1075,7 +1075,7 @@ impl WalkParallel {
|
|||||||
pub fn run<F>(
|
pub fn run<F>(
|
||||||
self,
|
self,
|
||||||
mut mkf: F,
|
mut mkf: F,
|
||||||
) where F: FnMut() -> Box<FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static> {
|
) where F: FnMut() -> Box<dyn FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static> {
|
||||||
let mut f = mkf();
|
let mut f = mkf();
|
||||||
let threads = self.threads();
|
let threads = self.threads();
|
||||||
// TODO: Figure out how to use a bounded channel here. With an
|
// TODO: Figure out how to use a bounded channel here. With an
|
||||||
@ -1253,7 +1253,7 @@ impl Work {
|
|||||||
/// Note that a worker is *both* a producer and a consumer.
|
/// Note that a worker is *both* a producer and a consumer.
|
||||||
struct Worker {
|
struct Worker {
|
||||||
/// The caller's callback.
|
/// The caller's callback.
|
||||||
f: Box<FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static>,
|
f: Box<dyn FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static>,
|
||||||
/// The push side of our mpmc queue.
|
/// The push side of our mpmc queue.
|
||||||
tx: channel::Sender<Message>,
|
tx: channel::Sender<Message>,
|
||||||
/// The receive side of our mpmc queue.
|
/// The receive side of our mpmc queue.
|
||||||
|
@ -55,7 +55,7 @@ pub fn args() -> Vec<OsString> {
|
|||||||
/// for each line in addition to successfully parsed arguments.
|
/// for each line in addition to successfully parsed arguments.
|
||||||
fn parse<P: AsRef<Path>>(
|
fn parse<P: AsRef<Path>>(
|
||||||
path: P,
|
path: P,
|
||||||
) -> Result<(Vec<OsString>, Vec<Box<Error>>)> {
|
) -> Result<(Vec<OsString>, Vec<Box<dyn Error>>)> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
match File::open(&path) {
|
match File::open(&path) {
|
||||||
Ok(file) => parse_reader(file),
|
Ok(file) => parse_reader(file),
|
||||||
@ -76,7 +76,7 @@ fn parse<P: AsRef<Path>>(
|
|||||||
/// in addition to successfully parsed arguments.
|
/// in addition to successfully parsed arguments.
|
||||||
fn parse_reader<R: io::Read>(
|
fn parse_reader<R: io::Read>(
|
||||||
rdr: R,
|
rdr: R,
|
||||||
) -> Result<(Vec<OsString>, Vec<Box<Error>>)> {
|
) -> Result<(Vec<OsString>, Vec<Box<dyn Error>>)> {
|
||||||
let bufrdr = io::BufReader::new(rdr);
|
let bufrdr = io::BufReader::new(rdr);
|
||||||
let (mut args, mut errs) = (vec![], vec![]);
|
let (mut args, mut errs) = (vec![], vec![]);
|
||||||
let mut line_number = 0;
|
let mut line_number = 0;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::error;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -42,7 +43,7 @@ mod subject;
|
|||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||||
|
|
||||||
type Result<T> = ::std::result::Result<T, Box<::std::error::Error>>;
|
type Result<T> = ::std::result::Result<T, Box<dyn error::Error>>;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(err) = Args::parse().and_then(try_main) {
|
if let Err(err) = Args::parse().and_then(try_main) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user