Skip to content

Commit

Permalink
Merge pull request project-chip#215 from ivmarkov/clippy
Browse files Browse the repository at this point in the history
Automatic Clippy fixes
  • Loading branch information
kedars authored Dec 1, 2024
2 parents ccf1c1a + d7a30f0 commit 2921a36
Show file tree
Hide file tree
Showing 39 changed files with 167 additions and 138 deletions.
2 changes: 1 addition & 1 deletion rs-matter-data-model/src/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
}
}

impl<'a> DeepestIndex for GreedyError<Span<'a>, ErrorKind> {
impl DeepestIndex for GreedyError<Span<'_>, ErrorKind> {
fn depest_index(&self) -> Option<usize> {
self.errors.iter().map(|(p, _k)| p.location_offset()).max()
}
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/cert/asn1_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'a> ASN1Writer<'a> {
}
}

impl<'a> CertConsumer for ASN1Writer<'a> {
impl CertConsumer for ASN1Writer<'_> {
fn start_seq(&mut self, _tag: &str) -> Result<(), Error> {
self.add_compound(0x30)
}
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/cert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ impl<'a> CertRef<'a> {
}
}

impl<'a> fmt::Display for CertRef<'a> {
impl fmt::Display for CertRef<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut printer = CertPrinter::new(f);

Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/cert/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SPACE: [&str; MAX_DEPTH] = [
" ",
];

impl<'a, 'b> CertConsumer for CertPrinter<'a, 'b> {
impl CertConsumer for CertPrinter<'_, '_> {
fn start_seq(&mut self, tag: &str) -> Result<(), Error> {
if !tag.is_empty() {
let _ = writeln!(self.f, "{} {}", SPACE[self.level], tag);
Expand Down
8 changes: 4 additions & 4 deletions rs-matter/src/crypto/crypto_rustcrypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,19 +354,19 @@ impl<'a> SliceBuffer<'a> {
}
}

impl<'a> AsMut<[u8]> for SliceBuffer<'a> {
impl AsMut<[u8]> for SliceBuffer<'_> {
fn as_mut(&mut self) -> &mut [u8] {
&mut self.slice[..self.len]
}
}

impl<'a> AsRef<[u8]> for SliceBuffer<'a> {
impl AsRef<[u8]> for SliceBuffer<'_> {
fn as_ref(&self) -> &[u8] {
&self.slice[..self.len]
}
}

impl<'a> ccm::aead::Buffer for SliceBuffer<'a> {
impl ccm::aead::Buffer for SliceBuffer<'_> {
fn extend_from_slice(&mut self, other: &[u8]) -> ccm::aead::Result<()> {
self.slice[self.len..][..other.len()].copy_from_slice(other);
self.len += other.len();
Expand All @@ -380,7 +380,7 @@ impl<'a> ccm::aead::Buffer for SliceBuffer<'a> {

struct VecWriter<'a>(&'a mut alloc::vec::Vec<u8>);

impl<'a> Writer for VecWriter<'a> {
impl Writer for VecWriter<'_> {
fn write(&mut self, slice: &[u8]) -> x509_cert::der::Result<()> {
self.0.extend_from_slice(slice);

Expand Down
6 changes: 3 additions & 3 deletions rs-matter/src/data_model/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ where
}
}

impl<'a, const N: usize, B, T> ExchangeHandler for DataModel<'a, N, B, T>
impl<const N: usize, B, T> ExchangeHandler for DataModel<'_, N, B, T>
where
T: DataModelHandler,
B: BufferAccess<IMBuffer>,
Expand Down Expand Up @@ -837,7 +837,7 @@ impl<'a> ReportDataReq<'a> {
}
}

impl<'a> WriteReqRef<'a> {
impl WriteReqRef<'_> {
async fn respond<T>(
&self,
handler: T,
Expand Down Expand Up @@ -881,7 +881,7 @@ impl<'a> WriteReqRef<'a> {
}
}

impl<'a> InvReqRef<'a> {
impl InvReqRef<'_> {
async fn respond<T>(
&self,
handler: T,
Expand Down
6 changes: 3 additions & 3 deletions rs-matter/src/data_model/objects/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct AttrDetails<'a> {
pub wildcard: bool,
}

impl<'a> AttrDetails<'a> {
impl AttrDetails<'_> {
pub fn is_system(&self) -> bool {
Attribute::is_system_attr(self.attr_id)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ pub struct CmdDetails<'a> {
pub wildcard: bool,
}

impl<'a> CmdDetails<'a> {
impl CmdDetails<'_> {
pub fn path(&self) -> CmdPath {
CmdPath::new(
Some(self.endpoint_id),
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'a> Cluster<'a> {
}
}

impl<'a> core::fmt::Display for Cluster<'a> {
impl core::fmt::Display for Cluster<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "id:{}, ", self.id)?;
write!(f, "attrs[")?;
Expand Down
12 changes: 6 additions & 6 deletions rs-matter/src/data_model/objects/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,23 @@ impl<'a, 'b, 'c> AttrDataWriter<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> Drop for AttrDataWriter<'a, 'b, 'c> {
impl Drop for AttrDataWriter<'_, '_, '_> {
fn drop(&mut self) {
if !self.completed {
self.reset();
}
}
}

impl<'a, 'b, 'c> Deref for AttrDataWriter<'a, 'b, 'c> {
impl<'b, 'c> Deref for AttrDataWriter<'_, 'b, 'c> {
type Target = TLVWriter<'b, 'c>;

fn deref(&self) -> &Self::Target {
self.tw
}
}

impl<'a, 'b, 'c> DerefMut for AttrDataWriter<'a, 'b, 'c> {
impl DerefMut for AttrDataWriter<'_, '_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.tw
}
Expand Down Expand Up @@ -335,23 +335,23 @@ impl<'a, 'b, 'c> CmdDataWriter<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> Drop for CmdDataWriter<'a, 'b, 'c> {
impl Drop for CmdDataWriter<'_, '_, '_> {
fn drop(&mut self) {
if !self.completed {
self.reset();
}
}
}

impl<'a, 'b, 'c> Deref for CmdDataWriter<'a, 'b, 'c> {
impl<'b, 'c> Deref for CmdDataWriter<'_, 'b, 'c> {
type Target = TLVWriter<'b, 'c>;

fn deref(&self) -> &Self::Target {
self.tw
}
}

impl<'a, 'b, 'c> DerefMut for CmdDataWriter<'a, 'b, 'c> {
impl DerefMut for CmdDataWriter<'_, '_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.tw
}
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/data_model/objects/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> Endpoint<'a> {
}
}

impl<'a> core::fmt::Display for Endpoint<'a> {
impl core::fmt::Display for Endpoint<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "clusters:[")?;
let mut comma = "";
Expand Down
48 changes: 35 additions & 13 deletions rs-matter/src/data_model/objects/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ impl<T> Metadata for &T
where
T: Metadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a> where Self: 'a;
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

fn lock(&self) -> Self::MetadataGuard<'_> {
(**self).lock()
Expand All @@ -66,14 +69,17 @@ impl<T> Metadata for &mut T
where
T: Metadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a> where Self: 'a;
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

fn lock(&self) -> Self::MetadataGuard<'_> {
(**self).lock()
}
}

impl<'a> MetadataGuard for Node<'a> {
impl MetadataGuard for Node<'_> {
fn node(&self) -> Node<'_> {
Node {
id: self.id,
Expand All @@ -82,8 +88,11 @@ impl<'a> MetadataGuard for Node<'a> {
}
}

impl<'a> Metadata for Node<'a> {
type MetadataGuard<'g> = Node<'g> where Self: 'g;
impl Metadata for Node<'_> {
type MetadataGuard<'g>
= Node<'g>
where
Self: 'g;

fn lock(&self) -> Self::MetadataGuard<'_> {
Node {
Expand All @@ -97,7 +106,8 @@ impl<M, H> Metadata for (M, H)
where
M: Metadata,
{
type MetadataGuard<'a> = M::MetadataGuard<'a>
type MetadataGuard<'a>
= M::MetadataGuard<'a>
where
Self: 'a;

Expand All @@ -110,7 +120,8 @@ impl<T> Metadata for HandlerCompat<T>
where
T: Metadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a>
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

Expand All @@ -136,7 +147,10 @@ pub mod asynch {
where
T: AsyncMetadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a> where Self: 'a;
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

async fn lock(&self) -> Self::MetadataGuard<'_> {
(**self).lock().await
Expand All @@ -147,15 +161,21 @@ pub mod asynch {
where
T: AsyncMetadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a> where Self: 'a;
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

async fn lock(&self) -> Self::MetadataGuard<'_> {
(**self).lock().await
}
}

impl<'a> AsyncMetadata for Node<'a> {
type MetadataGuard<'g> = Node<'g> where Self: 'g;
impl AsyncMetadata for Node<'_> {
type MetadataGuard<'g>
= Node<'g>
where
Self: 'g;

async fn lock(&self) -> Self::MetadataGuard<'_> {
Node {
Expand All @@ -169,7 +189,8 @@ pub mod asynch {
where
M: AsyncMetadata,
{
type MetadataGuard<'a> = M::MetadataGuard<'a>
type MetadataGuard<'a>
= M::MetadataGuard<'a>
where
Self: 'a;

Expand All @@ -182,7 +203,8 @@ pub mod asynch {
where
T: Metadata,
{
type MetadataGuard<'a> = T::MetadataGuard<'a>
type MetadataGuard<'a>
= T::MetadataGuard<'a>
where
Self: 'a;

Expand Down
15 changes: 8 additions & 7 deletions rs-matter/src/data_model/objects/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'a> Node<'a> {
&'m self,
req: &'m ReportDataReq,
accessor: &'m Accessor<'m>,
) -> Result<impl Iterator<Item = Result<Result<AttrDetails, AttrStatus>, Error>> + 'm, Error>
) -> Result<impl Iterator<Item = Result<Result<AttrDetails<'m>, AttrStatus>, Error>> + 'm, Error>
{
let dataver_filters = req.dataver_filters()?;
let fabric_filtered = req.fabric_filtered()?;
Expand All @@ -82,12 +82,13 @@ impl<'a> Node<'a> {
/// As part of the expansion, the method will check whether the attributes are
/// accessible by the accessor and filter out the inaccessible ones (wildcard writes)
/// or report an error status for the non-wildcard ones.
#[allow(clippy::type_complexity)]
pub fn write<'m>(
&'m self,
req: &'m WriteReqRef,
accessor: &'m Accessor<'m>,
) -> Result<
impl Iterator<Item = Result<Result<(AttrDetails, TLVElement<'m>), AttrStatus>, Error>> + 'm,
impl Iterator<Item = Result<Result<(AttrDetails<'m>, TLVElement<'m>), AttrStatus>, Error>> + 'm,
Error,
> {
Ok(PathExpander::new(
Expand All @@ -103,12 +104,13 @@ impl<'a> Node<'a> {
/// As part of the expansion, the method will check whether the commands are
/// accessible by the accessor and filter out the inaccessible ones (wildcard invocations)
/// or report an error status for the non-wildcard ones.
#[allow(clippy::type_complexity)]
pub fn invoke<'m>(
&'m self,
req: &'m InvReqRef,
accessor: &'m Accessor<'m>,
) -> Result<
impl Iterator<Item = Result<Result<(CmdDetails, TLVElement<'m>), CmdStatus>, Error>> + 'm,
impl Iterator<Item = Result<Result<(CmdDetails<'m>, TLVElement<'m>), CmdStatus>, Error>> + 'm,
Error,
> {
Ok(PathExpander::new(
Expand All @@ -119,7 +121,7 @@ impl<'a> Node<'a> {
}
}

impl<'a> core::fmt::Display for Node<'a> {
impl core::fmt::Display for Node<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "node:")?;
for (index, endpoint) in self.endpoints.iter().enumerate() {
Expand Down Expand Up @@ -180,7 +182,7 @@ impl<'a, const N: usize> DynamicNode<'a, N> {
}
}

impl<'a, const N: usize> core::fmt::Display for DynamicNode<'a, N> {
impl<const N: usize> core::fmt::Display for DynamicNode<'_, N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.node().fmt(f)
}
Expand Down Expand Up @@ -653,8 +655,7 @@ mod test {
let fab_mgr = RefCell::new(FabricMgr::new());
let accessor = Accessor::new(0, AccessorSubjects::new(0), AuthMode::Pase, &fab_mgr);

let expander =
PathExpander::new(&node, &accessor, Some(input.into_iter().cloned().map(Ok)));
let expander = PathExpander::new(node, &accessor, Some(input.iter().cloned().map(Ok)));

assert_eq!(
expander
Expand Down
4 changes: 2 additions & 2 deletions rs-matter/src/data_model/sdm/thread_nw_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl<'a> ThreadNwDiagCluster<'a> {
}
}

impl<'a> Handler for ThreadNwDiagCluster<'a> {
impl Handler for ThreadNwDiagCluster<'_> {
fn read(
&self,
exchange: &Exchange,
Expand All @@ -484,4 +484,4 @@ impl<'a> Handler for ThreadNwDiagCluster<'a> {
}
}

impl<'a> NonBlockingHandler for ThreadNwDiagCluster<'a> {}
impl NonBlockingHandler for ThreadNwDiagCluster<'_> {}
Loading

0 comments on commit 2921a36

Please sign in to comment.