From 8771861b0cb118bb15b0e2b45faef2115778686c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 27 Jul 2024 19:49:58 -0400 Subject: [PATCH] Remove unnecessary lifetime parameter from Dependencies --- src/find/matchers/mod.rs | 4 ++-- src/find/mod.rs | 26 +++++++++++++------------- tests/common/test_helpers.rs | 10 +++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index bcee1c2..8e7d5cf 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -72,11 +72,11 @@ use super::{Config, Dependencies}; pub struct MatcherIO<'a> { should_skip_dir: bool, quit: bool, - deps: &'a dyn Dependencies<'a>, + deps: &'a dyn Dependencies, } impl<'a> MatcherIO<'a> { - pub fn new(deps: &'a dyn Dependencies<'a>) -> MatcherIO<'a> { + pub fn new(deps: &dyn Dependencies) -> MatcherIO<'_> { MatcherIO { deps, should_skip_dir: false, diff --git a/src/find/mod.rs b/src/find/mod.rs index 8e777f8..738562d 100644 --- a/src/find/mod.rs +++ b/src/find/mod.rs @@ -46,9 +46,9 @@ impl Default for Config { /// Trait that encapsulates various dependencies (output, clocks, etc.) that we /// might want to fake out for unit tests. -pub trait Dependencies<'a> { - fn get_output(&'a self) -> &'a RefCell; - fn now(&'a self) -> SystemTime; +pub trait Dependencies { + fn get_output(&self) -> &RefCell; + fn now(&self) -> SystemTime; } /// Struct that holds the dependencies we use when run as the real executable. @@ -73,12 +73,12 @@ impl Default for StandardDependencies { } } -impl<'a> Dependencies<'a> for StandardDependencies { - fn get_output(&'a self) -> &'a RefCell { +impl Dependencies for StandardDependencies { + fn get_output(&self) -> &RefCell { self.output.as_ref() } - fn now(&'a self) -> SystemTime { + fn now(&self) -> SystemTime { self.now } } @@ -135,10 +135,10 @@ fn parse_args(args: &[&str]) -> Result> { }) } -fn process_dir<'a>( +fn process_dir( dir: &str, config: &Config, - deps: &'a dyn Dependencies<'a>, + deps: &dyn Dependencies, matcher: &dyn matchers::Matcher, quit: &mut bool, ) -> u64 { @@ -180,7 +180,7 @@ fn process_dir<'a>( found_count } -fn do_find<'a>(args: &[&str], deps: &'a dyn Dependencies<'a>) -> Result> { +fn do_find(args: &[&str], deps: &dyn Dependencies) -> Result> { let paths_and_matcher = parse_args(args)?; if paths_and_matcher.config.help_requested { print_help(); @@ -263,7 +263,7 @@ fn print_version() { /// All main has to do is pass in the command-line args and exit the process /// with the exit code. Note that the first string in args is expected to be /// the name of the executable. -pub fn find_main<'a>(args: &[&str], deps: &'a dyn Dependencies<'a>) -> i32 { +pub fn find_main(args: &[&str], deps: &dyn Dependencies) -> i32 { match do_find(&args[1..], deps) { Ok(_) => uucore::error::get_exit_code(), Err(e) => { @@ -336,12 +336,12 @@ mod tests { } } - impl<'a> Dependencies<'a> for FakeDependencies { - fn get_output(&'a self) -> &'a RefCell { + impl Dependencies for FakeDependencies { + fn get_output(&self) -> &RefCell { &self.output } - fn now(&'a self) -> SystemTime { + fn now(&self) -> SystemTime { self.now } } diff --git a/tests/common/test_helpers.rs b/tests/common/test_helpers.rs index 72b076e..d39d860 100644 --- a/tests/common/test_helpers.rs +++ b/tests/common/test_helpers.rs @@ -21,7 +21,7 @@ pub struct FakeDependencies { now: SystemTime, } -impl<'a> FakeDependencies { +impl FakeDependencies { pub fn new() -> Self { Self { output: RefCell::new(Cursor::new(Vec::::new())), @@ -29,7 +29,7 @@ impl<'a> FakeDependencies { } } - pub fn new_matcher_io(&'a self) -> MatcherIO<'a> { + pub fn new_matcher_io(&self) -> MatcherIO<'_> { MatcherIO::new(self) } @@ -42,12 +42,12 @@ impl<'a> FakeDependencies { } } -impl<'a> Dependencies<'a> for FakeDependencies { - fn get_output(&'a self) -> &'a RefCell { +impl Dependencies for FakeDependencies { + fn get_output(&self) -> &RefCell { &self.output } - fn now(&'a self) -> SystemTime { + fn now(&self) -> SystemTime { self.now } }