Skip to content

Clippy-suggested code improvements. #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/captured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl From<Captured> for CapturedBuilder {

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

impl<'a> io::Write for CapturedWriter<'a> {
impl io::Write for CapturedWriter<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
self.0.extend_from_slice(buf);
Ok(buf.len())
Expand Down
4 changes: 2 additions & 2 deletions src/decode/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub trait Source {
}
}

impl<'a, T: Source> Source for &'a mut T {
impl<T: Source> Source for &'_ mut T {
type Error = T::Error;

fn request(&mut self, len: usize) -> Result<usize, Self::Error> {
Expand Down Expand Up @@ -340,7 +340,7 @@ impl<'a> SliceSource<'a> {
}
}

impl<'a> Source for SliceSource<'a> {
impl Source for SliceSource<'_> {
type Error = Infallible;

fn pos(&self) -> Pos {
Expand Down
4 changes: 2 additions & 2 deletions src/encode/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait PrimitiveContent: Sized {

//--- Blanket impls

impl<'a, T: PrimitiveContent> PrimitiveContent for &'a T {
impl<T: PrimitiveContent> PrimitiveContent for &'_ T {
const TAG: Tag = T::TAG;

fn encoded_len(&self, mode: Mode) -> usize {
Expand Down Expand Up @@ -323,7 +323,7 @@ impl PrimitiveContent for bool {
}
}

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

fn encoded_len(&self, _: Mode) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions src/encode/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait Values {

//--- Blanket impls

impl<'a, T: Values> Values for &'a T {
impl<T: Values> Values for &'_ T {
fn encoded_len(&self, mode: Mode) -> usize {
(*self).encoded_len(mode)
}
Expand Down Expand Up @@ -358,7 +358,7 @@ impl<T: IntoIterator> IntoIterator for Iter<T> {
}
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl hash::Hash for Integer {

//--- encode::PrimitiveContent

impl<'a> PrimitiveContent for &'a Integer {
impl PrimitiveContent for &'_ Integer {
const TAG: Tag = Tag::INTEGER;

fn encoded_len(&self, _mode: Mode) -> usize {
Expand Down Expand Up @@ -528,7 +528,7 @@ impl Unsigned {
1 => Ok(prim.take_u8()?.into()),
2 => {
Ok(
u16::from(prim.take_u8()?) << 8 |
(u16::from(prim.take_u8()?) << 8) |
u16::from(prim.take_u8()?)
)
}
Expand All @@ -537,7 +537,7 @@ impl Unsigned {
return Err(prim.content_err("invalid integer"))
}
let res = {
u16::from(prim.take_u8()?) << 8 |
(u16::from(prim.take_u8()?) << 8) |
u16::from(prim.take_u8()?)
};
if res < 0x8000 {
Expand Down Expand Up @@ -654,7 +654,7 @@ impl AsRef<[u8]> for Unsigned {

//--- endode::PrimitiveContent

impl<'a> PrimitiveContent for &'a Unsigned {
impl PrimitiveContent for &'_ Unsigned {
const TAG: Tag = Tag::INTEGER;

fn encoded_len(&self, mode: Mode) -> usize {
Expand Down
12 changes: 6 additions & 6 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Length {
}
0x82 => {
let len =
(source.take_u8()? as usize) << 8 |
((source.take_u8()? as usize) << 8) |
(source.take_u8()? as usize);
if mode.is_ber() || len > 255 {
Ok(Length::Definite(len))
Expand All @@ -86,8 +86,8 @@ impl Length {
}
0x83 => {
let len =
(source.take_u8()? as usize) << 16 |
(source.take_u8()? as usize) << 8 |
((source.take_u8()? as usize) << 16) |
((source.take_u8()? as usize) << 8) |
(source.take_u8()? as usize);
if mode.is_ber() || len > 0xFFFF {
Ok(Length::Definite(len))
Expand All @@ -98,9 +98,9 @@ impl Length {
}
0x84 => {
let len =
(source.take_u8()? as usize) << 24 |
(source.take_u8()? as usize) << 16 |
(source.take_u8()? as usize) << 8 |
((source.take_u8()? as usize) << 24) |
((source.take_u8()? as usize) << 16) |
((source.take_u8()? as usize) << 8) |
(source.take_u8()? as usize);
if mode.is_ber() || len > 0x00FF_FFFF {
Ok(Length::Definite(len))
Expand Down
8 changes: 4 additions & 4 deletions src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a> Component<'a> {
}
let mut res = 0;
for &ch in self.slice {
res = res << 7 | u32::from(ch & 0x7F);
res = (res << 7) | u32::from(ch & 0x7F);
}
match self.position {
Position::First => {
Expand Down Expand Up @@ -400,18 +400,18 @@ impl<'a> Component<'a> {

//--- PartialEq and Eq

impl<'a> PartialEq for Component<'a> {
impl PartialEq for Component<'_> {
fn eq(&self, other: &Self) -> bool {
self.position == other.position && self.slice == other.slice
}
}

impl<'a> Eq for Component<'a> { }
impl Eq for Component<'_> { }


//--- Display

impl<'a> fmt::Display for Component<'a> {
impl fmt::Display for Component<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// XXX This can’t deal correctly with overly large components.
// Since this is a really rare (if not non-existant) case,
Expand Down
2 changes: 1 addition & 1 deletion src/string/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl encode::PrimitiveContent for BitString {
#[derive(Clone, Debug)]
pub struct BitStringIter<'a>(::std::slice::Iter<'a, u8>);

impl<'a> Iterator for BitStringIter<'a> {
impl Iterator for BitStringIter<'_> {
type Item = u8;

fn next(&mut self) -> Option<u8> {
Expand Down
8 changes: 2 additions & 6 deletions src/string/octet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,12 @@ impl<'a> OctetStringOctets<'a> {
}
}

impl<'a> Iterator for OctetStringOctets<'a> {
impl Iterator for OctetStringOctets<'_> {
type Item = u8;

fn next(&mut self) -> Option<u8> {
while self.cur.is_empty() {
let next = match self.iter.next() {
Some(some) => some,
None => return None,
};
self.cur = next;
self.cur = self.iter.next()?;
}
let res = self.cur[0];
self.cur = &self.cur[1..];
Expand Down
14 changes: 7 additions & 7 deletions src/string/restricted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'a, L: CharSet> RestrictedStringChars<'a, L> {
}
}

impl<'a, L: CharSet> Iterator for RestrictedStringChars<'a, L> {
impl<L: CharSet> Iterator for RestrictedStringChars<'_, L> {
type Item = char;

fn next(&mut self) -> Option<char> {
Expand Down Expand Up @@ -361,7 +361,7 @@ impl CharSet for Utf8CharSet {
if first < 0xE0 {
return Ok(Some(unsafe {
char::from_u32_unchecked(
(u32::from(first & 0x1F)) << 6 |
((u32::from(first & 0x1F)) << 6) |
u32::from(second & 0x3F)
)
}))
Expand All @@ -376,8 +376,8 @@ impl CharSet for Utf8CharSet {
if first < 0xF0 {
return Ok(Some(unsafe {
char::from_u32_unchecked(
(u32::from(first & 0x0F)) << 12 |
(u32::from(second & 0x3F)) << 6 |
((u32::from(first & 0x0F)) << 12) |
((u32::from(second & 0x3F)) << 6) |
u32::from(third & 0x3F)
)
}))
Expand All @@ -391,9 +391,9 @@ impl CharSet for Utf8CharSet {
}
Ok(Some(unsafe {
char::from_u32_unchecked(
(u32::from(first & 0x07)) << 18 |
(u32::from(second & 0x3F)) << 12 |
(u32::from(third & 0x3F)) << 6 |
((u32::from(first & 0x07)) << 18) |
((u32::from(second & 0x3F)) << 12) |
((u32::from(third & 0x3F)) << 6) |
u32::from(fourth & 0x3F)
)
}))
Expand Down
6 changes: 3 additions & 3 deletions src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ impl Tag {
} else if Tag::LAST_OCTET_MASK & self.0[2] == 0 {
// It's a multibyte that starts in the second octet and ends in
// the third octet
u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 7
(u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 7)
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2])
} else {
// It's a multibyte that spans the first three octets
u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 14
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2]) << 7
(u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[1]) << 14)
| (u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[2]) << 7)
| u32::from(Tag::MULTIBYTE_DATA_MASK & self.0[3])
}
}
Expand Down
Loading