Skip to content

Commit 2c487f0

Browse files
Use Self
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 <[email protected]>
1 parent a22553e commit 2c487f0

16 files changed

+53
-53
lines changed

benches/extra/zipslices.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
#[inline(always)]
5959
pub fn from_slices(a: T, b: U) -> Self {
6060
let minl = cmp::min(a.len(), b.len());
61-
ZipSlices {
61+
Self {
6262
t: a,
6363
u: b,
6464
len: minl,

examples/iris.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum ParseError {
2525

2626
impl From<ParseFloatError> for ParseError {
2727
fn from(err: ParseFloatError) -> Self {
28-
ParseError::Numeric(err)
28+
Self::Numeric(err)
2929
}
3030
}
3131

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

3636
fn from_str(s: &str) -> Result<Self, Self::Err> {
37-
let mut iris = Iris {
37+
let mut iris = Self {
3838
name: "".into(),
3939
data: [0.; 4],
4040
};

src/adaptors/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ where
218218
/// Split the `PutBack` into its parts.
219219
#[inline]
220220
pub fn into_parts(self) -> (Option<I::Item>, I) {
221-
let PutBack { top, iter } = self;
221+
let Self { top, iter } = self;
222222
(top, iter)
223223
}
224224

@@ -689,7 +689,7 @@ pub struct Tuple1Combination<I> {
689689

690690
impl<I> From<I> for Tuple1Combination<I> {
691691
fn from(iter: I) -> Self {
692-
Tuple1Combination { iter }
692+
Self { iter }
693693
}
694694
}
695695

src/adaptors/multi_product.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ where
9595

9696
if last.in_progress() {
9797
true
98-
} else if MultiProduct::iterate_last(rest, state) {
98+
} else if Self::iterate_last(rest, state) {
9999
last.reset();
100100
last.iterate();
101101
// If iterator is None twice consecutively, then iterator is
@@ -139,7 +139,7 @@ where
139139
I::Item: Clone,
140140
{
141141
fn new(iter: I) -> Self {
142-
MultiProductIter {
142+
Self {
143143
cur: None,
144144
iter: iter.clone(),
145145
iter_orig: iter,
@@ -171,7 +171,7 @@ where
171171
type Item = Vec<I::Item>;
172172

173173
fn next(&mut self) -> Option<Self::Item> {
174-
if MultiProduct::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
174+
if Self::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
175175
Some(self.curr_iterator())
176176
} else {
177177
None

src/duplicates_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod private {
2222

2323
impl<I: Iterator, Key: Eq + Hash, F> DuplicatesBy<I, Key, F> {
2424
pub(crate) fn new(iter: I, key_method: F) -> Self {
25-
DuplicatesBy {
25+
Self {
2626
iter,
2727
meta: Meta {
2828
used: HashMap::new(),
@@ -77,7 +77,7 @@ mod private {
7777
type Item = I::Item;
7878

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

@@ -109,7 +109,7 @@ mod private {
109109
F: KeyMethod<Key, I::Item>,
110110
{
111111
fn next_back(&mut self) -> Option<Self::Item> {
112-
let DuplicatesBy { iter, meta } = self;
112+
let Self { iter, meta } = self;
113113
iter.rev().find_map(|v| meta.filter(v))
114114
}
115115
}

src/either_or_both.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ impl<A, B> EitherOrBoth<A, B> {
301301
B: Default,
302302
{
303303
match self {
304-
EitherOrBoth::Left(l) => (l, B::default()),
305-
EitherOrBoth::Right(r) => (A::default(), r),
306-
EitherOrBoth::Both(l, r) => (l, r),
304+
Left(l) => (l, B::default()),
305+
Right(r) => (A::default(), r),
306+
Both(l, r) => (l, r),
307307
}
308308
}
309309

@@ -498,18 +498,18 @@ impl<T> EitherOrBoth<T, T> {
498498
impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
499499
fn into(self) -> Option<Either<A, B>> {
500500
match self {
501-
EitherOrBoth::Left(l) => Some(Either::Left(l)),
502-
EitherOrBoth::Right(r) => Some(Either::Right(r)),
503-
_ => None,
501+
Left(l) => Some(Either::Left(l)),
502+
Right(r) => Some(Either::Right(r)),
503+
Both(..) => None,
504504
}
505505
}
506506
}
507507

508508
impl<A, B> From<Either<A, B>> for EitherOrBoth<A, B> {
509509
fn from(either: Either<A, B>) -> Self {
510510
match either {
511-
Either::Left(l) => EitherOrBoth::Left(l),
512-
Either::Right(l) => EitherOrBoth::Right(l),
511+
Either::Left(l) => Left(l),
512+
Either::Right(l) => Right(l),
513513
}
514514
}
515515
}

src/groupbylazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ChunkIndex {
2929
impl ChunkIndex {
3030
#[inline(always)]
3131
fn new(size: usize) -> Self {
32-
ChunkIndex {
32+
Self {
3333
size,
3434
index: 0,
3535
key: 0,

src/kmerge_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ where
2727
I: Iterator,
2828
{
2929
/// Constructs a `HeadTail` from an `Iterator`. Returns `None` if the `Iterator` is empty.
30-
fn new(mut it: I) -> Option<HeadTail<I>> {
30+
fn new(mut it: I) -> Option<Self> {
3131
let head = it.next();
32-
head.map(|h| HeadTail { head: h, tail: it })
32+
head.map(|h| Self { head: h, tail: it })
3333
}
3434

3535
/// Get the next element and update `head`, returning the old head in `Some`.

src/lazy_buffer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ impl<I> LazyBuffer<I>
1414
where
1515
I: Iterator,
1616
{
17-
pub fn new(it: I) -> LazyBuffer<I> {
18-
LazyBuffer {
17+
pub fn new(it: I) -> Self {
18+
Self {
1919
it: it.fuse(),
2020
buffer: Vec::new(),
2121
}

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4077,15 +4077,15 @@ impl<T> FoldWhile<T> {
40774077
/// Return the value in the continue or done.
40784078
pub fn into_inner(self) -> T {
40794079
match self {
4080-
FoldWhile::Continue(x) | FoldWhile::Done(x) => x,
4080+
Self::Continue(x) | Self::Done(x) => x,
40814081
}
40824082
}
40834083

40844084
/// Return true if `self` is `Done`, false if it is `Continue`.
40854085
pub fn is_done(&self) -> bool {
40864086
match *self {
4087-
FoldWhile::Continue(_) => false,
4088-
FoldWhile::Done(_) => true,
4087+
Self::Continue(_) => false,
4088+
Self::Done(_) => true,
40894089
}
40904090
}
40914091
}

src/minmax.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl<T: Clone> MinMaxResult<T> {
3737
/// ```
3838
pub fn into_option(self) -> Option<(T, T)> {
3939
match self {
40-
MinMaxResult::NoElements => None,
41-
MinMaxResult::OneElement(x) => Some((x.clone(), x)),
42-
MinMaxResult::MinMax(x, y) => Some((x, y)),
40+
Self::NoElements => None,
41+
Self::OneElement(x) => Some((x.clone(), x)),
42+
Self::MinMax(x, y) => Some((x, y)),
4343
}
4444
}
4545
}

src/tuple_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
T: HomogeneousTuple,
3535
{
3636
fn new(buf: T::Buffer) -> Self {
37-
TupleBuffer { cur: 0, buf }
37+
Self { cur: 0, buf }
3838
}
3939
}
4040

src/zip_longest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
Self: Sized,
6060
F: FnMut(B, Self::Item) -> B,
6161
{
62-
let ZipLongest { a, mut b } = self;
62+
let Self { a, mut b } = self;
6363
init = a.fold(init, |init, a| match b.next() {
6464
Some(b) => f(init, EitherOrBoth::Both(a, b)),
6565
None => f(init, EitherOrBoth::Left(a)),

tests/quick.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl HintKind for Exact {
3838

3939
impl qc::Arbitrary for Exact {
4040
fn arbitrary<G: qc::Gen>(_: &mut G) -> Self {
41-
Exact {}
41+
Self {}
4242
}
4343
}
4444

@@ -69,7 +69,7 @@ impl qc::Arbitrary for Inexact {
6969
// Compensate for quickcheck using extreme values too rarely
7070
let ue_choices = &[0, ue_value, usize::max_value()];
7171
let oe_choices = &[0, oe_value, usize::max_value()];
72-
Inexact {
72+
Self {
7373
underestimate: *ue_choices.choose(g).unwrap(),
7474
overestimate: *oe_choices.choose(g).unwrap(),
7575
}
@@ -79,7 +79,7 @@ impl qc::Arbitrary for Inexact {
7979
let underestimate_value = self.underestimate;
8080
let overestimate_value = self.overestimate;
8181
Box::new(underestimate_value.shrink().flat_map(move |ue_value| {
82-
overestimate_value.shrink().map(move |oe_value| Inexact {
82+
overestimate_value.shrink().map(move |oe_value| Self {
8383
underestimate: ue_value,
8484
overestimate: oe_value,
8585
})
@@ -108,7 +108,7 @@ where
108108
HK: HintKind,
109109
{
110110
fn new(it: Range<T>, hint_kind: HK) -> Self {
111-
Iter {
111+
Self {
112112
iterator: it,
113113
fuse_flag: 0,
114114
hint_kind,
@@ -166,16 +166,16 @@ where
166166
HK: HintKind,
167167
{
168168
fn arbitrary<G: qc::Gen>(g: &mut G) -> Self {
169-
Iter::new(T::arbitrary(g)..T::arbitrary(g), HK::arbitrary(g))
169+
Self::new(T::arbitrary(g)..T::arbitrary(g), HK::arbitrary(g))
170170
}
171171

172-
fn shrink(&self) -> Box<dyn Iterator<Item = Iter<T, HK>>> {
172+
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
173173
let r = self.iterator.clone();
174174
let hint_kind = self.hint_kind;
175175
Box::new(r.start.shrink().flat_map(move |a| {
176176
r.end
177177
.shrink()
178-
.map(move |b| Iter::new(a.clone()..b, hint_kind))
178+
.map(move |b| Self::new(a.clone()..b, hint_kind))
179179
}))
180180
}
181181
}
@@ -231,7 +231,7 @@ where
231231
let iter_count = g.gen_range(0, MAX_ITER_COUNT + 1);
232232
let hint_kind = qc::Arbitrary::arbitrary(g);
233233

234-
ShiftRange {
234+
Self {
235235
range_start,
236236
range_end,
237237
start_step,
@@ -1307,25 +1307,25 @@ quickcheck! {
13071307
#[derive(Clone, Debug, PartialEq, Eq)]
13081308
struct Val(u32, u32);
13091309

1310-
impl PartialOrd<Val> for Val {
1311-
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
1310+
impl PartialOrd<Self> for Val {
1311+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
13121312
Some(self.cmp(other))
13131313
}
13141314
}
13151315

13161316
impl Ord for Val {
1317-
fn cmp(&self, other: &Val) -> Ordering {
1317+
fn cmp(&self, other: &Self) -> Ordering {
13181318
self.0.cmp(&other.0)
13191319
}
13201320
}
13211321

13221322
impl qc::Arbitrary for Val {
13231323
fn arbitrary<G: qc::Gen>(g: &mut G) -> Self {
13241324
let (x, y) = <(u32, u32)>::arbitrary(g);
1325-
Val(x, y)
1325+
Self(x, y)
13261326
}
13271327
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1328-
Box::new((self.0, self.1).shrink().map(|(x, y)| Val(x, y)))
1328+
Box::new((self.0, self.1).shrink().map(|(x, y)| Self(x, y)))
13291329
}
13301330
}
13311331

tests/test_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn count_clones() {
237237
fn clone(&self) -> Self {
238238
let n = self.n.get();
239239
self.n.set(n + 1);
240-
Foo {
240+
Self {
241241
n: Cell::new(n + 1),
242242
}
243243
}

tests/test_std.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ where
540540

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

1266-
impl PartialOrd<Val> for Val {
1267-
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
1266+
impl PartialOrd<Self> for Val {
1267+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
12681268
Some(self.cmp(other))
12691269
}
12701270
}
12711271

12721272
impl Ord for Val {
1273-
fn cmp(&self, other: &Val) -> Ordering {
1273+
fn cmp(&self, other: &Self) -> Ordering {
12741274
self.0.cmp(&other.0)
12751275
}
12761276
}
@@ -1312,14 +1312,14 @@ fn minmax() {
13121312
#[derive(Clone, Debug, PartialEq, Eq)]
13131313
struct Val(u32, u32);
13141314

1315-
impl PartialOrd<Val> for Val {
1316-
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
1315+
impl PartialOrd<Self> for Val {
1316+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
13171317
Some(self.cmp(other))
13181318
}
13191319
}
13201320

13211321
impl Ord for Val {
1322-
fn cmp(&self, other: &Val) -> Ordering {
1322+
fn cmp(&self, other: &Self) -> Ordering {
13231323
self.0.cmp(&other.0)
13241324
}
13251325
}

0 commit comments

Comments
 (0)