From 7b9972c30876797103d6b51c14dd8f9bf1001c92 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 16 Jun 2019 18:37:51 -0400 Subject: [PATCH] style: fix deprecations Use `dyn` for trait objects and use `..=` for inclusive ranges. --- grep-cli/src/escape.rs | 6 +++--- grep-matcher/src/interpolate.rs | 2 +- grep-searcher/src/sink.rs | 7 ++++--- ignore/src/walk.rs | 8 ++++---- src/config.rs | 4 ++-- src/main.rs | 3 ++- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/grep-cli/src/escape.rs b/grep-cli/src/escape.rs index 7ea96788..6b4d2d3c 100644 --- a/grep-cli/src/escape.rs +++ b/grep-cli/src/escape.rs @@ -111,7 +111,7 @@ pub fn unescape(s: &str) -> Vec { } HexFirst => { match c { - '0'...'9' | 'A'...'F' | 'a'...'f' => { + '0'..='9' | 'A'..='F' | 'a'..='f' => { state = HexSecond(c); } c => { @@ -122,7 +122,7 @@ pub fn unescape(s: &str) -> Vec { } HexSecond(first) => { match c { - '0'...'9' | 'A'...'F' | 'a'...'f' => { + '0'..='9' | 'A'..='F' | 'a'..='f' => { let ordinal = format!("{}{}", first, c); let byte = u8::from_str_radix(&ordinal, 16).unwrap(); 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. fn escape_byte(byte: u8, into: &mut String) { 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'\r' => into.push_str(r"\r"), b'\t' => into.push_str(r"\t"), diff --git a/grep-matcher/src/interpolate.rs b/grep-matcher/src/interpolate.rs index 168dd343..445518de 100644 --- a/grep-matcher/src/interpolate.rs +++ b/grep-matcher/src/interpolate.rs @@ -134,7 +134,7 @@ fn find_cap_ref(replacement: &[u8]) -> Option { /// Returns true if and only if the given byte is allowed in a capture name. fn is_valid_cap_letter(b: &u8) -> bool { 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, } } diff --git a/grep-searcher/src/sink.rs b/grep-searcher/src/sink.rs index 63a8ae24..74fba00b 100644 --- a/grep-searcher/src/sink.rs +++ b/grep-searcher/src/sink.rs @@ -1,3 +1,4 @@ +use std::error; use std::fmt; use std::io; @@ -49,9 +50,9 @@ impl SinkError for io::Error { /// A `Box` can be used as an error for `Sink` /// implementations out of the box. -impl SinkError for Box<::std::error::Error> { - fn error_message(message: T) -> Box<::std::error::Error> { - Box::<::std::error::Error>::from(message.to_string()) +impl SinkError for Box { + fn error_message(message: T) -> Box { + Box::::from(message.to_string()) } } diff --git a/ignore/src/walk.rs b/ignore/src/walk.rs index 72459220..57f795c1 100644 --- a/ignore/src/walk.rs +++ b/ignore/src/walk.rs @@ -481,8 +481,8 @@ pub struct WalkBuilder { #[derive(Clone)] enum Sorter { - ByName(Arc cmp::Ordering + Send + Sync + 'static>), - ByPath(Arc cmp::Ordering + Send + Sync + 'static>), + ByName(Arc cmp::Ordering + Send + Sync + 'static>), + ByPath(Arc cmp::Ordering + Send + Sync + 'static>), } impl fmt::Debug for WalkBuilder { @@ -1075,7 +1075,7 @@ impl WalkParallel { pub fn run( self, mut mkf: F, - ) where F: FnMut() -> Box) -> WalkState + Send + 'static> { + ) where F: FnMut() -> Box) -> WalkState + Send + 'static> { let mut f = mkf(); let threads = self.threads(); // 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. struct Worker { /// The caller's callback. - f: Box) -> WalkState + Send + 'static>, + f: Box) -> WalkState + Send + 'static>, /// The push side of our mpmc queue. tx: channel::Sender, /// The receive side of our mpmc queue. diff --git a/src/config.rs b/src/config.rs index a5e492ec..f0f7929c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -55,7 +55,7 @@ pub fn args() -> Vec { /// for each line in addition to successfully parsed arguments. fn parse>( path: P, -) -> Result<(Vec, Vec>)> { +) -> Result<(Vec, Vec>)> { let path = path.as_ref(); match File::open(&path) { Ok(file) => parse_reader(file), @@ -76,7 +76,7 @@ fn parse>( /// in addition to successfully parsed arguments. fn parse_reader( rdr: R, -) -> Result<(Vec, Vec>)> { +) -> Result<(Vec, Vec>)> { let bufrdr = io::BufReader::new(rdr); let (mut args, mut errs) = (vec![], vec![]); let mut line_number = 0; diff --git a/src/main.rs b/src/main.rs index bed33296..6c8826b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::error; use std::io::{self, Write}; use std::process; use std::sync::{Arc, Mutex}; @@ -42,7 +43,7 @@ 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) {