Skip to content

Commit 0e3b246

Browse files
authored
Address various clippy warnings (tokio-rs#528)
1 parent 68afb40 commit 0e3b246

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

benches/buf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TestBuf {
4646
}
4747
impl Buf for TestBuf {
4848
fn remaining(&self) -> usize {
49-
return self.buf.len() - self.pos;
49+
self.buf.len() - self.pos
5050
}
5151
fn advance(&mut self, cnt: usize) {
5252
self.pos += cnt;

benches/bytes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fn from_long_slice(b: &mut Bencher) {
8888
#[bench]
8989
fn slice_empty(b: &mut Bencher) {
9090
b.iter(|| {
91+
// `clone` is to convert to ARC
9192
let b = Bytes::from(vec![17; 1024]).clone();
9293
for i in 0..1000 {
9394
test::black_box(b.slice(i % 100..i % 100));

clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv = "1.39"

src/bytes.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl Bytes {
262262
let mut ret = self.clone();
263263

264264
ret.len = end - begin;
265-
ret.ptr = unsafe { ret.ptr.offset(begin as isize) };
265+
ret.ptr = unsafe { ret.ptr.add(begin) };
266266

267267
ret
268268
}
@@ -501,7 +501,7 @@ impl Bytes {
501501
// should already be asserted, but debug assert for tests
502502
debug_assert!(self.len >= by, "internal: inc_start out of bounds");
503503
self.len -= by;
504-
self.ptr = self.ptr.offset(by as isize);
504+
self.ptr = self.ptr.add(by);
505505
}
506506
}
507507

@@ -604,7 +604,7 @@ impl<'a> IntoIterator for &'a Bytes {
604604
type IntoIter = core::slice::Iter<'a, u8>;
605605

606606
fn into_iter(self) -> Self::IntoIter {
607-
self.as_slice().into_iter()
607+
self.as_slice().iter()
608608
}
609609
}
610610

@@ -686,7 +686,7 @@ impl PartialOrd<Bytes> for str {
686686

687687
impl PartialEq<Vec<u8>> for Bytes {
688688
fn eq(&self, other: &Vec<u8>) -> bool {
689-
*self == &other[..]
689+
*self == other[..]
690690
}
691691
}
692692

@@ -710,7 +710,7 @@ impl PartialOrd<Bytes> for Vec<u8> {
710710

711711
impl PartialEq<String> for Bytes {
712712
fn eq(&self, other: &String) -> bool {
713-
*self == &other[..]
713+
*self == other[..]
714714
}
715715
}
716716

src/bytes_mut.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl BytesMut {
603603
v.reserve(additional);
604604

605605
// Update the info
606-
self.ptr = vptr(v.as_mut_ptr().offset(off as isize));
606+
self.ptr = vptr(v.as_mut_ptr().add(off));
607607
self.len = v.len() - off;
608608
self.cap = v.capacity() - off;
609609
}
@@ -818,7 +818,7 @@ impl BytesMut {
818818
// Updating the start of the view is setting `ptr` to point to the
819819
// new start and updating the `len` field to reflect the new length
820820
// of the view.
821-
self.ptr = vptr(self.ptr.as_ptr().offset(start as isize));
821+
self.ptr = vptr(self.ptr.as_ptr().add(start));
822822

823823
if self.len >= start {
824824
self.len -= start;
@@ -842,7 +842,7 @@ impl BytesMut {
842842
return Ok(());
843843
}
844844

845-
let ptr = unsafe { self.ptr.as_ptr().offset(self.len as isize) };
845+
let ptr = unsafe { self.ptr.as_ptr().add(self.len) };
846846
if ptr == other.ptr.as_ptr()
847847
&& self.kind() == KIND_ARC
848848
&& other.kind() == KIND_ARC
@@ -931,7 +931,7 @@ impl BytesMut {
931931
#[inline]
932932
fn uninit_slice(&mut self) -> &mut UninitSlice {
933933
unsafe {
934-
let ptr = self.ptr.as_ptr().offset(self.len as isize);
934+
let ptr = self.ptr.as_ptr().add(self.len);
935935
let len = self.cap - self.len;
936936

937937
UninitSlice::from_raw_parts_mut(ptr, len)
@@ -1178,7 +1178,7 @@ impl<'a> IntoIterator for &'a BytesMut {
11781178
type IntoIter = core::slice::Iter<'a, u8>;
11791179

11801180
fn into_iter(self) -> Self::IntoIter {
1181-
self.as_ref().into_iter()
1181+
self.as_ref().iter()
11821182
}
11831183
}
11841184

@@ -1207,7 +1207,7 @@ impl<'a> Extend<&'a u8> for BytesMut {
12071207
where
12081208
T: IntoIterator<Item = &'a u8>,
12091209
{
1210-
self.extend(iter.into_iter().map(|b| *b))
1210+
self.extend(iter.into_iter().copied())
12111211
}
12121212
}
12131213

@@ -1219,7 +1219,7 @@ impl FromIterator<u8> for BytesMut {
12191219

12201220
impl<'a> FromIterator<&'a u8> for BytesMut {
12211221
fn from_iter<T: IntoIterator<Item = &'a u8>>(into_iter: T) -> Self {
1222-
BytesMut::from_iter(into_iter.into_iter().map(|b| *b))
1222+
BytesMut::from_iter(into_iter.into_iter().copied())
12231223
}
12241224
}
12251225

@@ -1409,7 +1409,7 @@ impl PartialOrd<BytesMut> for str {
14091409

14101410
impl PartialEq<Vec<u8>> for BytesMut {
14111411
fn eq(&self, other: &Vec<u8>) -> bool {
1412-
*self == &other[..]
1412+
*self == other[..]
14131413
}
14141414
}
14151415

@@ -1433,7 +1433,7 @@ impl PartialOrd<BytesMut> for Vec<u8> {
14331433

14341434
impl PartialEq<String> for BytesMut {
14351435
fn eq(&self, other: &String) -> bool {
1436-
*self == &other[..]
1436+
*self == other[..]
14371437
}
14381438
}
14391439

@@ -1499,13 +1499,13 @@ impl PartialOrd<BytesMut> for &str {
14991499

15001500
impl PartialEq<BytesMut> for Bytes {
15011501
fn eq(&self, other: &BytesMut) -> bool {
1502-
&other[..] == &self[..]
1502+
other[..] == self[..]
15031503
}
15041504
}
15051505

15061506
impl PartialEq<Bytes> for BytesMut {
15071507
fn eq(&self, other: &Bytes) -> bool {
1508-
&other[..] == &self[..]
1508+
other[..] == self[..]
15091509
}
15101510
}
15111511

src/fmt/debug.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Debug for BytesRef<'_> {
2525
} else if b == b'\0' {
2626
write!(f, "\\0")?;
2727
// ASCII printable
28-
} else if b >= 0x20 && b < 0x7f {
28+
} else if (0x20..0x7f).contains(&b) {
2929
write!(f, "{}", b as char)?;
3030
} else {
3131
write!(f, "\\x{:02x}", b)?;
@@ -38,12 +38,12 @@ impl Debug for BytesRef<'_> {
3838

3939
impl Debug for Bytes {
4040
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
41-
Debug::fmt(&BytesRef(&self.as_ref()), f)
41+
Debug::fmt(&BytesRef(self.as_ref()), f)
4242
}
4343
}
4444

4545
impl Debug for BytesMut {
4646
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
47-
Debug::fmt(&BytesRef(&self.as_ref()), f)
47+
Debug::fmt(&BytesRef(self.as_ref()), f)
4848
}
4949
}

tests/test_bytes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut};
44

55
use std::usize;
66

7-
const LONG: &'static [u8] = b"mary had a little lamb, little lamb, little lamb";
8-
const SHORT: &'static [u8] = b"hello world";
7+
const LONG: &[u8] = b"mary had a little lamb, little lamb, little lamb";
8+
const SHORT: &[u8] = b"hello world";
99

1010
fn is_sync<T: Sync>() {}
1111
fn is_send<T: Send>() {}
@@ -874,7 +874,7 @@ fn from_iter_no_size_hint() {
874874

875875
fn test_slice_ref(bytes: &Bytes, start: usize, end: usize, expected: &[u8]) {
876876
let slice = &(bytes.as_ref()[start..end]);
877-
let sub = bytes.slice_ref(&slice);
877+
let sub = bytes.slice_ref(slice);
878878
assert_eq!(&sub[..], expected);
879879
}
880880

@@ -894,7 +894,7 @@ fn slice_ref_empty() {
894894
let bytes = Bytes::from(&b""[..]);
895895
let slice = &(bytes.as_ref()[0..0]);
896896

897-
let sub = bytes.slice_ref(&slice);
897+
let sub = bytes.slice_ref(slice);
898898
assert_eq!(&sub[..], b"");
899899
}
900900

tests/test_bytes_odd_alloc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ unsafe impl GlobalAlloc for Odd {
2424
};
2525
let ptr = System.alloc(new_layout);
2626
if !ptr.is_null() {
27-
let ptr = ptr.offset(1);
28-
ptr
27+
ptr.offset(1)
2928
} else {
3029
ptr
3130
}

0 commit comments

Comments
 (0)