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

Various Clippy fixes #143

Merged
merged 4 commits into from
Feb 5, 2022
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/find/matchers/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use super::{Matcher, MatcherIO};
pub struct DeleteMatcher;

impl DeleteMatcher {
pub fn new() -> DeleteMatcher {
pub fn new() -> Self {
DeleteMatcher
}

pub fn new_box() -> io::Result<Box<dyn Matcher>> {
Ok(Box::new(DeleteMatcher::new()))
Ok(Box::new(Self::new()))
}

fn delete(&self, file_path: &Path, file_type: FileType) -> io::Result<()> {
Expand Down
10 changes: 3 additions & 7 deletions src/find/matchers/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl SingleExecMatcher {
executable: &str,
args: &[&str],
exec_in_parent_dir: bool,
) -> Result<SingleExecMatcher, Box<dyn Error>> {
) -> Result<Self, Box<dyn Error>> {
let transformed_args = args
.iter()
.map(|&a| match a {
Expand All @@ -38,7 +38,7 @@ impl SingleExecMatcher {
})
.collect();

Ok(SingleExecMatcher {
Ok(Self {
executable: executable.to_string(),
args: transformed_args,
exec_in_parent_dir,
Expand All @@ -50,11 +50,7 @@ impl SingleExecMatcher {
args: &[&str],
exec_in_parent_dir: bool,
) -> Result<Box<dyn Matcher>, Box<dyn Error>> {
Ok(Box::new(SingleExecMatcher::new(
executable,
args,
exec_in_parent_dir,
)?))
Ok(Box::new(Self::new(executable, args, exec_in_parent_dir)?))
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/find/matchers/logical_matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct AndMatcher {
}

impl AndMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> AndMatcher {
AndMatcher { submatchers }
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> Self {
Self { submatchers }
}
}

Expand Down Expand Up @@ -62,8 +62,8 @@ pub struct AndMatcherBuilder {
}

impl AndMatcherBuilder {
pub fn new() -> AndMatcherBuilder {
AndMatcherBuilder {
pub fn new() -> Self {
Self {
submatchers: Vec::new(),
}
}
Expand Down Expand Up @@ -94,8 +94,8 @@ pub struct OrMatcher {
}

impl OrMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> OrMatcher {
OrMatcher { submatchers }
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> Self {
Self { submatchers }
}
}

Expand Down Expand Up @@ -151,8 +151,8 @@ impl OrMatcherBuilder {
Ok(())
}

pub fn new() -> OrMatcherBuilder {
let mut o = OrMatcherBuilder {
pub fn new() -> Self {
let mut o = Self {
submatchers: Vec::new(),
};
o.submatchers.push(AndMatcherBuilder::new());
Expand Down Expand Up @@ -184,8 +184,8 @@ pub struct ListMatcher {
}

impl ListMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> ListMatcher {
ListMatcher { submatchers }
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> Self {
Self { submatchers }
}
}

Expand Down Expand Up @@ -265,8 +265,8 @@ impl ListMatcherBuilder {
Ok(())
}

pub fn new() -> ListMatcherBuilder {
let mut o = ListMatcherBuilder {
pub fn new() -> Self {
let mut o = Self {
submatchers: Vec::new(),
};
o.submatchers.push(OrMatcherBuilder::new());
Expand All @@ -293,7 +293,7 @@ pub struct TrueMatcher;

impl TrueMatcher {
pub fn new_box() -> Box<dyn Matcher> {
Box::new(TrueMatcher {})
Box::new(Self {})
}
}

Expand All @@ -314,7 +314,7 @@ impl Matcher for FalseMatcher {

impl FalseMatcher {
pub fn new_box() -> Box<dyn Matcher> {
Box::new(FalseMatcher {})
Box::new(Self {})
}
}

Expand All @@ -324,12 +324,12 @@ pub struct NotMatcher {
}

impl NotMatcher {
pub fn new(submatcher: Box<dyn Matcher>) -> NotMatcher {
NotMatcher { submatcher }
pub fn new(submatcher: Box<dyn Matcher>) -> Self {
Self { submatcher }
}

pub fn new_box(submatcher: Box<dyn Matcher>) -> Box<NotMatcher> {
Box::new(NotMatcher::new(submatcher))
pub fn new_box(submatcher: Box<dyn Matcher>) -> Box<Self> {
Box::new(Self::new(submatcher))
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ mod tests {

impl HasSideEffects {
pub fn new_box() -> Box<dyn Matcher> {
Box::new(HasSideEffects {})
Box::new(Self {})
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/find/matchers/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod tests {
create_file_link();

let link_f = get_dir_entry_for("test_data/links", "link-f");
let matcher = NameMatcher::new(&"link?f", false).unwrap();
let matcher = NameMatcher::new("link?f", false).unwrap();
let deps = FakeDependencies::new();
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
}
Expand All @@ -195,7 +195,7 @@ mod tests {
create_file_link();

let link_f = get_dir_entry_for("test_data/links", "link-f");
let matcher = NameMatcher::new(&"ab?bc", true).unwrap();
let matcher = NameMatcher::new("ab?bc", true).unwrap();
let deps = FakeDependencies::new();
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
}
Expand Down Expand Up @@ -235,7 +235,7 @@ mod tests {
create_file_link();

let link_f = get_dir_entry_for("test_data/links", "link-f");
let matcher = CaselessNameMatcher::new(&"linK?f", false).unwrap();
let matcher = CaselessNameMatcher::new("linK?f", false).unwrap();
let deps = FakeDependencies::new();
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
}
Expand All @@ -245,7 +245,7 @@ mod tests {
create_file_link();

let link_f = get_dir_entry_for("test_data/links", "link-f");
let matcher = CaselessNameMatcher::new(&"AbB?c", true).unwrap();
let matcher = CaselessNameMatcher::new("AbB?c", true).unwrap();
let deps = FakeDependencies::new();
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
}
Expand Down
14 changes: 7 additions & 7 deletions src/find/matchers/perm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub enum ComparisonType {
#[cfg(unix)]
impl FromStr for ComparisonType {
type Err = Box<dyn Error>;
fn from_str(s: &str) -> Result<ComparisonType, Box<dyn Error>> {
fn from_str(s: &str) -> Result<Self, Box<dyn Error>> {
Ok(match s {
"" => ComparisonType::Exact,
"-" => ComparisonType::AtLeast,
"/" => ComparisonType::AnyOf,
"" => Self::Exact,
"-" => Self::AtLeast,
"/" => Self::AnyOf,
_ => {
return Err(From::from(format!(
"Invalid prefix {} for -perm. Only allowed \
Expand Down Expand Up @@ -270,9 +270,9 @@ pub struct PermMatcher {}

impl PermMatcher {
#[cfg(unix)]
pub fn new(pattern: &str) -> Result<PermMatcher, Box<dyn Error>> {
pub fn new(pattern: &str) -> Result<Self, Box<dyn Error>> {
let (bit_pattern, comparison_type) = parsing::parse(pattern)?;
Ok(PermMatcher {
Ok(Self {
pattern: bit_pattern,
comparison_type,
})
Expand All @@ -286,7 +286,7 @@ impl PermMatcher {
}

pub fn new_box(pattern: &str) -> Result<Box<dyn Matcher>, Box<dyn Error>> {
Ok(Box::new(PermMatcher::new(pattern)?))
Ok(Box::new(Self::new(pattern)?))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/find/matchers/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub struct Printer {
}

impl Printer {
pub fn new(delimiter: PrintDelimiter) -> Printer {
Printer { delimiter }
pub fn new(delimiter: PrintDelimiter) -> Self {
Self { delimiter }
}

pub fn new_box(delimiter: PrintDelimiter) -> Box<dyn Matcher> {
Box::new(Printer::new(delimiter))
Box::new(Self::new(delimiter))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/find/matchers/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ struct FormatString {
}

impl FormatString {
fn parse(string: &str) -> Result<FormatString, Box<dyn Error>> {
fn parse(string: &str) -> Result<Self, Box<dyn Error>> {
FormatStringParser { string }.parse()
}
}
Expand Down Expand Up @@ -600,14 +600,14 @@ pub struct Printf {
}

impl Printf {
pub fn new(format: &str) -> Result<Printf, Box<dyn Error>> {
Ok(Printf {
pub fn new(format: &str) -> Result<Self, Box<dyn Error>> {
Ok(Self {
format: FormatString::parse(format)?,
})
}

pub fn new_box(format: &str) -> Result<Box<dyn Matcher>, Box<dyn Error>> {
Ok(Box::new(Printf::new(format)?))
Ok(Box::new(Self::new(format)?))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/find/matchers/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use super::{Matcher, MatcherIO};
pub struct PruneMatcher;

impl PruneMatcher {
pub fn new() -> PruneMatcher {
PruneMatcher {}
pub fn new() -> Self {
Self {}
}

pub fn new_box() -> Box<dyn Matcher> {
Box::new(PruneMatcher::new())
Box::new(Self::new())
}
}

Expand Down
30 changes: 13 additions & 17 deletions src/find/matchers/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub enum RegexType {
}

impl RegexType {
pub const VALUES: &'static [RegexType] = &[
RegexType::Emacs,
RegexType::Grep,
RegexType::PosixBasic,
RegexType::PosixExtended,
pub const VALUES: &'static [Self] = &[
Self::Emacs,
Self::Grep,
Self::PosixBasic,
Self::PosixExtended,
];
}

Expand All @@ -63,18 +63,18 @@ impl FromStr for RegexType {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"emacs" => Ok(RegexType::Emacs),
"grep" => Ok(RegexType::Grep),
"posix-basic" => Ok(RegexType::PosixBasic),
"posix-extended" => Ok(RegexType::PosixExtended),
"emacs" => Ok(Self::Emacs),
"grep" => Ok(Self::Grep),
"posix-basic" => Ok(Self::PosixBasic),
"posix-extended" => Ok(Self::PosixExtended),
_ => Err(ParseRegexTypeError(s.to_owned())),
}
}
}

impl Default for RegexType {
fn default() -> Self {
RegexType::Emacs
Self::Emacs
}
}

Expand All @@ -87,7 +87,7 @@ impl RegexMatcher {
regex_type: RegexType,
pattern: &str,
ignore_case: bool,
) -> Result<RegexMatcher, Box<dyn Error>> {
) -> Result<Self, Box<dyn Error>> {
let syntax = match regex_type {
RegexType::Emacs => Syntax::emacs(),
RegexType::Grep => Syntax::grep(),
Expand All @@ -104,19 +104,15 @@ impl RegexMatcher {
},
syntax,
)?;
Ok(RegexMatcher { regex })
Ok(Self { regex })
}

pub fn new_box(
regex_type: RegexType,
pattern: &str,
ignore_case: bool,
) -> Result<Box<dyn Matcher>, Box<dyn Error>> {
Ok(Box::new(RegexMatcher::new(
regex_type,
pattern,
ignore_case,
)?))
Ok(Box::new(Self::new(regex_type, pattern, ignore_case)?))
}
}

Expand Down
Loading