Skip to content

Commit

Permalink
Use Self
Browse files Browse the repository at this point in the history
Two simple steps:
- run `cargo clippy --fix -- -D clippy::use_self`
- In `either_or_both`, remove `Self::` as glob use is quite convenient.

https://rust-lang.github.io/rust-clippy/master/index.html#/use_self

Co-Authored-By: Marcel Hellwig <ghpub@cookiesoft.de>
  • Loading branch information
Philippe-Cholet and hellow554 committed Jan 10, 2024
1 parent a22553e commit 2c487f0
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion benches/extra/zipslices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum ParseError {

impl From<ParseFloatError> for ParseError {
fn from(err: ParseFloatError) -> Self {
ParseError::Numeric(err)
Self::Numeric(err)
}
}

Expand All @@ -34,7 +34,7 @@ impl FromStr for Iris {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut iris = Iris {
let mut iris = Self {
name: "".into(),
data: [0.; 4],
};
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
/// Split the `PutBack` into its parts.
#[inline]
pub fn into_parts(self) -> (Option<I::Item>, I) {
let PutBack { top, iter } = self;
let Self { top, iter } = self;
(top, iter)
}

Expand Down Expand Up @@ -689,7 +689,7 @@ pub struct Tuple1Combination<I> {

impl<I> From<I> for Tuple1Combination<I> {
fn from(iter: I) -> Self {
Tuple1Combination { iter }
Self { iter }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/adaptors/multi_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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
Expand Down Expand Up @@ -139,7 +139,7 @@ where
I::Item: Clone,
{
fn new(iter: I) -> Self {
MultiProductIter {
Self {
cur: None,
iter: iter.clone(),
iter_orig: iter,
Expand Down Expand Up @@ -171,7 +171,7 @@ where
type Item = Vec<I::Item>;

fn next(&mut self) -> Option<Self::Item> {
if MultiProduct::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
if Self::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
Some(self.curr_iterator())
} else {
None
Expand Down
6 changes: 3 additions & 3 deletions src/duplicates_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod private {

impl<I: Iterator, Key: Eq + Hash, F> DuplicatesBy<I, Key, F> {
pub(crate) fn new(iter: I, key_method: F) -> Self {
DuplicatesBy {
Self {
iter,
meta: Meta {
used: HashMap::new(),
Expand Down Expand Up @@ -77,7 +77,7 @@ mod private {
type Item = I::Item;

fn next(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.find_map(|v| meta.filter(v))
}

Expand Down Expand Up @@ -109,7 +109,7 @@ mod private {
F: KeyMethod<Key, I::Item>,
{
fn next_back(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.rev().find_map(|v| meta.filter(v))
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ impl<A, B> EitherOrBoth<A, B> {
B: Default,
{
match self {
EitherOrBoth::Left(l) => (l, B::default()),
EitherOrBoth::Right(r) => (A::default(), r),
EitherOrBoth::Both(l, r) => (l, r),
Left(l) => (l, B::default()),
Right(r) => (A::default(), r),
Both(l, r) => (l, r),
}
}

Expand Down Expand Up @@ -498,18 +498,18 @@ impl<T> EitherOrBoth<T, T> {
impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
fn into(self) -> Option<Either<A, B>> {
match self {
EitherOrBoth::Left(l) => Some(Either::Left(l)),
EitherOrBoth::Right(r) => Some(Either::Right(r)),
_ => None,
Left(l) => Some(Either::Left(l)),
Right(r) => Some(Either::Right(r)),
Both(..) => None,
}
}
}

impl<A, B> From<Either<A, B>> for EitherOrBoth<A, B> {
fn from(either: Either<A, B>) -> Self {
match either {
Either::Left(l) => EitherOrBoth::Left(l),
Either::Right(l) => EitherOrBoth::Right(l),
Either::Left(l) => Left(l),
Either::Right(l) => Right(l),
}
}
}
2 changes: 1 addition & 1 deletion src/groupbylazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ChunkIndex {
impl ChunkIndex {
#[inline(always)]
fn new(size: usize) -> Self {
ChunkIndex {
Self {
size,
index: 0,
key: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/kmerge_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HeadTail<I>> {
fn new(mut it: I) -> Option<Self> {
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`.
Expand Down
4 changes: 2 additions & 2 deletions src/lazy_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl<I> LazyBuffer<I>
where
I: Iterator,
{
pub fn new(it: I) -> LazyBuffer<I> {
LazyBuffer {
pub fn new(it: I) -> Self {
Self {
it: it.fuse(),
buffer: Vec::new(),
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4077,15 +4077,15 @@ impl<T> FoldWhile<T> {
/// 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,
}
}
}
6 changes: 3 additions & 3 deletions src/minmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl<T: Clone> MinMaxResult<T> {
/// ```
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)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tuple_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
T: HomogeneousTuple,
{
fn new(buf: T::Buffer) -> Self {
TupleBuffer { cur: 0, buf }
Self { cur: 0, buf }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/zip_longest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
26 changes: 13 additions & 13 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl HintKind for Exact {

impl qc::Arbitrary for Exact {
fn arbitrary<G: qc::Gen>(_: &mut G) -> Self {
Exact {}
Self {}
}
}

Expand Down Expand Up @@ -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(),
}
Expand All @@ -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,
})
Expand Down Expand Up @@ -108,7 +108,7 @@ where
HK: HintKind,
{
fn new(it: Range<T>, hint_kind: HK) -> Self {
Iter {
Self {
iterator: it,
fuse_flag: 0,
hint_kind,
Expand Down Expand Up @@ -166,16 +166,16 @@ where
HK: HintKind,
{
fn arbitrary<G: qc::Gen>(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<dyn Iterator<Item = Iter<T, HK>>> {
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
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))
}))
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1307,25 +1307,25 @@ quickcheck! {
#[derive(Clone, Debug, PartialEq, Eq)]
struct Val(u32, u32);

impl PartialOrd<Val> for Val {
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
impl PartialOrd<Self> for Val {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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)
}
}

impl qc::Arbitrary for Val {
fn arbitrary<G: qc::Gen>(g: &mut G) -> Self {
let (x, y) = <(u32, u32)>::arbitrary(g);
Val(x, y)
Self(x, y)
}
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
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)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ where

impl<T: Clone + Send, R: Clone + Rng + SeedableRng + Send> qc::Arbitrary for RandIter<T, R> {
fn arbitrary<G: qc::Gen>(g: &mut G) -> Self {
RandIter {
Self {
idx: 0,
len: g.size(),
rng: R::seed_from_u64(g.next_u64()),
Expand Down Expand Up @@ -1263,14 +1263,14 @@ fn extrema_set() {
#[derive(Clone, Debug, PartialEq, Eq)]
struct Val(u32, u32);

impl PartialOrd<Val> for Val {
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
impl PartialOrd<Self> for Val {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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)
}
}
Expand Down Expand Up @@ -1312,14 +1312,14 @@ fn minmax() {
#[derive(Clone, Debug, PartialEq, Eq)]
struct Val(u32, u32);

impl PartialOrd<Val> for Val {
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
impl PartialOrd<Self> for Val {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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)
}
}
Expand Down

0 comments on commit 2c487f0

Please sign in to comment.