From cf4e2ae06e098f54942b3eacc146437da1d95ae7 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Wed, 10 Jan 2024 13:32:19 +0100 Subject: [PATCH] fix clippy::use_self --- benches/extra/zipslices.rs | 2 +- examples/iris.rs | 4 +- src/adaptors/mod.rs | 4 +- src/adaptors/multi_product.rs | 6 +- src/duplicates_impl.rs | 6 +- src/either_or_both.rs | 144 +++++++++++++++++----------------- src/groupbylazy.rs | 2 +- src/kmerge_impl.rs | 4 +- src/lazy_buffer.rs | 4 +- src/lib.rs | 6 +- src/minmax.rs | 6 +- src/tuple_impl.rs | 2 +- src/zip_longest.rs | 2 +- tests/quick.rs | 26 +++--- tests/test_core.rs | 2 +- tests/test_std.rs | 14 ++-- 16 files changed, 117 insertions(+), 117 deletions(-) diff --git a/benches/extra/zipslices.rs b/benches/extra/zipslices.rs index a7120e168..2ec7bc0c0 100644 --- a/benches/extra/zipslices.rs +++ b/benches/extra/zipslices.rs @@ -58,7 +58,7 @@ where #[inline(always)] pub fn from_slices(a: T, b: U) -> Self { let minl = cmp::min(a.len(), b.len()); - ZipSlices { + Self { t: a, u: b, len: minl, diff --git a/examples/iris.rs b/examples/iris.rs index 798fdb08e..5f5525154 100644 --- a/examples/iris.rs +++ b/examples/iris.rs @@ -25,7 +25,7 @@ enum ParseError { impl From for ParseError { fn from(err: ParseFloatError) -> Self { - ParseError::Numeric(err) + Self::Numeric(err) } } @@ -34,7 +34,7 @@ impl FromStr for Iris { type Err = ParseError; fn from_str(s: &str) -> Result { - let mut iris = Iris { + let mut iris = Self { name: "".into(), data: [0.; 4], }; diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index a5b182d78..08d91e397 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -218,7 +218,7 @@ where /// Split the `PutBack` into its parts. #[inline] pub fn into_parts(self) -> (Option, I) { - let PutBack { top, iter } = self; + let Self { top, iter } = self; (top, iter) } @@ -689,7 +689,7 @@ pub struct Tuple1Combination { impl From for Tuple1Combination { fn from(iter: I) -> Self { - Tuple1Combination { iter } + Self { iter } } } diff --git a/src/adaptors/multi_product.rs b/src/adaptors/multi_product.rs index 3782f5990..a9d39562b 100644 --- a/src/adaptors/multi_product.rs +++ b/src/adaptors/multi_product.rs @@ -93,7 +93,7 @@ where if last.in_progress() { true - } else if MultiProduct::iterate_last(rest, state) { + } else if Self::iterate_last(rest, state) { last.reset(); last.iterate(); // If iterator is None twice consecutively, then iterator is @@ -133,7 +133,7 @@ where I::Item: Clone, { fn new(iter: I) -> Self { - MultiProductIter { + Self { cur: None, iter: iter.clone(), iter_orig: iter, @@ -165,7 +165,7 @@ where type Item = Vec; fn next(&mut self) -> Option { - if MultiProduct::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) { + if Self::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) { Some(self.curr_iterator()) } else { None diff --git a/src/duplicates_impl.rs b/src/duplicates_impl.rs index 71ed21841..a0db15432 100644 --- a/src/duplicates_impl.rs +++ b/src/duplicates_impl.rs @@ -22,7 +22,7 @@ mod private { impl DuplicatesBy { pub(crate) fn new(iter: I, key_method: F) -> Self { - DuplicatesBy { + Self { iter, meta: Meta { used: HashMap::new(), @@ -77,7 +77,7 @@ mod private { type Item = I::Item; fn next(&mut self) -> Option { - let DuplicatesBy { iter, meta } = self; + let Self { iter, meta } = self; iter.find_map(|v| meta.filter(v)) } @@ -109,7 +109,7 @@ mod private { F: KeyMethod, { fn next_back(&mut self) -> Option { - let DuplicatesBy { iter, meta } = self; + let Self { iter, meta } = self; iter.rev().find_map(|v| meta.filter(v)) } } diff --git a/src/either_or_both.rs b/src/either_or_both.rs index b504d69f7..26fc1192d 100644 --- a/src/either_or_both.rs +++ b/src/either_or_both.rs @@ -27,13 +27,13 @@ impl EitherOrBoth { /// If `Left`, return true. Otherwise, return false. /// Exclusive version of [`has_left`](EitherOrBoth::has_left). pub fn is_left(&self) -> bool { - matches!(self, EitherOrBoth::Left(_)) + matches!(self, Self::Left(_)) } /// If `Right`, return true. Otherwise, return false. /// Exclusive version of [`has_right`](EitherOrBoth::has_right). pub fn is_right(&self) -> bool { - matches!(self, EitherOrBoth::Right(_)) + matches!(self, Self::Right(_)) } /// If `Both`, return true. Otherwise, return false. @@ -44,16 +44,16 @@ impl EitherOrBoth { /// If `Left`, or `Both`, return `Some` with the left value. Otherwise, return `None`. pub fn left(self) -> Option { match self { - EitherOrBoth::Left(left) | EitherOrBoth::Both(left, _) => Some(left), - EitherOrBoth::Right(_) => None, + Self::Left(left) | Self::Both(left, _) => Some(left), + Self::Right(_) => None, } } /// If `Right`, or `Both`, return `Some` with the right value. Otherwise, return `None`. pub fn right(self) -> Option { match self { - EitherOrBoth::Right(right) | EitherOrBoth::Both(_, right) => Some(right), - EitherOrBoth::Left(_) => None, + Self::Right(right) | Self::Both(_, right) => Some(right), + Self::Left(_) => None, } } @@ -85,7 +85,7 @@ impl EitherOrBoth { /// ``` pub fn just_left(self) -> Option { match self { - EitherOrBoth::Left(left) => Some(left), + Self::Left(left) => Some(left), _ => None, } } @@ -110,7 +110,7 @@ impl EitherOrBoth { /// ``` pub fn just_right(self) -> Option { match self { - EitherOrBoth::Right(right) => Some(right), + Self::Right(right) => Some(right), _ => None, } } @@ -118,7 +118,7 @@ impl EitherOrBoth { /// If `Both`, return `Some` containing the left and right values. Otherwise, return `None`. pub fn both(self) -> Option<(A, B)> { match self { - EitherOrBoth::Both(a, b) => Some((a, b)), + Self::Both(a, b) => Some((a, b)), _ => None, } } @@ -129,8 +129,8 @@ impl EitherOrBoth { B: Into, { match self { - EitherOrBoth::Left(a) | EitherOrBoth::Both(a, _) => a, - EitherOrBoth::Right(b) => b.into(), + Self::Left(a) | Self::Both(a, _) => a, + Self::Right(b) => b.into(), } } @@ -140,26 +140,26 @@ impl EitherOrBoth { A: Into, { match self { - EitherOrBoth::Right(b) | EitherOrBoth::Both(_, b) => b, - EitherOrBoth::Left(a) => a.into(), + Self::Right(b) | Self::Both(_, b) => b, + Self::Left(a) => a.into(), } } /// Converts from `&EitherOrBoth` to `EitherOrBoth<&A, &B>`. pub fn as_ref(&self) -> EitherOrBoth<&A, &B> { match *self { - EitherOrBoth::Left(ref left) => EitherOrBoth::Left(left), - EitherOrBoth::Right(ref right) => EitherOrBoth::Right(right), - EitherOrBoth::Both(ref left, ref right) => EitherOrBoth::Both(left, right), + Self::Left(ref left) => EitherOrBoth::Left(left), + Self::Right(ref right) => EitherOrBoth::Right(right), + Self::Both(ref left, ref right) => EitherOrBoth::Both(left, right), } } /// Converts from `&mut EitherOrBoth` to `EitherOrBoth<&mut A, &mut B>`. pub fn as_mut(&mut self) -> EitherOrBoth<&mut A, &mut B> { match *self { - EitherOrBoth::Left(ref mut left) => EitherOrBoth::Left(left), - EitherOrBoth::Right(ref mut right) => EitherOrBoth::Right(right), - EitherOrBoth::Both(ref mut left, ref mut right) => EitherOrBoth::Both(left, right), + Self::Left(ref mut left) => EitherOrBoth::Left(left), + Self::Right(ref mut right) => EitherOrBoth::Right(right), + Self::Both(ref mut left, ref mut right) => EitherOrBoth::Both(left, right), } } @@ -170,9 +170,9 @@ impl EitherOrBoth { B: Deref, { match *self { - EitherOrBoth::Left(ref left) => EitherOrBoth::Left(left), - EitherOrBoth::Right(ref right) => EitherOrBoth::Right(right), - EitherOrBoth::Both(ref left, ref right) => EitherOrBoth::Both(left, right), + Self::Left(ref left) => EitherOrBoth::Left(left), + Self::Right(ref right) => EitherOrBoth::Right(right), + Self::Both(ref left, ref right) => EitherOrBoth::Both(left, right), } } @@ -183,18 +183,18 @@ impl EitherOrBoth { B: DerefMut, { match *self { - EitherOrBoth::Left(ref mut left) => EitherOrBoth::Left(left), - EitherOrBoth::Right(ref mut right) => EitherOrBoth::Right(right), - EitherOrBoth::Both(ref mut left, ref mut right) => EitherOrBoth::Both(left, right), + Self::Left(ref mut left) => EitherOrBoth::Left(left), + Self::Right(ref mut right) => EitherOrBoth::Right(right), + Self::Both(ref mut left, ref mut right) => EitherOrBoth::Both(left, right), } } /// Convert `EitherOrBoth` to `EitherOrBoth`. pub fn flip(self) -> EitherOrBoth { match self { - EitherOrBoth::Left(a) => EitherOrBoth::Right(a), - EitherOrBoth::Right(b) => EitherOrBoth::Left(b), - EitherOrBoth::Both(a, b) => EitherOrBoth::Both(b, a), + Self::Left(a) => EitherOrBoth::Right(a), + Self::Right(b) => EitherOrBoth::Left(b), + Self::Both(a, b) => EitherOrBoth::Both(b, a), } } @@ -205,9 +205,9 @@ impl EitherOrBoth { F: FnOnce(A) -> M, { match self { - EitherOrBoth::Both(a, b) => EitherOrBoth::Both(f(a), b), - EitherOrBoth::Left(a) => EitherOrBoth::Left(f(a)), - EitherOrBoth::Right(b) => EitherOrBoth::Right(b), + Self::Both(a, b) => EitherOrBoth::Both(f(a), b), + Self::Left(a) => EitherOrBoth::Left(f(a)), + Self::Right(b) => EitherOrBoth::Right(b), } } @@ -218,9 +218,9 @@ impl EitherOrBoth { F: FnOnce(B) -> M, { match self { - EitherOrBoth::Left(a) => EitherOrBoth::Left(a), - EitherOrBoth::Right(b) => EitherOrBoth::Right(f(b)), - EitherOrBoth::Both(a, b) => EitherOrBoth::Both(a, f(b)), + Self::Left(a) => EitherOrBoth::Left(a), + Self::Right(b) => EitherOrBoth::Right(f(b)), + Self::Both(a, b) => EitherOrBoth::Both(a, f(b)), } } @@ -233,9 +233,9 @@ impl EitherOrBoth { G: FnOnce(B) -> R, { match self { - EitherOrBoth::Left(a) => EitherOrBoth::Left(f(a)), - EitherOrBoth::Right(b) => EitherOrBoth::Right(g(b)), - EitherOrBoth::Both(a, b) => EitherOrBoth::Both(f(a), g(b)), + Self::Left(a) => EitherOrBoth::Left(f(a)), + Self::Right(b) => EitherOrBoth::Right(g(b)), + Self::Both(a, b) => EitherOrBoth::Both(f(a), g(b)), } } @@ -246,8 +246,8 @@ impl EitherOrBoth { F: FnOnce(A) -> EitherOrBoth, { match self { - EitherOrBoth::Left(a) | EitherOrBoth::Both(a, _) => f(a), - EitherOrBoth::Right(b) => EitherOrBoth::Right(b), + Self::Left(a) | Self::Both(a, _) => f(a), + Self::Right(b) => EitherOrBoth::Right(b), } } @@ -258,8 +258,8 @@ impl EitherOrBoth { F: FnOnce(B) -> EitherOrBoth, { match self { - EitherOrBoth::Left(a) => EitherOrBoth::Left(a), - EitherOrBoth::Right(b) | EitherOrBoth::Both(_, b) => f(b), + Self::Left(a) => EitherOrBoth::Left(a), + Self::Right(b) | Self::Both(_, b) => f(b), } } @@ -284,9 +284,9 @@ impl EitherOrBoth { /// ``` pub fn or(self, l: A, r: B) -> (A, B) { match self { - EitherOrBoth::Left(inner_l) => (inner_l, r), - EitherOrBoth::Right(inner_r) => (l, inner_r), - EitherOrBoth::Both(inner_l, inner_r) => (inner_l, inner_r), + Self::Left(inner_l) => (inner_l, r), + Self::Right(inner_r) => (l, inner_r), + Self::Both(inner_l, inner_r) => (inner_l, inner_r), } } @@ -299,9 +299,9 @@ impl EitherOrBoth { B: Default, { match self { - EitherOrBoth::Left(l) => (l, B::default()), - EitherOrBoth::Right(r) => (A::default(), r), - EitherOrBoth::Both(l, r) => (l, r), + Self::Left(l) => (l, B::default()), + Self::Right(r) => (A::default(), r), + Self::Both(l, r) => (l, r), } } @@ -321,9 +321,9 @@ impl EitherOrBoth { /// ``` pub fn or_else A, R: FnOnce() -> B>(self, l: L, r: R) -> (A, B) { match self { - EitherOrBoth::Left(inner_l) => (inner_l, r()), - EitherOrBoth::Right(inner_r) => (l(), inner_r), - EitherOrBoth::Both(inner_l, inner_r) => (inner_l, inner_r), + Self::Left(inner_l) => (inner_l, r()), + Self::Right(inner_r) => (l(), inner_r), + Self::Both(inner_l, inner_r) => (inner_l, inner_r), } } @@ -346,8 +346,8 @@ impl EitherOrBoth { F: FnOnce() -> A, { match self { - EitherOrBoth::Left(left) | EitherOrBoth::Both(left, _) => left, - EitherOrBoth::Right(_) => self.insert_left(f()), + Self::Left(left) | Self::Both(left, _) => left, + Self::Right(_) => self.insert_left(f()), } } @@ -358,8 +358,8 @@ impl EitherOrBoth { F: FnOnce() -> B, { match self { - EitherOrBoth::Right(right) | EitherOrBoth::Both(_, right) => right, - EitherOrBoth::Left(_) => self.insert_right(f()), + Self::Right(right) | Self::Both(_, right) => right, + Self::Left(_) => self.insert_right(f()), } } @@ -381,21 +381,21 @@ impl EitherOrBoth { /// ``` pub fn insert_left(&mut self, val: A) -> &mut A { match self { - EitherOrBoth::Left(left) | EitherOrBoth::Both(left, _) => { + Self::Left(left) | Self::Both(left, _) => { *left = val; left } - EitherOrBoth::Right(right) => { + Self::Right(right) => { // This is like a map in place operation. We move out of the reference, // change the value, and then move back into the reference. unsafe { // SAFETY: We know this pointer is valid for reading since we got it from a reference. let right = std::ptr::read(right as *mut _); // SAFETY: Again, we know the pointer is valid since we got it from a reference. - std::ptr::write(self as *mut _, EitherOrBoth::Both(val, right)); + std::ptr::write(self as *mut _, Self::Both(val, right)); } - if let EitherOrBoth::Both(left, _) = self { + if let Self::Both(left, _) = self { left } else { // SAFETY: The above pattern will always match, since we just @@ -423,20 +423,20 @@ impl EitherOrBoth { /// ``` pub fn insert_right(&mut self, val: B) -> &mut B { match self { - EitherOrBoth::Right(right) | EitherOrBoth::Both(_, right) => { + Self::Right(right) | Self::Both(_, right) => { *right = val; right } - EitherOrBoth::Left(left) => { + Self::Left(left) => { // This is like a map in place operation. We move out of the reference, // change the value, and then move back into the reference. unsafe { // SAFETY: We know this pointer is valid for reading since we got it from a reference. let left = std::ptr::read(left as *mut _); // SAFETY: Again, we know the pointer is valid since we got it from a reference. - std::ptr::write(self as *mut _, EitherOrBoth::Both(left, val)); + std::ptr::write(self as *mut _, Self::Both(left, val)); } - if let EitherOrBoth::Both(_, right) = self { + if let Self::Both(_, right) = self { right } else { // SAFETY: The above pattern will always match, since we just @@ -450,8 +450,8 @@ impl EitherOrBoth { /// Set `self` to `Both(..)`, containing the specified left and right values, /// and returns a mutable reference to those values. pub fn insert_both(&mut self, left: A, right: B) -> (&mut A, &mut B) { - *self = EitherOrBoth::Both(left, right); - if let EitherOrBoth::Both(left, right) = self { + *self = Self::Both(left, right); + if let Self::Both(left, right) = self { (left, right) } else { // SAFETY: The above pattern will always match, since we just @@ -485,9 +485,9 @@ impl EitherOrBoth { F: FnOnce(T, T) -> T, { match self { - EitherOrBoth::Left(a) => a, - EitherOrBoth::Right(b) => b, - EitherOrBoth::Both(a, b) => f(a, b), + Self::Left(a) => a, + Self::Right(b) => b, + Self::Both(a, b) => f(a, b), } } } @@ -496,9 +496,9 @@ impl EitherOrBoth { impl Into>> for EitherOrBoth { fn into(self) -> Option> { match self { - EitherOrBoth::Left(l) => Some(Either::Left(l)), - EitherOrBoth::Right(r) => Some(Either::Right(r)), - EitherOrBoth::Both(..) => None, + Self::Left(l) => Some(Either::Left(l)), + Self::Right(r) => Some(Either::Right(r)), + Self::Both(..) => None, } } } @@ -506,8 +506,8 @@ impl Into>> for EitherOrBoth { impl From> for EitherOrBoth { fn from(either: Either) -> Self { match either { - Either::Left(l) => EitherOrBoth::Left(l), - Either::Right(l) => EitherOrBoth::Right(l), + Either::Left(l) => Self::Left(l), + Either::Right(l) => Self::Right(l), } } } diff --git a/src/groupbylazy.rs b/src/groupbylazy.rs index 6279899d0..ab553b414 100644 --- a/src/groupbylazy.rs +++ b/src/groupbylazy.rs @@ -29,7 +29,7 @@ struct ChunkIndex { impl ChunkIndex { #[inline(always)] fn new(size: usize) -> Self { - ChunkIndex { + Self { size, index: 0, key: 0, diff --git a/src/kmerge_impl.rs b/src/kmerge_impl.rs index af1462679..7f1e50e94 100644 --- a/src/kmerge_impl.rs +++ b/src/kmerge_impl.rs @@ -27,9 +27,9 @@ where I: Iterator, { /// Constructs a `HeadTail` from an `Iterator`. Returns `None` if the `Iterator` is empty. - fn new(mut it: I) -> Option> { + fn new(mut it: I) -> Option { let head = it.next(); - head.map(|h| HeadTail { head: h, tail: it }) + head.map(|h| Self { head: h, tail: it }) } /// Get the next element and update `head`, returning the old head in `Some`. diff --git a/src/lazy_buffer.rs b/src/lazy_buffer.rs index 38c7d405b..5cb039a63 100644 --- a/src/lazy_buffer.rs +++ b/src/lazy_buffer.rs @@ -14,8 +14,8 @@ impl LazyBuffer where I: Iterator, { - pub fn new(it: I) -> LazyBuffer { - LazyBuffer { + pub fn new(it: I) -> Self { + Self { it: it.fuse(), buffer: Vec::new(), } diff --git a/src/lib.rs b/src/lib.rs index 5845b9496..938f687b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4076,15 +4076,15 @@ impl FoldWhile { /// Return the value in the continue or done. pub fn into_inner(self) -> T { match self { - FoldWhile::Continue(x) | FoldWhile::Done(x) => x, + Self::Continue(x) | Self::Done(x) => x, } } /// Return true if `self` is `Done`, false if it is `Continue`. pub fn is_done(&self) -> bool { match *self { - FoldWhile::Continue(_) => false, - FoldWhile::Done(_) => true, + Self::Continue(_) => false, + Self::Done(_) => true, } } } diff --git a/src/minmax.rs b/src/minmax.rs index e522bcb4f..802b1e2f0 100644 --- a/src/minmax.rs +++ b/src/minmax.rs @@ -37,9 +37,9 @@ impl MinMaxResult { /// ``` pub fn into_option(self) -> Option<(T, T)> { match self { - MinMaxResult::NoElements => None, - MinMaxResult::OneElement(x) => Some((x.clone(), x)), - MinMaxResult::MinMax(x, y) => Some((x, y)), + Self::NoElements => None, + Self::OneElement(x) => Some((x.clone(), x)), + Self::MinMax(x, y) => Some((x, y)), } } } diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index f65941965..b1cfc3d5f 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -34,7 +34,7 @@ where T: HomogeneousTuple, { fn new(buf: T::Buffer) -> Self { - TupleBuffer { cur: 0, buf } + Self { cur: 0, buf } } } diff --git a/src/zip_longest.rs b/src/zip_longest.rs index 27d9f3ab6..e53733542 100644 --- a/src/zip_longest.rs +++ b/src/zip_longest.rs @@ -59,7 +59,7 @@ where Self: Sized, F: FnMut(B, Self::Item) -> B, { - let ZipLongest { a, mut b } = self; + let Self { a, mut b } = self; init = a.fold(init, |init, a| match b.next() { Some(b) => f(init, EitherOrBoth::Both(a, b)), None => f(init, EitherOrBoth::Left(a)), diff --git a/tests/quick.rs b/tests/quick.rs index 0ca32f49a..dffcd22f6 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -38,7 +38,7 @@ impl HintKind for Exact { impl qc::Arbitrary for Exact { fn arbitrary(_: &mut G) -> Self { - Exact {} + Self {} } } @@ -69,7 +69,7 @@ impl qc::Arbitrary for Inexact { // Compensate for quickcheck using extreme values too rarely let ue_choices = &[0, ue_value, usize::max_value()]; let oe_choices = &[0, oe_value, usize::max_value()]; - Inexact { + Self { underestimate: *ue_choices.choose(g).unwrap(), overestimate: *oe_choices.choose(g).unwrap(), } @@ -79,7 +79,7 @@ impl qc::Arbitrary for Inexact { let underestimate_value = self.underestimate; let overestimate_value = self.overestimate; Box::new(underestimate_value.shrink().flat_map(move |ue_value| { - overestimate_value.shrink().map(move |oe_value| Inexact { + overestimate_value.shrink().map(move |oe_value| Self { underestimate: ue_value, overestimate: oe_value, }) @@ -108,7 +108,7 @@ where HK: HintKind, { fn new(it: Range, hint_kind: HK) -> Self { - Iter { + Self { iterator: it, fuse_flag: 0, hint_kind, @@ -166,16 +166,16 @@ where HK: HintKind, { fn arbitrary(g: &mut G) -> Self { - Iter::new(T::arbitrary(g)..T::arbitrary(g), HK::arbitrary(g)) + Self::new(T::arbitrary(g)..T::arbitrary(g), HK::arbitrary(g)) } - fn shrink(&self) -> Box>> { + fn shrink(&self) -> Box> { let r = self.iterator.clone(); let hint_kind = self.hint_kind; Box::new(r.start.shrink().flat_map(move |a| { r.end .shrink() - .map(move |b| Iter::new(a.clone()..b, hint_kind)) + .map(move |b| Self::new(a.clone()..b, hint_kind)) })) } } @@ -231,7 +231,7 @@ where let iter_count = g.gen_range(0, MAX_ITER_COUNT + 1); let hint_kind = qc::Arbitrary::arbitrary(g); - ShiftRange { + Self { range_start, range_end, start_step, @@ -1307,14 +1307,14 @@ quickcheck! { #[derive(Clone, Debug, PartialEq, Eq)] struct Val(u32, u32); -impl PartialOrd for Val { - fn partial_cmp(&self, other: &Val) -> Option { +impl PartialOrd for Val { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Val { - fn cmp(&self, other: &Val) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.0.cmp(&other.0) } } @@ -1322,10 +1322,10 @@ impl Ord for Val { impl qc::Arbitrary for Val { fn arbitrary(g: &mut G) -> Self { let (x, y) = <(u32, u32)>::arbitrary(g); - Val(x, y) + Self(x, y) } fn shrink(&self) -> Box> { - Box::new((self.0, self.1).shrink().map(|(x, y)| Val(x, y))) + Box::new((self.0, self.1).shrink().map(|(x, y)| Self(x, y))) } } diff --git a/tests/test_core.rs b/tests/test_core.rs index 86625c8cf..263e1a7d3 100644 --- a/tests/test_core.rs +++ b/tests/test_core.rs @@ -237,7 +237,7 @@ fn count_clones() { fn clone(&self) -> Self { let n = self.n.get(); self.n.set(n + 1); - Foo { + Self { n: Cell::new(n + 1), } } diff --git a/tests/test_std.rs b/tests/test_std.rs index 24429e919..063eca049 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -540,7 +540,7 @@ where impl qc::Arbitrary for RandIter { fn arbitrary(g: &mut G) -> Self { - RandIter { + Self { idx: 0, len: g.size(), rng: R::seed_from_u64(g.next_u64()), @@ -1263,14 +1263,14 @@ fn extrema_set() { #[derive(Clone, Debug, PartialEq, Eq)] struct Val(u32, u32); - impl PartialOrd for Val { - fn partial_cmp(&self, other: &Val) -> Option { + impl PartialOrd for Val { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Val { - fn cmp(&self, other: &Val) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.0.cmp(&other.0) } } @@ -1312,14 +1312,14 @@ fn minmax() { #[derive(Clone, Debug, PartialEq, Eq)] struct Val(u32, u32); - impl PartialOrd for Val { - fn partial_cmp(&self, other: &Val) -> Option { + impl PartialOrd for Val { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Val { - fn cmp(&self, other: &Val) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.0.cmp(&other.0) } }