diff --git a/README.md b/README.md index d442770a..a0e9b06e 100644 --- a/README.md +++ b/README.md @@ -156,9 +156,7 @@ struct MyEqMatcher { expected: T, } -impl Matcher for MyEqMatcher { - type ActualT = T; - +impl Matcher for MyEqMatcher { fn matches(&self, actual: &Self::ActualT) -> MatcherResult { (self.expected == *actual).into() } @@ -179,7 +177,7 @@ impl Matcher for MyEqMatcher { It is recommended to expose a function which constructs the matcher: ```rust -pub fn eq_my_way(expected: T) -> impl Matcher { +pub fn eq_my_way(expected: T) -> impl Matcher { MyEqMatcher { expected } } ``` diff --git a/googletest/crate_docs.md b/googletest/crate_docs.md index 98ea15a7..ee365089 100644 --- a/googletest/crate_docs.md +++ b/googletest/crate_docs.md @@ -216,10 +216,8 @@ struct MyEqMatcher { expected: T, } -impl Matcher for MyEqMatcher { - type ActualT = T; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { +impl Matcher for MyEqMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult where T: 'a{ if self.expected == *actual { MatcherResult::Match } else { @@ -250,10 +248,8 @@ impl Matcher for MyEqMatcher { # expected: T, # } # - # impl Matcher for MyEqMatcher { - # type ActualT = T; - # - # fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + # impl Matcher for MyEqMatcher { + # fn matches<'a>(&self, actual: &'a T) -> MatcherResult where T: 'a{ # if self.expected == *actual { # MatcherResult::Match # } else { @@ -273,7 +269,7 @@ impl Matcher for MyEqMatcher { # } # } # - pub fn eq_my_way(expected: T) -> impl Matcher { + pub fn eq_my_way(expected: T) -> impl Matcher { MyEqMatcher { expected } } ``` @@ -289,10 +285,8 @@ impl Matcher for MyEqMatcher { # expected: T, # } # -# impl Matcher for MyEqMatcher { -# type ActualT = T; -# -# fn matches(&self, actual: &Self::ActualT) -> MatcherResult { +# impl Matcher for MyEqMatcher { +# fn matches<'a>(&self, actual: &'a T) -> MatcherResult where T: 'a{ # if self.expected == *actual { # MatcherResult::Match # } else { @@ -312,7 +306,7 @@ impl Matcher for MyEqMatcher { # } # } # -# pub fn eq_my_way(expected: T) -> impl Matcher { +# pub fn eq_my_way(expected: T) -> impl Matcher { # MyEqMatcher { expected } # } # /* The attribute macro would prevent the function from being compiled in a doctest. diff --git a/googletest/src/assertions.rs b/googletest/src/assertions.rs index 9fd93adc..b5acafa1 100644 --- a/googletest/src/assertions.rs +++ b/googletest/src/assertions.rs @@ -499,7 +499,7 @@ pub mod internal { #[must_use = "The assertion result must be evaluated to affect the test result."] pub fn check_matcher( actual: &T, - expected: impl Matcher, + expected: impl Matcher, actual_expr: &'static str, source_location: SourceLocation, ) -> Result<(), TestAssertionFailure> { diff --git a/googletest/src/matcher.rs b/googletest/src/matcher.rs index 39842317..d62c8131 100644 --- a/googletest/src/matcher.rs +++ b/googletest/src/matcher.rs @@ -21,17 +21,16 @@ use crate::matchers::__internal_unstable_do_not_depend_on_these::DisjunctionMatc use std::fmt::Debug; /// An interface for checking an arbitrary condition on a datum. -pub trait Matcher { - /// The type against which this matcher matches. - type ActualT: Debug + ?Sized; - +pub trait Matcher { /// Returns whether the condition matches the datum `actual`. /// /// The trait implementation defines what it means to "match". Often the /// matching condition is based on data stored in the matcher. For example, /// `eq` matches when its stored expected value is equal (in the sense of /// the `==` operator) to the value `actual`. - fn matches(&self, actual: &Self::ActualT) -> MatcherResult; + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a; /// Returns a description of `self` or a negative description if /// `matcher_result` is `DoesNotMatch`. @@ -128,7 +127,10 @@ pub trait Matcher { /// format!("which points to a value {}", self.expected.explain_match(actual.deref())) /// } /// ``` - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { format!("which {}", self.describe(self.matches(actual))) } @@ -155,10 +157,7 @@ pub trait Matcher { // TODO(b/264518763): Replace the return type with impl Matcher and reduce // visibility of ConjunctionMatcher once impl in return position in trait // methods is stable. - fn and>( - self, - right: Right, - ) -> ConjunctionMatcher + fn and>(self, right: Right) -> ConjunctionMatcher where Self: Sized, { @@ -185,10 +184,7 @@ pub trait Matcher { // TODO(b/264518763): Replace the return type with impl Matcher and reduce // visibility of DisjunctionMatcher once impl in return position in trait // methods is stable. - fn or>( - self, - right: Right, - ) -> DisjunctionMatcher + fn or>(self, right: Right) -> DisjunctionMatcher where Self: Sized, { @@ -206,7 +202,7 @@ const PRETTY_PRINT_LENGTH_THRESHOLD: usize = 60; /// The parameter `actual_expr` contains the expression which was evaluated to /// obtain `actual`. pub(crate) fn create_assertion_failure( - matcher: &impl Matcher, + matcher: &impl Matcher, actual: &T, actual_expr: &'static str, source_location: SourceLocation, @@ -240,7 +236,11 @@ pub enum MatcherResult { impl From for MatcherResult { fn from(b: bool) -> Self { - if b { MatcherResult::Match } else { MatcherResult::NoMatch } + if b { + MatcherResult::Match + } else { + MatcherResult::NoMatch + } } } diff --git a/googletest/src/matcher_support/edit_distance.rs b/googletest/src/matcher_support/edit_distance.rs index 8847bc9b..6cc18c12 100644 --- a/googletest/src/matcher_support/edit_distance.rs +++ b/googletest/src/matcher_support/edit_distance.rs @@ -430,8 +430,8 @@ mod tests { } #[test] - fn returns_common_part_plus_difference_plus_common_part_when_there_is_common_prefix_and_suffix() - -> Result<()> { + fn returns_common_part_plus_difference_plus_common_part_when_there_is_common_prefix_and_suffix( + ) -> Result<()> { let result = edit_list( ["Common part (1)", "Actual only", "Common part (2)"], ["Common part (1)", "Expected only", "Common part (2)"], @@ -449,8 +449,8 @@ mod tests { } #[test] - fn returns_common_part_plus_extra_actual_plus_common_part_when_there_is_common_prefix_and_suffix() - -> Result<()> { + fn returns_common_part_plus_extra_actual_plus_common_part_when_there_is_common_prefix_and_suffix( + ) -> Result<()> { let result = edit_list( ["Common part (1)", "Actual only", "Common part (2)"], ["Common part (1)", "Common part (2)"], @@ -467,8 +467,8 @@ mod tests { } #[test] - fn returns_common_part_plus_extra_expected_plus_common_part_when_there_is_common_prefix_and_suffix() - -> Result<()> { + fn returns_common_part_plus_extra_expected_plus_common_part_when_there_is_common_prefix_and_suffix( + ) -> Result<()> { let result = edit_list( ["Common part (1)", "Common part (2)"], ["Common part (1)", "Expected only", "Common part (2)"], @@ -500,8 +500,8 @@ mod tests { } #[test] - fn does_not_skip_extra_parts_on_actual_in_prefix_mode_at_end_when_they_are_in_common() - -> Result<()> { + fn does_not_skip_extra_parts_on_actual_in_prefix_mode_at_end_when_they_are_in_common( + ) -> Result<()> { let result = edit_list( ["Actual only", "Common part"], ["Expected only", "Common part"], @@ -518,8 +518,8 @@ mod tests { } #[test] - fn does_not_skip_corresponding_line_on_actual_when_actual_and_expected_differ_in_prefix_mode() - -> Result<()> { + fn does_not_skip_corresponding_line_on_actual_when_actual_and_expected_differ_in_prefix_mode( + ) -> Result<()> { let result = edit_list(["Actual only"], ["Expected only"], Mode::Prefix); verify_that!( result, diff --git a/googletest/src/matchers/all_matcher.rs b/googletest/src/matchers/all_matcher.rs index 198f0f14..f70917ad 100644 --- a/googletest/src/matchers/all_matcher.rs +++ b/googletest/src/matchers/all_matcher.rs @@ -75,22 +75,23 @@ pub mod internal { /// For internal use only. API stablility is not guaranteed! #[doc(hidden)] pub struct AllMatcher<'a, T: Debug + ?Sized, const N: usize> { - components: [Box + 'a>; N], + components: [Box + 'a>; N], } impl<'a, T: Debug + ?Sized, const N: usize> AllMatcher<'a, T, N> { /// Constructs an [`AllMatcher`] with the given component matchers. /// /// Intended for use only by the [`all`] macro. - pub fn new(components: [Box + 'a>; N]) -> Self { + pub fn new(components: [Box + 'a>; N]) -> Self { Self { components } } } - impl<'a, T: Debug + ?Sized, const N: usize> Matcher for AllMatcher<'a, T, N> { - type ActualT = T; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + impl<'a, T: Debug + ?Sized, const N: usize> Matcher for AllMatcher<'a, T, N> { + fn matches<'b>(&self, actual: &'b T) -> MatcherResult + where + T: 'b, + { for component in &self.components { match component.matches(actual) { MatcherResult::NoMatch => { @@ -102,7 +103,10 @@ pub mod internal { MatcherResult::Match } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'b>(&self, actual: &'b T) -> String + where + T: 'b, + { match N { 0 => anything::().explain_match(actual), 1 => self.components[0].explain_match(actual), diff --git a/googletest/src/matchers/any_matcher.rs b/googletest/src/matchers/any_matcher.rs index 4d86a768..7d706e27 100644 --- a/googletest/src/matchers/any_matcher.rs +++ b/googletest/src/matchers/any_matcher.rs @@ -77,26 +77,30 @@ pub mod internal { /// For internal use only. API stablility is not guaranteed! #[doc(hidden)] pub struct AnyMatcher<'a, T: Debug + ?Sized, const N: usize> { - components: [Box + 'a>; N], + components: [Box + 'a>; N], } impl<'a, T: Debug + ?Sized, const N: usize> AnyMatcher<'a, T, N> { /// Constructs an [`AnyMatcher`] with the given component matchers. /// /// Intended for use only by the [`all`] macro. - pub fn new(components: [Box + 'a>; N]) -> Self { + pub fn new(components: [Box + 'a>; N]) -> Self { Self { components } } } - impl<'a, T: Debug + ?Sized, const N: usize> Matcher for AnyMatcher<'a, T, N> { - type ActualT = T; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + impl<'a, T: Debug + ?Sized, const N: usize> Matcher for AnyMatcher<'a, T, N> { + fn matches<'b>(&self, actual: &'b T) -> MatcherResult + where + T: 'b, + { MatcherResult::from(self.components.iter().any(|c| c.matches(actual).is_match())) } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'b>(&self, actual: &'b T) -> String + where + T: 'b, + { match N { 0 => format!("which {}", anything::().describe(MatcherResult::NoMatch)), 1 => self.components[0].explain_match(actual), diff --git a/googletest/src/matchers/anything_matcher.rs b/googletest/src/matchers/anything_matcher.rs index 82de4607..2550d5be 100644 --- a/googletest/src/matchers/anything_matcher.rs +++ b/googletest/src/matchers/anything_matcher.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::matcher::{Matcher, MatcherResult}; -use std::{fmt::Debug, marker::PhantomData}; +use std::fmt::Debug; /// Matches anything. This matcher always succeeds. /// @@ -29,16 +29,17 @@ use std::{fmt::Debug, marker::PhantomData}; /// # } /// # should_pass().unwrap(); /// ``` -pub fn anything() -> impl Matcher { - Anything::(Default::default()) +pub fn anything() -> impl Matcher { + Anything } -struct Anything(PhantomData); +struct Anything; -impl Matcher for Anything { - type ActualT = T; - - fn matches(&self, _: &T) -> MatcherResult { +impl Matcher for Anything { + fn matches<'a>(&self, _: &'a T) -> MatcherResult + where + T: 'a, + { MatcherResult::Match } diff --git a/googletest/src/matchers/char_count_matcher.rs b/googletest/src/matchers/char_count_matcher.rs index a7765b4a..c65f4d92 100644 --- a/googletest/src/matchers/char_count_matcher.rs +++ b/googletest/src/matchers/char_count_matcher.rs @@ -53,9 +53,9 @@ use std::{fmt::Debug, marker::PhantomData}; /// # } /// # should_pass().unwrap(); /// ``` -pub fn char_count, E: Matcher>( +pub fn char_count, E: Matcher>( expected: E, -) -> impl Matcher { +) -> impl Matcher { CharLenMatcher { expected, phantom: Default::default() } } @@ -64,10 +64,11 @@ struct CharLenMatcher { phantom: PhantomData, } -impl, E: Matcher> Matcher for CharLenMatcher { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { +impl, E: Matcher> Matcher for CharLenMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { self.expected.matches(&actual.as_ref().chars().count()) } @@ -88,7 +89,10 @@ impl, E: Matcher> Matcher for Ch } } - fn explain_match(&self, actual: &T) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { let actual_size = actual.as_ref().chars().count(); format!( "which has character count {}, {}", @@ -128,10 +132,11 @@ mod tests { #[test] fn char_count_explains_match() -> Result<()> { struct TestMatcher(PhantomData); - impl Matcher for TestMatcher { - type ActualT = T; - - fn matches(&self, _: &T) -> MatcherResult { + impl Matcher for TestMatcher { + fn matches<'a>(&self, _: &'a T) -> MatcherResult + where + T: 'a, + { false.into() } @@ -139,7 +144,10 @@ mod tests { "called described".into() } - fn explain_match(&self, _: &T) -> String { + fn explain_match<'a>(&self, _: &'a T) -> String + where + T: 'a, + { "called explain_match".into() } } diff --git a/googletest/src/matchers/conjunction_matcher.rs b/googletest/src/matchers/conjunction_matcher.rs index 1ba59c30..c20b06a3 100644 --- a/googletest/src/matchers/conjunction_matcher.rs +++ b/googletest/src/matchers/conjunction_matcher.rs @@ -33,20 +33,21 @@ impl ConjunctionMatcher { } } -impl> Matcher for ConjunctionMatcher -where - M1::ActualT: Debug, -{ - type ActualT = M1::ActualT; - - fn matches(&self, actual: &M1::ActualT) -> MatcherResult { +impl, M2: Matcher> Matcher for ConjunctionMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { match (self.m1.matches(actual), self.m2.matches(actual)) { (MatcherResult::Match, MatcherResult::Match) => MatcherResult::Match, _ => MatcherResult::NoMatch, } } - fn explain_match(&self, actual: &M1::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { match (self.m1.matches(actual), self.m2.matches(actual)) { (MatcherResult::Match, MatcherResult::Match) => { format!( diff --git a/googletest/src/matchers/container_eq_matcher.rs b/googletest/src/matchers/container_eq_matcher.rs index 15832f27..2c9a9834 100644 --- a/googletest/src/matchers/container_eq_matcher.rs +++ b/googletest/src/matchers/container_eq_matcher.rs @@ -103,8 +103,8 @@ pub struct ContainerEqMatcher { phantom: PhantomData, } -impl Matcher - for ContainerEqMatcher +impl + Matcher for ContainerEqMatcher where ActualElementT: PartialEq + Debug + ?Sized, ActualContainerT: PartialEq + Debug + ?Sized, @@ -113,13 +113,17 @@ where for<'a> &'a ActualContainerT: IntoIterator, for<'a> &'a ExpectedContainerT: IntoIterator, { - type ActualT = ActualContainerT; - - fn matches(&self, actual: &ActualContainerT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualContainerT) -> MatcherResult + where + ActualContainerT: 'a, + { (*actual == self.expected).into() } - fn explain_match(&self, actual: &ActualContainerT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualContainerT) -> String + where + ActualContainerT: 'a, + { build_explanation(self.get_missing_items(actual), self.get_unexpected_items(actual)) } @@ -270,15 +274,15 @@ mod tests { } #[test] - fn container_eq_matches_owned_vec_of_owned_strings_with_slice_of_string_references() - -> Result<()> { + fn container_eq_matches_owned_vec_of_owned_strings_with_slice_of_string_references( + ) -> Result<()> { let vector = vec!["A string".to_string(), "Another string".to_string()]; verify_that!(vector, container_eq(["A string", "Another string"])) } #[test] - fn container_eq_matches_owned_vec_of_owned_strings_with_shorter_slice_of_string_references() - -> Result<()> { + fn container_eq_matches_owned_vec_of_owned_strings_with_shorter_slice_of_string_references( + ) -> Result<()> { let actual = vec!["A string".to_string(), "Another string".to_string()]; let matcher = container_eq(["A string"]); diff --git a/googletest/src/matchers/contains_matcher.rs b/googletest/src/matchers/contains_matcher.rs index d714c888..e22359d9 100644 --- a/googletest/src/matchers/contains_matcher.rs +++ b/googletest/src/matchers/contains_matcher.rs @@ -48,7 +48,7 @@ pub fn contains(inner: InnerMatcherT) -> ContainsMatcher { inner: InnerMatcherT, - count: Option>>, + count: Option>>, phantom: PhantomData, } @@ -65,7 +65,7 @@ impl ContainsMatcher { /// /// One can also use `times(eq(0))` to test for the *absence* of an item /// matching the expected value. - pub fn times(mut self, count: impl Matcher + 'static) -> Self { + pub fn times(mut self, count: impl Matcher + 'static) -> Self { self.count = Some(Box::new(count)); self } @@ -81,14 +81,15 @@ impl ContainsMatcher { // because val is dropped before matcher but the trait bound requires that // the argument to matches outlive the matcher. It works fine if one defines // val before matcher. -impl, ContainerT: Debug> Matcher +impl, ContainerT: Debug> Matcher for ContainsMatcher where for<'a> &'a ContainerT: IntoIterator, { - type ActualT = ContainerT; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ContainerT) -> MatcherResult + where + ContainerT: 'a, + { if let Some(count) = &self.count { count.matches(&self.count_matches(actual)) } else { @@ -101,7 +102,10 @@ where } } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ContainerT) -> String + where + ContainerT: 'a, + { let count = self.count_matches(actual); match (count, &self.count) { (_, Some(_)) => format!("which contains {} matching elements", count), @@ -137,7 +141,7 @@ impl ContainsMatcher { fn count_matches(&self, actual: &ContainerT) -> usize where for<'b> &'b ContainerT: IntoIterator, - InnerMatcherT: Matcher, + InnerMatcherT: Matcher, { let mut count = 0; for v in actual.into_iter() { diff --git a/googletest/src/matchers/contains_regex_matcher.rs b/googletest/src/matchers/contains_regex_matcher.rs index 8cc93a70..f5c88d94 100644 --- a/googletest/src/matchers/contains_regex_matcher.rs +++ b/googletest/src/matchers/contains_regex_matcher.rs @@ -70,10 +70,11 @@ pub struct ContainsRegexMatcher { phantom: PhantomData, } -impl + Debug + ?Sized> Matcher for ContainsRegexMatcher { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { +impl + Debug + ?Sized> Matcher for ContainsRegexMatcher { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { self.regex.is_match(actual.as_ref()).into() } diff --git a/googletest/src/matchers/disjunction_matcher.rs b/googletest/src/matchers/disjunction_matcher.rs index 48bf226a..849b6da9 100644 --- a/googletest/src/matchers/disjunction_matcher.rs +++ b/googletest/src/matchers/disjunction_matcher.rs @@ -33,20 +33,21 @@ impl DisjunctionMatcher { } } -impl> Matcher for DisjunctionMatcher -where - M1::ActualT: Debug, -{ - type ActualT = M1::ActualT; - - fn matches(&self, actual: &M1::ActualT) -> MatcherResult { +impl, M2: Matcher> Matcher for DisjunctionMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { match (self.m1.matches(actual), self.m2.matches(actual)) { (MatcherResult::NoMatch, MatcherResult::NoMatch) => MatcherResult::NoMatch, _ => MatcherResult::Match, } } - fn explain_match(&self, actual: &M1::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { format!("{} and\n {}", self.m1.explain_match(actual), self.m2.explain_match(actual)) } diff --git a/googletest/src/matchers/display_matcher.rs b/googletest/src/matchers/display_matcher.rs index 628769be..de31367e 100644 --- a/googletest/src/matchers/display_matcher.rs +++ b/googletest/src/matchers/display_matcher.rs @@ -22,27 +22,31 @@ use std::marker::PhantomData; /// let result: impl Display = ...; /// verify_that!(result, displays_as(eq(format!("{}", result))))?; /// ``` -pub fn displays_as>( +pub fn displays_as>( inner: InnerMatcher, -) -> impl Matcher { +) -> impl Matcher { DisplayMatcher:: { inner, phantom: Default::default() } } -struct DisplayMatcher { +struct DisplayMatcher> { inner: InnerMatcher, phantom: PhantomData, } -impl> Matcher +impl> Matcher for DisplayMatcher { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { self.inner.matches(&format!("{actual}")) } - fn explain_match(&self, actual: &T) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { format!("which displays as a string {}", self.inner.explain_match(&format!("{actual}"))) } diff --git a/googletest/src/matchers/each_matcher.rs b/googletest/src/matchers/each_matcher.rs index 39b96b30..93f683be 100644 --- a/googletest/src/matchers/each_matcher.rs +++ b/googletest/src/matchers/each_matcher.rs @@ -63,10 +63,10 @@ use std::{fmt::Debug, marker::PhantomData}; /// ``` pub fn each( inner: MatcherT, -) -> impl Matcher +) -> impl Matcher where for<'a> &'a ActualT: IntoIterator, - MatcherT: Matcher, + MatcherT: Matcher, { EachMatcher { inner, phantom: Default::default() } } @@ -76,14 +76,16 @@ struct EachMatcher { phantom: PhantomData, } -impl Matcher for EachMatcher +impl Matcher + for EachMatcher where for<'a> &'a ActualT: IntoIterator, - MatcherT: Matcher, + MatcherT: Matcher, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { for element in actual { if self.inner.matches(element).is_no_match() { return MatcherResult::NoMatch; @@ -92,7 +94,10 @@ where MatcherResult::Match } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { let mut non_matching_elements = Vec::new(); for (index, element) in actual.into_iter().enumerate() { if self.inner.matches(element).is_no_match() { diff --git a/googletest/src/matchers/elements_are_matcher.rs b/googletest/src/matchers/elements_are_matcher.rs index b5d59107..1dabbdf2 100644 --- a/googletest/src/matchers/elements_are_matcher.rs +++ b/googletest/src/matchers/elements_are_matcher.rs @@ -102,7 +102,7 @@ pub mod internal { /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] pub struct ElementsAre<'a, ContainerT: ?Sized, T: Debug> { - elements: Vec + 'a>>, + elements: Vec + 'a>>, phantom: PhantomData, } @@ -111,18 +111,20 @@ pub mod internal { /// /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] - pub fn new(elements: Vec + 'a>>) -> Self { + pub fn new(elements: Vec + 'a>>) -> Self { Self { elements, phantom: Default::default() } } } - impl<'a, T: Debug, ContainerT: Debug + ?Sized> Matcher for ElementsAre<'a, ContainerT, T> + impl<'a, T: Debug, ContainerT: Debug + ?Sized> Matcher + for ElementsAre<'a, ContainerT, T> where for<'b> &'b ContainerT: IntoIterator, { - type ActualT = ContainerT; - - fn matches(&self, actual: &ContainerT) -> MatcherResult { + fn matches<'b>(&self, actual: &'b ContainerT) -> MatcherResult + where + ContainerT: 'b, + { let mut zipped_iterator = zip(actual.into_iter(), self.elements.iter()); for (a, e) in zipped_iterator.by_ref() { if e.matches(a).is_no_match() { @@ -136,7 +138,10 @@ pub mod internal { } } - fn explain_match(&self, actual: &ContainerT) -> String { + fn explain_match<'b>(&self, actual: &'b ContainerT) -> String + where + ContainerT: 'b, + { let actual_iterator = actual.into_iter(); let mut zipped_iterator = zip(actual_iterator, self.elements.iter()); let mut mismatches = Vec::new(); diff --git a/googletest/src/matchers/empty_matcher.rs b/googletest/src/matchers/empty_matcher.rs index 5a120faa..63d34763 100644 --- a/googletest/src/matchers/empty_matcher.rs +++ b/googletest/src/matchers/empty_matcher.rs @@ -47,7 +47,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # should_pass().unwrap(); /// ``` -pub fn empty() -> impl Matcher +pub fn empty() -> impl Matcher where for<'a> &'a T: IntoIterator, { @@ -58,13 +58,14 @@ struct EmptyMatcher { phantom: PhantomData, } -impl Matcher for EmptyMatcher +impl Matcher for EmptyMatcher where for<'a> &'a T: IntoIterator, { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { actual.into_iter().next().is_none().into() } diff --git a/googletest/src/matchers/eq_deref_of_matcher.rs b/googletest/src/matchers/eq_deref_of_matcher.rs index 15409058..3ab6721c 100644 --- a/googletest/src/matchers/eq_deref_of_matcher.rs +++ b/googletest/src/matchers/eq_deref_of_matcher.rs @@ -64,15 +64,16 @@ pub struct EqDerefOfMatcher { phantom: PhantomData, } -impl Matcher for EqDerefOfMatcher +impl Matcher for EqDerefOfMatcher where ActualT: Debug + ?Sized, ExpectedRefT: Deref + Debug, ExpectedT: PartialEq + Debug, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { (self.expected.deref() == actual).into() } @@ -83,7 +84,10 @@ where } } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { format!( "which {}{}", &self.describe(self.matches(actual)), diff --git a/googletest/src/matchers/eq_matcher.rs b/googletest/src/matchers/eq_matcher.rs index 42684c97..eb248323 100644 --- a/googletest/src/matchers/eq_matcher.rs +++ b/googletest/src/matchers/eq_matcher.rs @@ -82,10 +82,11 @@ pub struct EqMatcher { phantom: PhantomData, } -impl + Debug> Matcher for EqMatcher { - type ActualT = A; - - fn matches(&self, actual: &A) -> MatcherResult { +impl + Debug> Matcher for EqMatcher { + fn matches<'a>(&self, actual: &'a A) -> MatcherResult + where + A: 'a, + { (self.expected == *actual).into() } @@ -96,7 +97,10 @@ impl + Debug> Matcher for EqMatcher { } } - fn explain_match(&self, actual: &A) -> String { + fn explain_match<'a>(&self, actual: &'a A) -> String + where + A: 'a, + { let expected_debug = format!("{:#?}", self.expected); let actual_debug = format!("{:#?}", actual); let description = self.describe(self.matches(actual)); diff --git a/googletest/src/matchers/err_matcher.rs b/googletest/src/matchers/err_matcher.rs index 022bc8cb..d3e04a64 100644 --- a/googletest/src/matchers/err_matcher.rs +++ b/googletest/src/matchers/err_matcher.rs @@ -35,9 +35,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # should_fail_1().unwrap_err(); /// # should_fail_2().unwrap_err(); /// ``` -pub fn err( - inner: impl Matcher, -) -> impl Matcher> { +pub fn err(inner: impl Matcher) -> impl Matcher> { ErrMatcher:: { inner, phantom_t: Default::default(), phantom_e: Default::default() } } @@ -47,16 +45,20 @@ struct ErrMatcher { phantom_e: PhantomData, } -impl> Matcher +impl> Matcher> for ErrMatcher { - type ActualT = std::result::Result; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a std::result::Result) -> MatcherResult + where + std::result::Result: 'a, + { actual.as_ref().err().map(|v| self.inner.matches(v)).unwrap_or(MatcherResult::NoMatch) } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a std::result::Result) -> String + where + std::result::Result: 'a, + { match actual { Err(e) => format!("which is an error {}", self.inner.explain_match(e)), Ok(_) => "which is a success".to_string(), diff --git a/googletest/src/matchers/field_matcher.rs b/googletest/src/matchers/field_matcher.rs index 50cac137..05c40a78 100644 --- a/googletest/src/matchers/field_matcher.rs +++ b/googletest/src/matchers/field_matcher.rs @@ -149,11 +149,11 @@ pub mod internal { /// /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] - pub fn field_matcher>( + pub fn field_matcher>( field_accessor: fn(&OuterT) -> Option<&InnerT>, field_path: &'static str, inner: InnerMatcher, - ) -> impl Matcher { + ) -> impl Matcher { FieldMatcher { field_accessor, field_path, inner } } @@ -163,12 +163,13 @@ pub mod internal { inner: InnerMatcher, } - impl> Matcher + impl> Matcher for FieldMatcher { - type ActualT = OuterT; - - fn matches(&self, actual: &OuterT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a OuterT) -> MatcherResult + where + OuterT: 'a, + { if let Some(value) = (self.field_accessor)(actual) { self.inner.matches(value) } else { @@ -176,7 +177,10 @@ pub mod internal { } } - fn explain_match(&self, actual: &OuterT) -> String { + fn explain_match<'a>(&self, actual: &'a OuterT) -> String + where + OuterT: 'a, + { if let Some(actual) = (self.field_accessor)(actual) { format!( "which has field `{}`, {}", diff --git a/googletest/src/matchers/ge_matcher.rs b/googletest/src/matchers/ge_matcher.rs index 33e847ec..8a453a6b 100644 --- a/googletest/src/matchers/ge_matcher.rs +++ b/googletest/src/matchers/ge_matcher.rs @@ -73,7 +73,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// pub fn ge, ExpectedT: Debug>( expected: ExpectedT, -) -> impl Matcher { +) -> impl Matcher { GeMatcher:: { expected, phantom: Default::default() } } @@ -82,12 +82,13 @@ struct GeMatcher { phantom: PhantomData, } -impl, ExpectedT: Debug> Matcher +impl, ExpectedT: Debug> Matcher for GeMatcher { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { (*actual >= self.expected).into() } diff --git a/googletest/src/matchers/gt_matcher.rs b/googletest/src/matchers/gt_matcher.rs index 699bf2a8..c1934e44 100644 --- a/googletest/src/matchers/gt_matcher.rs +++ b/googletest/src/matchers/gt_matcher.rs @@ -73,7 +73,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// pub fn gt, ExpectedT: Debug>( expected: ExpectedT, -) -> impl Matcher { +) -> impl Matcher { GtMatcher:: { expected, phantom: Default::default() } } @@ -82,12 +82,13 @@ struct GtMatcher { phantom: PhantomData, } -impl, ExpectedT: Debug> Matcher +impl, ExpectedT: Debug> Matcher for GtMatcher { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { (*actual > self.expected).into() } diff --git a/googletest/src/matchers/has_entry_matcher.rs b/googletest/src/matchers/has_entry_matcher.rs index 67a44cd1..7acda7a1 100644 --- a/googletest/src/matchers/has_entry_matcher.rs +++ b/googletest/src/matchers/has_entry_matcher.rs @@ -61,10 +61,10 @@ use std::marker::PhantomData; /// However, `has_entry` will offer somewhat better diagnostic messages in the /// case of assertion failure. And it avoid the extra allocation hidden in the /// code above. -pub fn has_entry>( +pub fn has_entry>( key: KeyT, inner: MatcherT, -) -> impl Matcher> { +) -> impl Matcher> { HasEntryMatcher { key, inner, phantom: Default::default() } } @@ -74,12 +74,13 @@ struct HasEntryMatcher { phantom: PhantomData, } -impl> Matcher - for HasEntryMatcher +impl> + Matcher> for HasEntryMatcher { - type ActualT = HashMap; - - fn matches(&self, actual: &HashMap) -> MatcherResult { + fn matches<'a>(&self, actual: &'a HashMap) -> MatcherResult + where + HashMap: 'a, + { if let Some(value) = actual.get(&self.key) { self.inner.matches(value) } else { @@ -87,7 +88,10 @@ impl } } - fn explain_match(&self, actual: &HashMap) -> String { + fn explain_match<'a>(&self, actual: &'a HashMap) -> String + where + HashMap: 'a, + { if let Some(value) = actual.get(&self.key) { format!( "which contains key {:?}, but is mapped to value {:#?}, {}", diff --git a/googletest/src/matchers/is_matcher.rs b/googletest/src/matchers/is_matcher.rs index 51fd3b21..e821ed33 100644 --- a/googletest/src/matchers/is_matcher.rs +++ b/googletest/src/matchers/is_matcher.rs @@ -22,10 +22,10 @@ use std::{fmt::Debug, marker::PhantomData}; /// The returned matcher produces a description prefixed by the string /// `description`. This is useful in contexts where the test assertion failure /// output must include the additional description. -pub fn is<'a, ActualT: Debug + 'a, InnerMatcherT: Matcher + 'a>( +pub fn is<'a, ActualT: Debug + 'a, InnerMatcherT: Matcher + 'a>( description: &'a str, inner: InnerMatcherT, -) -> impl Matcher + 'a { +) -> impl Matcher + 'a { IsMatcher { description, inner, phantom: Default::default() } } @@ -35,12 +35,13 @@ struct IsMatcher<'a, ActualT, InnerMatcherT> { phantom: PhantomData, } -impl<'a, ActualT: Debug, InnerMatcherT: Matcher> Matcher +impl<'a, ActualT: Debug, InnerMatcherT: Matcher> Matcher for IsMatcher<'a, ActualT, InnerMatcherT> { - type ActualT = ActualT; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + fn matches<'b>(&self, actual: &'b ActualT) -> MatcherResult + where + ActualT: 'b, + { self.inner.matches(actual) } @@ -59,7 +60,10 @@ impl<'a, ActualT: Debug, InnerMatcherT: Matcher> Matcher } } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'b>(&self, actual: &'b ActualT) -> String + where + ActualT: 'b, + { self.inner.explain_match(actual) } } diff --git a/googletest/src/matchers/is_nan_matcher.rs b/googletest/src/matchers/is_nan_matcher.rs index 3cbe694d..82234750 100644 --- a/googletest/src/matchers/is_nan_matcher.rs +++ b/googletest/src/matchers/is_nan_matcher.rs @@ -17,16 +17,17 @@ use num_traits::float::Float; use std::{fmt::Debug, marker::PhantomData}; /// Matches a floating point value which is NaN. -pub fn is_nan() -> impl Matcher { +pub fn is_nan() -> impl Matcher { IsNanMatcher::(Default::default()) } struct IsNanMatcher(PhantomData); -impl Matcher for IsNanMatcher { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { +impl Matcher for IsNanMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { actual.is_nan().into() } diff --git a/googletest/src/matchers/le_matcher.rs b/googletest/src/matchers/le_matcher.rs index 6e7a16f7..54d71c1c 100644 --- a/googletest/src/matchers/le_matcher.rs +++ b/googletest/src/matchers/le_matcher.rs @@ -73,7 +73,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// pub fn le, ExpectedT: Debug>( expected: ExpectedT, -) -> impl Matcher { +) -> impl Matcher { LeMatcher:: { expected, phantom: Default::default() } } @@ -82,12 +82,13 @@ struct LeMatcher { phantom: PhantomData, } -impl, ExpectedT: Debug> Matcher +impl, ExpectedT: Debug> Matcher for LeMatcher { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { (*actual <= self.expected).into() } diff --git a/googletest/src/matchers/len_matcher.rs b/googletest/src/matchers/len_matcher.rs index 47158ff2..a402a718 100644 --- a/googletest/src/matchers/len_matcher.rs +++ b/googletest/src/matchers/len_matcher.rs @@ -48,7 +48,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # } /// # should_pass().unwrap(); /// ``` -pub fn len>(expected: E) -> impl Matcher +pub fn len>(expected: E) -> impl Matcher where for<'a> &'a T: IntoIterator, { @@ -60,13 +60,14 @@ struct LenMatcher { phantom: PhantomData, } -impl> Matcher for LenMatcher +impl> Matcher for LenMatcher where for<'a> &'a T: IntoIterator, { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { self.expected.matches(&count_elements(actual)) } @@ -81,7 +82,10 @@ where } } - fn explain_match(&self, actual: &T) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { let actual_size = count_elements(actual); format!("which has length {}, {}", actual_size, self.expected.explain_match(&actual_size)) } @@ -175,10 +179,11 @@ mod tests { #[test] fn len_matcher_explain_match() -> Result<()> { struct TestMatcher(PhantomData); - impl Matcher for TestMatcher { - type ActualT = T; - - fn matches(&self, _: &T) -> MatcherResult { + impl Matcher for TestMatcher { + fn matches<'a>(&self, _: &'a T) -> MatcherResult + where + T: 'a, + { false.into() } @@ -186,7 +191,10 @@ mod tests { "called described".into() } - fn explain_match(&self, _: &T) -> String { + fn explain_match<'a>(&self, _: &'a T) -> String + where + T: 'a, + { "called explain_match".into() } } diff --git a/googletest/src/matchers/lt_matcher.rs b/googletest/src/matchers/lt_matcher.rs index 96df00c3..2440148a 100644 --- a/googletest/src/matchers/lt_matcher.rs +++ b/googletest/src/matchers/lt_matcher.rs @@ -73,7 +73,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// pub fn lt, ExpectedT: Debug>( expected: ExpectedT, -) -> impl Matcher { +) -> impl Matcher { LtMatcher:: { expected, phantom: Default::default() } } @@ -82,12 +82,13 @@ struct LtMatcher { phantom: PhantomData, } -impl, ExpectedT: Debug> Matcher +impl, ExpectedT: Debug> Matcher for LtMatcher { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { (*actual < self.expected).into() } diff --git a/googletest/src/matchers/matches_regex_matcher.rs b/googletest/src/matchers/matches_regex_matcher.rs index d0001e2d..952b38e6 100644 --- a/googletest/src/matchers/matches_regex_matcher.rs +++ b/googletest/src/matchers/matches_regex_matcher.rs @@ -83,14 +83,15 @@ pub struct MatchesRegexMatcher> { phantom: PhantomData, } -impl Matcher for MatchesRegexMatcher +impl Matcher for MatchesRegexMatcher where PatternT: Deref, ActualT: AsRef + Debug + ?Sized, { - type ActualT = ActualT; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { self.regex.is_match(actual.as_ref()).into() } diff --git a/googletest/src/matchers/near_matcher.rs b/googletest/src/matchers/near_matcher.rs index 484939cb..705c148a 100644 --- a/googletest/src/matchers/near_matcher.rs +++ b/googletest/src/matchers/near_matcher.rs @@ -163,10 +163,11 @@ impl NearMatcher { } } -impl Matcher for NearMatcher { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { +impl Matcher for NearMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { if self.nans_are_equal && self.expected.is_nan() && actual.is_nan() { return MatcherResult::Match; } diff --git a/googletest/src/matchers/none_matcher.rs b/googletest/src/matchers/none_matcher.rs index e48d5492..3dfbb68e 100644 --- a/googletest/src/matchers/none_matcher.rs +++ b/googletest/src/matchers/none_matcher.rs @@ -31,7 +31,7 @@ use std::marker::PhantomData; /// # should_pass().unwrap(); /// # should_fail().unwrap_err(); /// ``` -pub fn none() -> impl Matcher> { +pub fn none() -> impl Matcher> { NoneMatcher:: { phantom: Default::default() } } @@ -39,10 +39,11 @@ struct NoneMatcher { phantom: PhantomData, } -impl Matcher for NoneMatcher { - type ActualT = Option; - - fn matches(&self, actual: &Option) -> MatcherResult { +impl Matcher> for NoneMatcher { + fn matches<'a>(&self, actual: &'a Option) -> MatcherResult + where + Option: 'a, + { (actual.is_none()).into() } diff --git a/googletest/src/matchers/not_matcher.rs b/googletest/src/matchers/not_matcher.rs index 1dff7911..4b6c4e8d 100644 --- a/googletest/src/matchers/not_matcher.rs +++ b/googletest/src/matchers/not_matcher.rs @@ -30,9 +30,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # should_pass().unwrap(); /// # should_fail().unwrap_err(); /// ``` -pub fn not>( - inner: InnerMatcherT, -) -> impl Matcher { +pub fn not>(inner: InnerMatcherT) -> impl Matcher { NotMatcher:: { inner, phantom: Default::default() } } @@ -41,17 +39,21 @@ struct NotMatcher { phantom: PhantomData, } -impl> Matcher for NotMatcher { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { +impl> Matcher for NotMatcher { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { match self.inner.matches(actual) { MatcherResult::Match => MatcherResult::NoMatch, MatcherResult::NoMatch => MatcherResult::Match, } } - fn explain_match(&self, actual: &T) -> String { + fn explain_match<'a>(&self, actual: &'a T) -> String + where + T: 'a, + { self.inner.explain_match(actual) } diff --git a/googletest/src/matchers/ok_matcher.rs b/googletest/src/matchers/ok_matcher.rs index 5c6fa512..5ff74ba5 100644 --- a/googletest/src/matchers/ok_matcher.rs +++ b/googletest/src/matchers/ok_matcher.rs @@ -35,9 +35,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # should_fail_1().unwrap_err(); /// # should_fail_2().unwrap_err(); /// ``` -pub fn ok( - inner: impl Matcher, -) -> impl Matcher> { +pub fn ok(inner: impl Matcher) -> impl Matcher> { OkMatcher:: { inner, phantom_t: Default::default(), phantom_e: Default::default() } } @@ -47,16 +45,20 @@ struct OkMatcher { phantom_e: PhantomData, } -impl> Matcher +impl> Matcher> for OkMatcher { - type ActualT = std::result::Result; - - fn matches(&self, actual: &Self::ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a std::result::Result) -> MatcherResult + where + std::result::Result: 'a, + { actual.as_ref().map(|v| self.inner.matches(v)).unwrap_or(MatcherResult::NoMatch) } - fn explain_match(&self, actual: &Self::ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a std::result::Result) -> String + where + std::result::Result: 'a, + { match actual { Ok(o) => format!("which is a success {}", self.inner.explain_match(o)), Err(_) => "which is an error".to_string(), diff --git a/googletest/src/matchers/points_to_matcher.rs b/googletest/src/matchers/points_to_matcher.rs index 08c7343d..14d485ba 100644 --- a/googletest/src/matchers/points_to_matcher.rs +++ b/googletest/src/matchers/points_to_matcher.rs @@ -31,12 +31,10 @@ use std::ops::Deref; /// # } /// # should_pass().unwrap(); /// ``` -pub fn points_to( - expected: MatcherT, -) -> impl Matcher +pub fn points_to(expected: MatcherT) -> impl Matcher where ExpectedT: Debug, - MatcherT: Matcher, + MatcherT: Matcher, ActualT: Deref + Debug + ?Sized, { PointsToMatcher { expected, phantom: Default::default() } @@ -47,19 +45,23 @@ struct PointsToMatcher { phantom: PhantomData, } -impl Matcher for PointsToMatcher +impl Matcher for PointsToMatcher where ExpectedT: Debug, - MatcherT: Matcher, + MatcherT: Matcher, ActualT: Deref + Debug + ?Sized, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { self.expected.matches(actual.deref()) } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { self.expected.explain_match(actual.deref()) } diff --git a/googletest/src/matchers/pointwise_matcher.rs b/googletest/src/matchers/pointwise_matcher.rs index 636f70fb..6aa9ce00 100644 --- a/googletest/src/matchers/pointwise_matcher.rs +++ b/googletest/src/matchers/pointwise_matcher.rs @@ -171,14 +171,15 @@ pub mod internal { } } - impl, ContainerT: ?Sized + Debug> Matcher + impl, ContainerT: ?Sized + Debug> Matcher for PointwiseMatcher where for<'b> &'b ContainerT: IntoIterator, { - type ActualT = ContainerT; - - fn matches(&self, actual: &ContainerT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ContainerT) -> MatcherResult + where + ContainerT: 'a, + { let mut zipped_iterator = zip(actual.into_iter(), self.matchers.iter()); for (element, matcher) in zipped_iterator.by_ref() { if matcher.matches(element).is_no_match() { @@ -192,7 +193,10 @@ pub mod internal { } } - fn explain_match(&self, actual: &ContainerT) -> String { + fn explain_match<'a>(&self, actual: &'a ContainerT) -> String + where + ContainerT: 'a, + { // TODO(b/260819741) This code duplicates elements_are_matcher.rs. Consider // extract as a separate library. (or implement pointwise! with // elements_are) diff --git a/googletest/src/matchers/predicate_matcher.rs b/googletest/src/matchers/predicate_matcher.rs index fabd6c3a..034f8b98 100644 --- a/googletest/src/matchers/predicate_matcher.rs +++ b/googletest/src/matchers/predicate_matcher.rs @@ -121,13 +121,14 @@ where #[doc(hidden)] pub struct NoDescription; -impl Matcher for PredicateMatcher +impl Matcher for PredicateMatcher where for<'a> P: Fn(&'a T) -> bool, { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { (self.predicate)(actual).into() } @@ -139,14 +140,15 @@ where } } -impl Matcher +impl Matcher for PredicateMatcher where for<'a> P: Fn(&'a T) -> bool, { - type ActualT = T; - - fn matches(&self, actual: &T) -> MatcherResult { + fn matches<'a>(&self, actual: &'a T) -> MatcherResult + where + T: 'a, + { (self.predicate)(actual).into() } @@ -165,7 +167,7 @@ mod tests { use crate::prelude::*; // Simple matcher with a description - fn is_odd() -> impl Matcher { + fn is_odd() -> impl Matcher { predicate(|x| x % 2 == 1).with_description("is odd", "is even") } @@ -185,7 +187,7 @@ mod tests { } // Simple Matcher without description - fn is_even() -> impl Matcher { + fn is_even() -> impl Matcher { predicate(|x| x % 2 == 0) } diff --git a/googletest/src/matchers/property_matcher.rs b/googletest/src/matchers/property_matcher.rs index 32638ec6..2b2dedae 100644 --- a/googletest/src/matchers/property_matcher.rs +++ b/googletest/src/matchers/property_matcher.rs @@ -139,11 +139,11 @@ pub mod internal { /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] - pub fn property_matcher>( + pub fn property_matcher>( extractor: impl Fn(&OuterT) -> InnerT, property_desc: &'static str, inner: MatcherT, - ) -> impl Matcher { + ) -> impl Matcher { PropertyMatcher { extractor, property_desc, inner, phantom: Default::default() } } @@ -154,16 +154,18 @@ pub mod internal { phantom: PhantomData, } - impl Matcher for PropertyMatcher + impl Matcher + for PropertyMatcher where InnerT: Debug, OuterT: Debug, ExtractorT: Fn(&OuterT) -> InnerT, - MatcherT: Matcher, + MatcherT: Matcher, { - type ActualT = OuterT; - - fn matches(&self, actual: &OuterT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a OuterT) -> MatcherResult + where + OuterT: 'a, + { self.inner.matches(&(self.extractor)(actual)) } @@ -175,7 +177,10 @@ pub mod internal { ) } - fn explain_match(&self, actual: &OuterT) -> String { + fn explain_match<'a>(&self, actual: &'a OuterT) -> String + where + OuterT: 'a, + { let actual_inner = (self.extractor)(actual); format!( "whose property `{}` is `{:#?}`, {}", @@ -192,11 +197,11 @@ pub mod internal { extractor: fn(&OuterT) -> &InnerT, property_desc: &'static str, inner: MatcherT, - ) -> impl Matcher + ) -> impl Matcher where OuterT: Debug, InnerT: Debug + ?Sized, - MatcherT: Matcher, + MatcherT: Matcher, { PropertyRefMatcher { extractor, property_desc, inner } } @@ -207,12 +212,13 @@ pub mod internal { inner: MatcherT, } - impl> Matcher + impl> Matcher for PropertyRefMatcher { - type ActualT = OuterT; - - fn matches(&self, actual: &OuterT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a OuterT) -> MatcherResult + where + OuterT: 'a, + { self.inner.matches((self.extractor)(actual)) } @@ -224,7 +230,10 @@ pub mod internal { ) } - fn explain_match(&self, actual: &OuterT) -> String { + fn explain_match<'a>(&self, actual: &'a OuterT) -> String + where + OuterT: 'a, + { let actual_inner = (self.extractor)(actual); format!( "whose property `{}` is `{:#?}`, {}", diff --git a/googletest/src/matchers/some_matcher.rs b/googletest/src/matchers/some_matcher.rs index a6ce021d..2046444b 100644 --- a/googletest/src/matchers/some_matcher.rs +++ b/googletest/src/matchers/some_matcher.rs @@ -35,7 +35,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// # should_fail_1().unwrap_err(); /// # should_fail_2().unwrap_err(); /// ``` -pub fn some(inner: impl Matcher) -> impl Matcher> { +pub fn some(inner: impl Matcher) -> impl Matcher> { SomeMatcher { inner, phantom: Default::default() } } @@ -44,14 +44,18 @@ struct SomeMatcher { phantom: PhantomData, } -impl> Matcher for SomeMatcher { - type ActualT = Option; - - fn matches(&self, actual: &Option) -> MatcherResult { +impl> Matcher> for SomeMatcher { + fn matches<'a>(&self, actual: &'a Option) -> MatcherResult + where + Option: 'a, + { actual.as_ref().map(|v| self.inner.matches(v)).unwrap_or(MatcherResult::NoMatch) } - fn explain_match(&self, actual: &Option) -> String { + fn explain_match<'a>(&self, actual: &'a Option) -> String + where + Option: 'a, + { match (self.matches(actual), actual) { (_, Some(t)) => format!("which has a value {}", self.inner.explain_match(t)), (_, None) => "which is None".to_string(), diff --git a/googletest/src/matchers/str_matcher.rs b/googletest/src/matchers/str_matcher.rs index 3a4e2e99..eb95ab62 100644 --- a/googletest/src/matchers/str_matcher.rs +++ b/googletest/src/matchers/str_matcher.rs @@ -271,10 +271,7 @@ pub trait StrMatcherConfigurator { /// This is only meaningful when the matcher was constructed with /// [`contains_substring`]. This method will panic when it is used with any /// other matcher construction. - fn times( - self, - times: impl Matcher + 'static, - ) -> StrMatcher; + fn times(self, times: impl Matcher + 'static) -> StrMatcher; } /// A matcher which matches equality or containment of a string-like value in a @@ -292,14 +289,15 @@ pub struct StrMatcher { phantom: PhantomData, } -impl Matcher for StrMatcher +impl Matcher for StrMatcher where ExpectedT: Deref + Debug, ActualT: AsRef + Debug + ?Sized, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { self.configuration.do_strings_match(self.expected.deref(), actual.as_ref()).into() } @@ -307,7 +305,10 @@ where self.configuration.describe(matcher_result, self.expected.deref()) } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { self.configuration.explain_match(self.expected.deref(), actual.as_ref()) } } @@ -341,10 +342,7 @@ impl>> StrMatcher { configuration: existing.configuration.ignoring_ascii_case(), ..existing } } - fn times( - self, - times: impl Matcher + 'static, - ) -> StrMatcher { + fn times(self, times: impl Matcher + 'static) -> StrMatcher { let existing = self.into(); if !matches!(existing.configuration.mode, MatchMode::Contains) { panic!("The times() configurator is only meaningful with contains_substring()."); @@ -386,7 +384,7 @@ struct Configuration { ignore_leading_whitespace: bool, ignore_trailing_whitespace: bool, case_policy: CasePolicy, - times: Option>>, + times: Option>>, } #[derive(Clone)] @@ -568,7 +566,7 @@ impl Configuration { Self { case_policy: CasePolicy::IgnoreAscii, ..self } } - fn times(self, times: impl Matcher + 'static) -> Self { + fn times(self, times: impl Matcher + 'static) -> Self { Self { times: Some(Box::new(times)), ..self } } } @@ -726,8 +724,8 @@ mod tests { } #[test] - fn matches_string_containing_expected_value_in_contains_mode_while_ignoring_ascii_case() - -> Result<()> { + fn matches_string_containing_expected_value_in_contains_mode_while_ignoring_ascii_case( + ) -> Result<()> { verify_that!("Some string", contains_substring("STR").ignoring_ascii_case()) } @@ -876,8 +874,8 @@ mod tests { } #[test] - fn describes_itself_for_matching_result_ignoring_ascii_case_and_leading_whitespace() - -> Result<()> { + fn describes_itself_for_matching_result_ignoring_ascii_case_and_leading_whitespace( + ) -> Result<()> { let matcher: StrMatcher<&str, _> = StrMatcher::with_default_config("A string") .ignoring_leading_whitespace() .ignoring_ascii_case(); @@ -1017,8 +1015,8 @@ mod tests { } #[test] - fn match_explanation_for_starts_with_includes_both_versions_of_differing_last_line() - -> Result<()> { + fn match_explanation_for_starts_with_includes_both_versions_of_differing_last_line( + ) -> Result<()> { let result = verify_that!( indoc!( " @@ -1121,8 +1119,8 @@ mod tests { } #[test] - fn match_explanation_for_contains_substring_shows_diff_when_first_and_last_line_are_incomplete() - -> Result<()> { + fn match_explanation_for_contains_substring_shows_diff_when_first_and_last_line_are_incomplete( + ) -> Result<()> { let result = verify_that!( indoc!( " diff --git a/googletest/src/matchers/subset_of_matcher.rs b/googletest/src/matchers/subset_of_matcher.rs index 587160fa..d249b257 100644 --- a/googletest/src/matchers/subset_of_matcher.rs +++ b/googletest/src/matchers/subset_of_matcher.rs @@ -82,7 +82,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// items. It should not be used on especially large containers. pub fn subset_of( superset: ExpectedT, -) -> impl Matcher +) -> impl Matcher where for<'a> &'a ActualT: IntoIterator, for<'a> &'a ExpectedT: IntoIterator, @@ -95,15 +95,16 @@ struct SubsetOfMatcher { phantom: PhantomData, } -impl Matcher +impl Matcher for SubsetOfMatcher where for<'a> &'a ActualT: IntoIterator, for<'a> &'a ExpectedT: IntoIterator, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { for actual_item in actual { if self.expected_is_missing(actual_item) { return MatcherResult::NoMatch; @@ -112,7 +113,10 @@ where MatcherResult::Match } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { let unexpected_elements = actual .into_iter() .enumerate() diff --git a/googletest/src/matchers/superset_of_matcher.rs b/googletest/src/matchers/superset_of_matcher.rs index 179339bf..f3740dda 100644 --- a/googletest/src/matchers/superset_of_matcher.rs +++ b/googletest/src/matchers/superset_of_matcher.rs @@ -83,7 +83,7 @@ use std::{fmt::Debug, marker::PhantomData}; /// items. It should not be used on especially large containers. pub fn superset_of( subset: ExpectedT, -) -> impl Matcher +) -> impl Matcher where for<'a> &'a ActualT: IntoIterator, for<'a> &'a ExpectedT: IntoIterator, @@ -96,15 +96,16 @@ struct SupersetOfMatcher { phantom: PhantomData, } -impl Matcher +impl Matcher for SupersetOfMatcher where for<'a> &'a ActualT: IntoIterator, for<'a> &'a ExpectedT: IntoIterator, { - type ActualT = ActualT; - - fn matches(&self, actual: &ActualT) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ActualT) -> MatcherResult + where + ActualT: 'a, + { for expected_item in &self.subset { if actual_is_missing(actual, expected_item) { return MatcherResult::NoMatch; @@ -113,7 +114,10 @@ where MatcherResult::Match } - fn explain_match(&self, actual: &ActualT) -> String { + fn explain_match<'a>(&self, actual: &'a ActualT) -> String + where + ActualT: 'a, + { let missing_items: Vec<_> = self .subset .into_iter() diff --git a/googletest/src/matchers/tuple_matcher.rs b/googletest/src/matchers/tuple_matcher.rs index a2e325bb..436b620e 100644 --- a/googletest/src/matchers/tuple_matcher.rs +++ b/googletest/src/matchers/tuple_matcher.rs @@ -40,10 +40,11 @@ pub mod internal { // This implementation is provided for completeness, but is completely trivial. // The only actual value which can be supplied is (), which must match. - impl Matcher for () { - type ActualT = (); - - fn matches(&self, _: &Self::ActualT) -> MatcherResult { + impl Matcher<()> for () { + fn matches<'a>(&self, _: &'a ()) -> MatcherResult + where + (): 'a, + { MatcherResult::Match } @@ -61,12 +62,10 @@ pub mod internal { #[doc(hidden)] macro_rules! tuple_matcher_n { ($([$field_number:tt, $matcher_type:ident, $field_type:ident]),*) => { - impl<$($field_type: Debug, $matcher_type: Matcher),*> - Matcher for ($($matcher_type,)*) + impl<$($field_type: Debug, $matcher_type: Matcher<$field_type>),*> + Matcher<($($field_type,)*)> for ($($matcher_type,)*) { - type ActualT = ($($field_type,)*); - - fn matches(&self, actual: &($($field_type,)*)) -> MatcherResult { + fn matches<'a>(&self, actual: &'a ($($field_type,)*)) -> MatcherResult where ($($field_type,)*): 'a { $(match self.$field_number.matches(&actual.$field_number) { MatcherResult::Match => {}, MatcherResult::NoMatch => { @@ -76,7 +75,7 @@ pub mod internal { MatcherResult::Match } - fn explain_match(&self, actual: &($($field_type,)*)) -> String { + fn explain_match<'a>(&self, actual: &'a ($($field_type,)*)) -> String where ($($field_type,)*): 'a { let mut explanation = format!("which {}", self.describe(self.matches(actual))); $(match self.$field_number.matches(&actual.$field_number) { MatcherResult::Match => {}, diff --git a/googletest/src/matchers/unordered_elements_are_matcher.rs b/googletest/src/matchers/unordered_elements_are_matcher.rs index d0e9e582..107cb171 100644 --- a/googletest/src/matchers/unordered_elements_are_matcher.rs +++ b/googletest/src/matchers/unordered_elements_are_matcher.rs @@ -378,7 +378,7 @@ pub mod internal { /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] pub struct UnorderedElementsAreMatcher<'a, ContainerT: ?Sized, T: Debug, const N: usize> { - elements: [Box + 'a>; N], + elements: [Box + 'a>; N], requirements: Requirements, phantom: PhantomData, } @@ -386,10 +386,7 @@ pub mod internal { impl<'a, ContainerT: ?Sized, T: Debug, const N: usize> UnorderedElementsAreMatcher<'a, ContainerT, T, N> { - pub fn new( - elements: [Box + 'a>; N], - requirements: Requirements, - ) -> Self { + pub fn new(elements: [Box + 'a>; N], requirements: Requirements) -> Self { Self { elements, requirements, phantom: Default::default() } } } @@ -403,19 +400,23 @@ pub mod internal { // least one expected element and vice versa. // 3. `UnorderedElementsAreMatcher` verifies that a perfect matching exists // using Ford-Fulkerson. - impl<'a, T: Debug, ContainerT: Debug + ?Sized, const N: usize> Matcher + impl<'a, T: Debug, ContainerT: Debug + ?Sized, const N: usize> Matcher for UnorderedElementsAreMatcher<'a, ContainerT, T, N> where for<'b> &'b ContainerT: IntoIterator, { - type ActualT = ContainerT; - - fn matches(&self, actual: &ContainerT) -> MatcherResult { + fn matches<'b>(&self, actual: &'b ContainerT) -> MatcherResult + where + ContainerT: 'b, + { let match_matrix = MatchMatrix::generate(actual, &self.elements); match_matrix.is_match_for(self.requirements).into() } - fn explain_match(&self, actual: &ContainerT) -> String { + fn explain_match<'b>(&self, actual: &'b ContainerT) -> String + where + ContainerT: 'b, + { if let Some(size_mismatch_explanation) = self.requirements.explain_size_mismatch(actual, N) { @@ -450,7 +451,7 @@ pub mod internal { } type KeyValueMatcher<'a, KeyT, ValueT> = - (Box + 'a>, Box + 'a>); + (Box + 'a>, Box + 'a>); /// This is the analogue to [UnorderedElementsAreMatcher] for maps and /// map-like collections. @@ -479,19 +480,23 @@ pub mod internal { } } - impl<'a, KeyT: Debug, ValueT: Debug, ContainerT: Debug + ?Sized, const N: usize> Matcher - for UnorderedElementsOfMapAreMatcher<'a, ContainerT, KeyT, ValueT, N> + impl<'a, KeyT: Debug, ValueT: Debug, ContainerT: Debug + ?Sized, const N: usize> + Matcher for UnorderedElementsOfMapAreMatcher<'a, ContainerT, KeyT, ValueT, N> where for<'b> &'b ContainerT: IntoIterator, { - type ActualT = ContainerT; - - fn matches(&self, actual: &ContainerT) -> MatcherResult { + fn matches<'b>(&self, actual: &'b ContainerT) -> MatcherResult + where + ContainerT: 'b, + { let match_matrix = MatchMatrix::generate_for_map(actual, &self.elements); match_matrix.is_match_for(self.requirements).into() } - fn explain_match(&self, actual: &ContainerT) -> String { + fn explain_match<'b>(&self, actual: &'b ContainerT) -> String + where + ContainerT: 'b, + { if let Some(size_mismatch_explanation) = self.requirements.explain_size_mismatch(actual, N) { @@ -601,7 +606,7 @@ pub mod internal { impl MatchMatrix { fn generate<'a, T: Debug + 'a, ContainerT: Debug + ?Sized>( actual: &ContainerT, - expected: &[Box + 'a>; N], + expected: &[Box + 'a>; N], ) -> Self where for<'b> &'b ContainerT: IntoIterator, @@ -960,7 +965,7 @@ pub mod internal { fn get_explanation<'a, T: Debug, ContainerT: Debug + ?Sized>( &self, actual: &ContainerT, - expected: &[Box + 'a>; N], + expected: &[Box + 'a>; N], requirements: Requirements, ) -> Option where @@ -1081,9 +1086,9 @@ mod tests { // aren't dropped too early. let matchers = ((eq(2), eq("Two")), (eq(1), eq("One")), (eq(3), eq("Three"))); let matcher: UnorderedElementsOfMapAreMatcher, _, _, 3> = unordered_elements_are![ - (matchers.0.0, matchers.0.1), - (matchers.1.0, matchers.1.1), - (matchers.2.0, matchers.2.1) + (matchers.0 .0, matchers.0 .1), + (matchers.1 .0, matchers.1 .1), + (matchers.2 .0, matchers.2 .1) ]; verify_that!( Matcher::describe(&matcher, MatcherResult::Match), @@ -1106,9 +1111,9 @@ mod tests { // aren't dropped too early. let matchers = ((anything(), eq(1)), (anything(), eq(2)), (anything(), eq(2))); let matcher: UnorderedElementsOfMapAreMatcher, _, _, 3> = unordered_elements_are![ - (matchers.0.0, matchers.0.1), - (matchers.1.0, matchers.1.1), - (matchers.2.0, matchers.2.1), + (matchers.0 .0, matchers.0 .1), + (matchers.1 .0, matchers.1 .1), + (matchers.2 .0, matchers.2 .1), ]; let value: HashMap = HashMap::from_iter([(0, 1), (1, 1), (2, 2)]); verify_that!( diff --git a/googletest/tests/elements_are_matcher_test.rs b/googletest/tests/elements_are_matcher_test.rs index 99e9fe78..64c49c27 100644 --- a/googletest/tests/elements_are_matcher_test.rs +++ b/googletest/tests/elements_are_matcher_test.rs @@ -110,7 +110,7 @@ fn elements_are_explain_match_wrong_size() -> Result<()> { ) } -fn create_matcher() -> impl Matcher> { +fn create_matcher() -> impl Matcher> { elements_are![eq(1)] } diff --git a/googletest/tests/matches_pattern_test.rs b/googletest/tests/matches_pattern_test.rs index ab3b1e34..9a79f578 100644 --- a/googletest/tests/matches_pattern_test.rs +++ b/googletest/tests/matches_pattern_test.rs @@ -993,8 +993,8 @@ fn matches_struct_with_a_method_returning_reference_followed_by_a_field() -> Res } #[test] -fn matches_struct_with_a_method_returning_reference_followed_by_a_field_with_trailing_comma() --> Result<()> { +fn matches_struct_with_a_method_returning_reference_followed_by_a_field_with_trailing_comma( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1064,8 +1064,8 @@ fn matches_struct_with_a_method_taking_enum_value_param_ret_ref_followed_by_fiel } #[test] -fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref_and_field() --> Result<()> { +fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref_and_field( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1291,8 +1291,8 @@ fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref( } #[test] -fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_ret_ref() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_ret_ref( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1341,8 +1341,8 @@ fn matches_struct_with_a_field_followed_by_a_method_followed_by_a_field() -> Res } #[test] -fn matches_struct_with_a_field_followed_by_a_method_followed_by_a_field_with_trailing_comma() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_followed_by_a_field_with_trailing_comma( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1397,8 +1397,8 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_followed_by_a_fi } #[test] -fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_followed_by_a_field() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_followed_by_a_field( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1425,8 +1425,8 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_com } #[test] -fn matches_struct_with_field_followed_by_method_taking_enum_value_param_followed_by_field() --> Result<()> { +fn matches_struct_with_field_followed_by_method_taking_enum_value_param_followed_by_field( +) -> Result<()> { enum AnEnum { AVariant, } @@ -1484,8 +1484,8 @@ fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field( } #[test] -fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_with_trailing_comma() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_with_trailing_comma( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1512,8 +1512,8 @@ fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_ } #[test] -fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed_by_a_field() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed_by_a_field( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, @@ -1540,8 +1540,8 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed } #[test] -fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_followed_by_field() --> Result<()> { +fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_followed_by_field( +) -> Result<()> { enum AnEnum { AVariant, } @@ -1572,8 +1572,8 @@ fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_ } #[test] -fn matches_struct_with_a_field_followed_by_a_method_with_params_trailing_comma_ret_ref_followed_by_a_field() --> Result<()> { +fn matches_struct_with_a_field_followed_by_a_method_with_params_trailing_comma_ret_ref_followed_by_a_field( +) -> Result<()> { #[derive(Debug)] struct AStruct { a_field: u32, diff --git a/googletest/tests/pointwise_matcher_test.rs b/googletest/tests/pointwise_matcher_test.rs index 85d16ff6..b40038f0 100644 --- a/googletest/tests/pointwise_matcher_test.rs +++ b/googletest/tests/pointwise_matcher_test.rs @@ -127,8 +127,8 @@ fn pointwise_returns_mismatch_when_actual_value_does_not_match_on_second_item() } #[test] -fn pointwise_returns_mismatch_when_actual_value_does_not_match_on_first_and_second_items() --> Result<()> { +fn pointwise_returns_mismatch_when_actual_value_does_not_match_on_first_and_second_items( +) -> Result<()> { let result = verify_that!(vec![1, 2, 3], pointwise!(eq, vec![2, 3, 3])); verify_that!( diff --git a/googletest/tests/unordered_elements_are_matcher_test.rs b/googletest/tests/unordered_elements_are_matcher_test.rs index a105b70c..70089586 100644 --- a/googletest/tests/unordered_elements_are_matcher_test.rs +++ b/googletest/tests/unordered_elements_are_matcher_test.rs @@ -208,7 +208,7 @@ fn unordered_elements_are_unmatchable_actual_description_mismatch() -> Result<() ) } -fn create_matcher() -> impl Matcher> { +fn create_matcher() -> impl Matcher> { unordered_elements_are![eq(1)] } @@ -217,7 +217,7 @@ fn unordered_elements_are_works_when_matcher_is_created_in_subroutine() -> Resul verify_that!(vec![1], create_matcher()) } -fn create_matcher_for_map() -> impl Matcher> { +fn create_matcher_for_map() -> impl Matcher> { unordered_elements_are![(eq(1), eq(1))] }