Skip to content

Commit 1b8852f

Browse files
authored
Clippy-suggested code improvements. (#80)
1 parent 163aa64 commit 1b8852f

File tree

11 files changed

+34
-38
lines changed

11 files changed

+34
-38
lines changed

src/captured.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl From<Captured> for CapturedBuilder {
269269

270270
struct CapturedWriter<'a>(&'a mut BytesMut);
271271

272-
impl<'a> io::Write for CapturedWriter<'a> {
272+
impl io::Write for CapturedWriter<'_> {
273273
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
274274
self.0.extend_from_slice(buf);
275275
Ok(buf.len())

src/decode/source.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait Source {
136136
}
137137
}
138138

139-
impl<'a, T: Source> Source for &'a mut T {
139+
impl<T: Source> Source for &'_ mut T {
140140
type Error = T::Error;
141141

142142
fn request(&mut self, len: usize) -> Result<usize, Self::Error> {
@@ -340,7 +340,7 @@ impl<'a> SliceSource<'a> {
340340
}
341341
}
342342

343-
impl<'a> Source for SliceSource<'a> {
343+
impl Source for SliceSource<'_> {
344344
type Error = Infallible;
345345

346346
fn pos(&self) -> Pos {

src/encode/primitive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub trait PrimitiveContent: Sized {
7979

8080
//--- Blanket impls
8181

82-
impl<'a, T: PrimitiveContent> PrimitiveContent for &'a T {
82+
impl<T: PrimitiveContent> PrimitiveContent for &'_ T {
8383
const TAG: Tag = T::TAG;
8484

8585
fn encoded_len(&self, mode: Mode) -> usize {
@@ -323,7 +323,7 @@ impl PrimitiveContent for bool {
323323
}
324324
}
325325

326-
impl<'a> PrimitiveContent for &'a [u8] {
326+
impl PrimitiveContent for &'_ [u8] {
327327
const TAG: Tag = Tag::OCTET_STRING;
328328

329329
fn encoded_len(&self, _: Mode) -> usize {

src/encode/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait Values {
5555

5656
//--- Blanket impls
5757

58-
impl<'a, T: Values> Values for &'a T {
58+
impl<T: Values> Values for &'_ T {
5959
fn encoded_len(&self, mode: Mode) -> usize {
6060
(*self).encoded_len(mode)
6161
}
@@ -358,7 +358,7 @@ impl<T: IntoIterator> IntoIterator for Iter<T> {
358358
}
359359
}
360360

361-
impl<'a, T: Clone + IntoIterator> IntoIterator for &'a Iter<T> {
361+
impl<T: Clone + IntoIterator> IntoIterator for &'_ Iter<T> {
362362
type Item = <T as IntoIterator>::Item;
363363
type IntoIter = <T as IntoIterator>::IntoIter;
364364

src/int.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl hash::Hash for Integer {
397397

398398
//--- encode::PrimitiveContent
399399

400-
impl<'a> PrimitiveContent for &'a Integer {
400+
impl PrimitiveContent for &'_ Integer {
401401
const TAG: Tag = Tag::INTEGER;
402402

403403
fn encoded_len(&self, _mode: Mode) -> usize {
@@ -528,7 +528,7 @@ impl Unsigned {
528528
1 => Ok(prim.take_u8()?.into()),
529529
2 => {
530530
Ok(
531-
u16::from(prim.take_u8()?) << 8 |
531+
(u16::from(prim.take_u8()?) << 8) |
532532
u16::from(prim.take_u8()?)
533533
)
534534
}
@@ -537,7 +537,7 @@ impl Unsigned {
537537
return Err(prim.content_err("invalid integer"))
538538
}
539539
let res = {
540-
u16::from(prim.take_u8()?) << 8 |
540+
(u16::from(prim.take_u8()?) << 8) |
541541
u16::from(prim.take_u8()?)
542542
};
543543
if res < 0x8000 {
@@ -654,7 +654,7 @@ impl AsRef<[u8]> for Unsigned {
654654

655655
//--- endode::PrimitiveContent
656656

657-
impl<'a> PrimitiveContent for &'a Unsigned {
657+
impl PrimitiveContent for &'_ Unsigned {
658658
const TAG: Tag = Tag::INTEGER;
659659

660660
fn encoded_len(&self, mode: Mode) -> usize {

src/length.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Length {
7575
}
7676
0x82 => {
7777
let len =
78-
(source.take_u8()? as usize) << 8 |
78+
((source.take_u8()? as usize) << 8) |
7979
(source.take_u8()? as usize);
8080
if mode.is_ber() || len > 255 {
8181
Ok(Length::Definite(len))
@@ -86,8 +86,8 @@ impl Length {
8686
}
8787
0x83 => {
8888
let len =
89-
(source.take_u8()? as usize) << 16 |
90-
(source.take_u8()? as usize) << 8 |
89+
((source.take_u8()? as usize) << 16) |
90+
((source.take_u8()? as usize) << 8) |
9191
(source.take_u8()? as usize);
9292
if mode.is_ber() || len > 0xFFFF {
9393
Ok(Length::Definite(len))
@@ -98,9 +98,9 @@ impl Length {
9898
}
9999
0x84 => {
100100
let len =
101-
(source.take_u8()? as usize) << 24 |
102-
(source.take_u8()? as usize) << 16 |
103-
(source.take_u8()? as usize) << 8 |
101+
((source.take_u8()? as usize) << 24) |
102+
((source.take_u8()? as usize) << 16) |
103+
((source.take_u8()? as usize) << 8) |
104104
(source.take_u8()? as usize);
105105
if mode.is_ber() || len > 0x00FF_FFFF {
106106
Ok(Length::Definite(len))

src/oid.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a> Component<'a> {
370370
}
371371
let mut res = 0;
372372
for &ch in self.slice {
373-
res = res << 7 | u32::from(ch & 0x7F);
373+
res = (res << 7) | u32::from(ch & 0x7F);
374374
}
375375
match self.position {
376376
Position::First => {
@@ -400,18 +400,18 @@ impl<'a> Component<'a> {
400400

401401
//--- PartialEq and Eq
402402

403-
impl<'a> PartialEq for Component<'a> {
403+
impl PartialEq for Component<'_> {
404404
fn eq(&self, other: &Self) -> bool {
405405
self.position == other.position && self.slice == other.slice
406406
}
407407
}
408408

409-
impl<'a> Eq for Component<'a> { }
409+
impl Eq for Component<'_> { }
410410

411411

412412
//--- Display
413413

414-
impl<'a> fmt::Display for Component<'a> {
414+
impl fmt::Display for Component<'_> {
415415
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
416416
// XXX This can’t deal correctly with overly large components.
417417
// Since this is a really rare (if not non-existant) case,

src/string/bit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl encode::PrimitiveContent for BitString {
275275
#[derive(Clone, Debug)]
276276
pub struct BitStringIter<'a>(::std::slice::Iter<'a, u8>);
277277

278-
impl<'a> Iterator for BitStringIter<'a> {
278+
impl Iterator for BitStringIter<'_> {
279279
type Item = u8;
280280

281281
fn next(&mut self) -> Option<u8> {

src/string/octet.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -678,16 +678,12 @@ impl<'a> OctetStringOctets<'a> {
678678
}
679679
}
680680

681-
impl<'a> Iterator for OctetStringOctets<'a> {
681+
impl Iterator for OctetStringOctets<'_> {
682682
type Item = u8;
683683

684684
fn next(&mut self) -> Option<u8> {
685685
while self.cur.is_empty() {
686-
let next = match self.iter.next() {
687-
Some(some) => some,
688-
None => return None,
689-
};
690-
self.cur = next;
686+
self.cur = self.iter.next()?;
691687
}
692688
let res = self.cur[0];
693689
self.cur = &self.cur[1..];

src/string/restricted.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'a, L: CharSet> RestrictedStringChars<'a, L> {
308308
}
309309
}
310310

311-
impl<'a, L: CharSet> Iterator for RestrictedStringChars<'a, L> {
311+
impl<L: CharSet> Iterator for RestrictedStringChars<'_, L> {
312312
type Item = char;
313313

314314
fn next(&mut self) -> Option<char> {
@@ -361,7 +361,7 @@ impl CharSet for Utf8CharSet {
361361
if first < 0xE0 {
362362
return Ok(Some(unsafe {
363363
char::from_u32_unchecked(
364-
(u32::from(first & 0x1F)) << 6 |
364+
((u32::from(first & 0x1F)) << 6) |
365365
u32::from(second & 0x3F)
366366
)
367367
}))
@@ -376,8 +376,8 @@ impl CharSet for Utf8CharSet {
376376
if first < 0xF0 {
377377
return Ok(Some(unsafe {
378378
char::from_u32_unchecked(
379-
(u32::from(first & 0x0F)) << 12 |
380-
(u32::from(second & 0x3F)) << 6 |
379+
((u32::from(first & 0x0F)) << 12) |
380+
((u32::from(second & 0x3F)) << 6) |
381381
u32::from(third & 0x3F)
382382
)
383383
}))
@@ -391,9 +391,9 @@ impl CharSet for Utf8CharSet {
391391
}
392392
Ok(Some(unsafe {
393393
char::from_u32_unchecked(
394-
(u32::from(first & 0x07)) << 18 |
395-
(u32::from(second & 0x3F)) << 12 |
396-
(u32::from(third & 0x3F)) << 6 |
394+
((u32::from(first & 0x07)) << 18) |
395+
((u32::from(second & 0x3F)) << 12) |
396+
((u32::from(third & 0x3F)) << 6) |
397397
u32::from(fourth & 0x3F)
398398
)
399399
}))

src/tag.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ impl Tag {
351351
} else if Tag::LAST_OCTET_MASK & self.0[2] == 0 {
352352
// It's a multibyte that starts in the second octet and ends in
353353
// the third octet
354-
u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 7
354+
(u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 7)
355355
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2])
356356
} else {
357357
// It's a multibyte that spans the first three octets
358-
u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 14
359-
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2]) << 7
358+
(u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 14)
359+
| (u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2]) << 7)
360360
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[3])
361361
}
362362
}

0 commit comments

Comments
 (0)