Skip to content
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

rust 1.83 clippy fixup #1640

Merged
merged 16 commits into from
Jan 27, 2025
4 changes: 2 additions & 2 deletions base64ct/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<'i, E: Encoding> Decoder<'i, E> {
}

#[cfg(feature = "std")]
impl<'i, E: Encoding> io::Read for Decoder<'i, E> {
impl<E: Encoding> io::Read for Decoder<'_, E> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if self.is_finished() {
return Ok(0);
Expand Down Expand Up @@ -344,7 +344,7 @@ pub struct Line<'i> {
remaining: &'i [u8],
}

impl<'i> Default for Line<'i> {
impl Default for Line<'_> {
fn default() -> Self {
Self::new(&[])
}
Expand Down
2 changes: 1 addition & 1 deletion base64ct/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'o, E: Encoding> Encoder<'o, E> {
}

#[cfg(feature = "std")]
impl<'o, E: Encoding> io::Write for Encoder<'o, E> {
impl<E: Encoding> io::Write for Encoder<'_, E> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.encode(buf)?;
Ok(buf.len())
Expand Down
2 changes: 1 addition & 1 deletion cms/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'s> SignerInfoBuilder<'s> {
}
}

impl<'s> Builder for SignerInfoBuilder<'s> {
impl Builder for SignerInfoBuilder<'_> {
type Output = SignerInfo;

/// Calculate the data to be signed
Expand Down
2 changes: 1 addition & 1 deletion const-oid/src/arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> Arcs<'a> {
}
}

impl<'a> Iterator for Arcs<'a> {
impl Iterator for Arcs<'_> {
type Item = Arc;

fn next(&mut self) -> Option<Arc> {
Expand Down
2 changes: 1 addition & 1 deletion const-oid/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const fn base128_byte(arc: Arc, pos: usize, total: usize) -> Result<u8> {
debug_assert!(pos < total);
let last_byte = checked_add!(pos, 1) == total;
let mask = if last_byte { 0 } else { 0b10000000 };
let shift = checked_sub!(checked_sub!(total, pos), 1) * 7;
let shift = checked_mul!(checked_sub!(checked_sub!(total, pos), 1), 7);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes this warning:

warning: arithmetic operation that can potentially result in unexpected side-effects
   --> const-oid/src/encoder.rs:135:17
    |
135 |     let shift = checked_sub!(checked_sub!(total, pos), 1) * 7;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
note: the lint level is defined here
   --> const-oid/src/lib.rs:11:5
    |
11  |     clippy::arithmetic_side_effects,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I don't think the shift should overflow in the first place, but clippy still warns about it.

Ok(((arc >> shift) & 0b1111111) as u8 | mask)
}

Expand Down
2 changes: 1 addition & 1 deletion crmf/src/pop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'a> ::der::Decode<'a> for EncKeyWithIdChoice<'a> {
}
}
}
impl<'a> ::der::EncodeValue for EncKeyWithIdChoice<'a> {
impl ::der::EncodeValue for EncKeyWithIdChoice<'_> {
fn encode_value(&self, encoder: &mut impl ::der::Writer) -> ::der::Result<()> {
match self {
Self::String(variant) => variant.encode_value(encoder),
Expand Down
2 changes: 1 addition & 1 deletion der/src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
impl<T> ExactSizeIterator for Iter<'_, T> {}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/bit_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<'a> TryFrom<BitStringRef<'a>> for &'a [u8] {
}
}

impl<'a> FixedTag for BitStringRef<'a> {
impl FixedTag for BitStringRef<'_> {
const TAG: Tag = Tag::BitString;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ pub struct BitStringIter<'a> {
position: usize,
}

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

#[allow(clippy::arithmetic_side_effects)]
Expand All @@ -417,13 +417,13 @@ impl<'a> Iterator for BitStringIter<'a> {
}
}

impl<'a> ExactSizeIterator for BitStringIter<'a> {
impl ExactSizeIterator for BitStringIter<'_> {
fn len(&self) -> usize {
self.bit_string.bit_len()
}
}

impl<'a> FusedIterator for BitStringIter<'a> {}
impl FusedIterator for BitStringIter<'_> {}

#[cfg(feature = "flagset")]
impl<T: flagset::Flags> FixedTag for flagset::FlagSet<T> {
Expand Down
4 changes: 2 additions & 2 deletions der/src/asn1/context_specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl<'a, T> ContextSpecificRef<'a, T> {
}
}

impl<'a, T> EncodeValue for ContextSpecificRef<'a, T>
impl<T> EncodeValue for ContextSpecificRef<'_, T>
where
T: EncodeValue + Tagged,
{
Expand All @@ -247,7 +247,7 @@ where
}
}

impl<'a, T> Tagged for ContextSpecificRef<'a, T>
impl<T> Tagged for ContextSpecificRef<'_, T>
where
T: Tagged,
{
Expand Down
6 changes: 3 additions & 3 deletions der/src/asn1/integer/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a> DecodeValue<'a> for IntRef<'a> {
}
}

impl<'a> EncodeValue for IntRef<'a> {
impl EncodeValue for IntRef<'_> {
fn value_len(&self) -> Result<Length> {
// Signed integers always hold their full encoded form.
Ok(self.inner.len())
Expand All @@ -168,11 +168,11 @@ impl<'a> From<&IntRef<'a>> for IntRef<'a> {
}
}

impl<'a> FixedTag for IntRef<'a> {
impl FixedTag for IntRef<'_> {
const TAG: Tag = Tag::Integer;
}

impl<'a> OrdIsValueOrd for IntRef<'a> {}
impl OrdIsValueOrd for IntRef<'_> {}

#[cfg(feature = "alloc")]
mod allocating {
Expand Down
6 changes: 3 additions & 3 deletions der/src/asn1/integer/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a> DecodeValue<'a> for UintRef<'a> {
}
}

impl<'a> EncodeValue for UintRef<'a> {
impl EncodeValue for UintRef<'_> {
fn value_len(&self) -> Result<Length> {
encoded_len(self.inner.as_slice())
}
Expand All @@ -155,11 +155,11 @@ impl<'a> From<&UintRef<'a>> for UintRef<'a> {
}
}

impl<'a> FixedTag for UintRef<'a> {
impl FixedTag for UintRef<'_> {
const TAG: Tag = Tag::Integer;
}

impl<'a> OrdIsValueOrd for UintRef<'a> {}
impl OrdIsValueOrd for UintRef<'_> {}

#[cfg(feature = "alloc")]
mod allocating {
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/sequence_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'a, T> Iterator for SequenceOfIter<'a, T> {
}
}

impl<'a, T> ExactSizeIterator for SequenceOfIter<'a, T> {}
impl<T> ExactSizeIterator for SequenceOfIter<'_, T> {}

impl<'a, T, const N: usize> DecodeValue<'a> for [T; N]
where
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/set_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a, T> Iterator for SetOfIter<'a, T> {
}
}

impl<'a, T> ExactSizeIterator for SetOfIter<'a, T> {}
impl<T> ExactSizeIterator for SetOfIter<'_, T> {}

/// ASN.1 `SET OF` backed by a [`Vec`].
///
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/utf8_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'a> TryFrom<&'a str> for Utf8StringRef<'a> {
}
}

impl<'a> fmt::Debug for Utf8StringRef<'a> {
impl fmt::Debug for Utf8StringRef<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Utf8String({:?})", self.as_str())
}
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/videotex_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> From<VideotexStringRef<'a>> for &'a [u8] {
}
}

impl<'a> fmt::Debug for VideotexStringRef<'a> {
impl fmt::Debug for VideotexStringRef<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "VideotexString({:?})", self.as_str())
}
Expand Down
12 changes: 6 additions & 6 deletions der/src/encode_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use core::cmp::Ordering;
/// type which impls the same.
pub struct EncodeRef<'a, T>(pub &'a T);

impl<'a, T> AsRef<T> for EncodeRef<'a, T> {
impl<T> AsRef<T> for EncodeRef<'_, T> {
fn as_ref(&self) -> &T {
self.0
}
}

impl<'a, T> Encode for EncodeRef<'a, T>
impl<T> Encode for EncodeRef<'_, T>
where
T: Encode,
{
Expand All @@ -33,13 +33,13 @@ where
/// By virtue of the blanket impl, this type also impls `Encode`.
pub struct EncodeValueRef<'a, T>(pub &'a T);

impl<'a, T> AsRef<T> for EncodeValueRef<'a, T> {
impl<T> AsRef<T> for EncodeValueRef<'_, T> {
fn as_ref(&self) -> &T {
self.0
}
}

impl<'a, T> EncodeValue for EncodeValueRef<'a, T>
impl<T> EncodeValue for EncodeValueRef<'_, T>
where
T: EncodeValue,
{
Expand All @@ -52,7 +52,7 @@ where
}
}

impl<'a, T> Tagged for EncodeValueRef<'a, T>
impl<T> Tagged for EncodeValueRef<'_, T>
where
T: Tagged,
{
Expand All @@ -61,7 +61,7 @@ where
}
}

impl<'a, T> ValueOrd for EncodeValueRef<'a, T>
impl<T> ValueOrd for EncodeValueRef<'_, T>
where
T: ValueOrd,
{
Expand Down
2 changes: 1 addition & 1 deletion der/src/str_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> DecodeValue<'a> for StrRef<'a> {
}
}

impl<'a> EncodeValue for StrRef<'a> {
impl EncodeValue for StrRef<'_> {
fn value_len(&self) -> Result<Length> {
Ok(self.length)
}
Expand Down
2 changes: 1 addition & 1 deletion der/src/writer/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> SliceWriter<'a> {
}
}

impl<'a> Writer for SliceWriter<'a> {
impl Writer for SliceWriter<'_> {
fn write(&mut self, slice: &[u8]) -> Result<()> {
self.reserve(slice.len())?.copy_from_slice(slice);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions gss-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct InitialContextToken<'a> {
pub inner_context_token: AnyRef<'a>,
}

impl<'a> FixedTag for InitialContextToken<'a> {
impl FixedTag for InitialContextToken<'_> {
const TAG: Tag = Tag::Application {
constructed: true,
number: TagNumber::new(0),
Expand All @@ -72,7 +72,7 @@ impl<'a> DecodeValue<'a> for InitialContextToken<'a> {
}
}

impl<'a> EncodeValue for InitialContextToken<'a> {
impl EncodeValue for InitialContextToken<'_> {
fn value_len(&self) -> der::Result<Length> {
self.this_mech.encoded_len()? + self.inner_context_token.encoded_len()?
}
Expand Down
4 changes: 2 additions & 2 deletions gss-api/src/negotiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub struct NegTokenTarg<'a> {
/// processed by the target (accept_incomplete) and a mechToken
/// sent by the initiator and processed by the target
/// (accept_completed).
///
//
// For those targets that support piggybacking the initial mechToken,
// an optimistic negotiation response is possible and includes in that
// case a responseToken which may continue the authentication exchange
Expand All @@ -154,7 +154,7 @@ pub struct NegTokenTarg<'a> {
// the responseToken is used to carry the tokens specific to the
// mechanism selected. For subsequent tokens (if any) returned by the
// target, negResult, and supportedMech are not present.

//
// For the last token returned by the target, the mechListMIC, when
// present, is a MIC computed over the MechTypes using the selected
// mechanism.
Expand Down
2 changes: 1 addition & 1 deletion pem-rfc7468/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'i> From<Decoder<'i>> for Base64Decoder<'i> {
}

#[cfg(feature = "std")]
impl<'i> io::Read for Decoder<'i> {
impl io::Read for Decoder<'_> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.base64.read(buf)
}
Expand Down
2 changes: 1 addition & 1 deletion pem-rfc7468/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'l, 'o> Encoder<'l, 'o> {
}

#[cfg(feature = "std")]
impl<'l, 'o> io::Write for Encoder<'l, 'o> {
impl io::Write for Encoder<'_, '_> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.encode(buf)?;
Ok(buf.len())
Expand Down
4 changes: 2 additions & 2 deletions pkcs1/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a> RsaPssParams<'a> {
}
}

impl<'a> Default for RsaPssParams<'a> {
impl Default for RsaPssParams<'_> {
fn default() -> Self {
Self {
hash: SHA_1_AI,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<'a> RsaOaepParams<'a> {
}
}

impl<'a> Default for RsaOaepParams<'a> {
impl Default for RsaOaepParams<'_> {
fn default() -> Self {
Self {
hash: SHA_1_AI,
Expand Down
4 changes: 2 additions & 2 deletions pkcs12/src/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ where
Pkcs12KeyType::Mac => vec![3u8; block_size],
};

let slen = block_size * ((salt.len() + block_size - 1) / block_size);
let plen = block_size * ((pass.len() + block_size - 1) / block_size);
let slen = block_size * salt.len().div_ceil(block_size);
let plen = block_size * pass.len().div_ceil(block_size);
let ilen = slen + plen;
let mut init_key = vec![0u8; ilen];
// 2. Concatenate copies of the salt together to create a string S of
Expand Down
2 changes: 1 addition & 1 deletion pkcs12/src/safe_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ::der::EncodeValue for SafeBag {
Ok(())
}
}
impl<'a> ::der::Sequence<'a> for SafeBag {}
impl ::der::Sequence<'_> for SafeBag {}

/// Version for the PrivateKeyInfo structure as defined in [RFC 5208 Section 5].
///
Expand Down
2 changes: 1 addition & 1 deletion pkcs8/src/private_key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub trait BitStringLike {
fn as_bit_string(&self) -> BitStringRef<'_>;
}

impl<'a> BitStringLike for BitStringRef<'a> {
impl BitStringLike for BitStringRef<'_> {
fn as_bit_string(&self) -> BitStringRef<'_> {
BitStringRef::from(self)
}
Expand Down
2 changes: 1 addition & 1 deletion sec1/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ pub enum Coordinates<'a, Size: ModulusSize> {
},
}

impl<'a, Size: ModulusSize> Coordinates<'a, Size> {
impl<Size: ModulusSize> Coordinates<'_, Size> {
/// Get the tag octet needed to encode this set of [`Coordinates`]
pub fn tag(&self) -> Tag {
match self {
Expand Down
2 changes: 1 addition & 1 deletion sec1/src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'a> TryFrom<&'a [u8]> for EcPrivateKey<'a> {
}
}

impl<'a> fmt::Debug for EcPrivateKey<'a> {
impl fmt::Debug for EcPrivateKey<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EcPrivateKey")
.field("parameters", &self.parameters)
Expand Down
Loading
Loading