diff --git a/crates/reportify/src/lib.rs b/crates/reportify/src/lib.rs index 0dd2583..44be1bc 100644 --- a/crates/reportify/src/lib.rs +++ b/crates/reportify/src/lib.rs @@ -840,7 +840,6 @@ impl ResultExt for Result { } #[track_caller] - #[must_use] fn whatever(self, description: C) -> Result> where F: Whatever, @@ -854,7 +853,6 @@ impl ResultExt for Result { } #[track_caller] - #[must_use] fn whatever_with(self, description: X) -> Result> where F: Whatever, diff --git a/crates/reportify/src/renderer.rs b/crates/reportify/src/renderer.rs index 96cc235..af52784 100644 --- a/crates/reportify/src/renderer.rs +++ b/crates/reportify/src/renderer.rs @@ -117,7 +117,7 @@ enum ReportTreeNode<'report> { }, } -impl<'report> TreeNode for ReportTreeNode<'report> { +impl TreeNode for ReportTreeNode<'_> { fn render(&self, renderer: &mut Renderer) -> fmt::Result { use std::fmt::Write; match self { diff --git a/crates/rugpi-common/src/artifact/format/decode.rs b/crates/rugpi-common/src/artifact/format/decode.rs index 81c6393..dce9f25 100644 --- a/crates/rugpi-common/src/artifact/format/decode.rs +++ b/crates/rugpi-common/src/artifact/format/decode.rs @@ -27,18 +27,18 @@ pub enum DecodeError { pub trait Decode: Sized { /// Try to decode the structure from a segment. #[allow(unused_variables)] - fn decode_segment<'r, R: BufRead>(segment: SegmentDecoder<'r, R>) -> Result { + fn decode_segment(segment: SegmentDecoder<'_, R>) -> Result { todo!("cannot be decoded from segment") } /// Try to decode the structure from a value. #[allow(unused_variables)] - fn decode_value<'r, R: BufRead>(value: ValueDecoder<'r, R>) -> Result { + fn decode_value(value: ValueDecoder<'_, R>) -> Result { todo!("cannot be decoded from value") } /// Try to decode the structure from either a segment or a value. - fn decode<'r, R: BufRead>(decoder: Decoder<'r, R>) -> Result { + fn decode(decoder: Decoder<'_, R>) -> Result { match decoder { Decoder::Segment(segment) => Self::decode_segment(segment), Decoder::Value(value) => Self::decode_value(value), @@ -46,10 +46,7 @@ pub trait Decode: Sized { } #[allow(unused_variables)] - fn decode_extension<'r, R: BufRead>( - &mut self, - decoder: Decoder<'r, R>, - ) -> Result<(), DecodeError> { + fn decode_extension(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> { todo!( "cannot decode extension of {}", std::any::type_name::() @@ -62,14 +59,11 @@ pub trait Decode: Sized { } impl Decode for Option { - fn decode<'r, R: BufRead>(decoder: Decoder<'r, R>) -> Result { + fn decode(decoder: Decoder<'_, R>) -> Result { Ok(Some(decoder.decode()?)) } - fn decode_extension<'r, R: BufRead>( - &mut self, - decoder: Decoder<'r, R>, - ) -> Result<(), DecodeError> { + fn decode_extension(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> { match self { Some(inner) => inner.decode_extension(decoder), None => { @@ -85,14 +79,11 @@ impl Decode for Option { } impl Decode for Vec { - fn decode<'r, R: BufRead>(decoder: Decoder<'r, R>) -> Result { + fn decode(decoder: Decoder<'_, R>) -> Result { Ok(vec![decoder.decode()?]) } - fn decode_extension<'r, R: BufRead>( - &mut self, - decoder: Decoder<'r, R>, - ) -> Result<(), DecodeError> { + fn decode_extension(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> { self.push(decoder.decode()?); Ok(()) } @@ -103,19 +94,19 @@ impl Decode for Vec { } impl Decode for String { - fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result { + fn decode_value(mut value: ValueDecoder<'_, R>) -> Result { String::from_utf8(value.consume_bytes()?).map_err(|_| todo!("handle invalid UTF-8")) } } impl Decode for Bytes { - fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result { + fn decode_value(mut value: ValueDecoder<'_, R>) -> Result { Ok(value.consume_bytes()?.into()) } } impl Decode for bool { - fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result { + fn decode_value(mut value: ValueDecoder<'_, R>) -> Result { Ok(value.consume_array::<1>()?[0] != 0) } } @@ -124,7 +115,7 @@ macro_rules! impl_decode_for_int { ($($int:ty),*) => { $( impl Decode for $int { - fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result { + fn decode_value(mut value: ValueDecoder<'_, R>) -> Result { Ok(Self::from_be_bytes(value.consume_array()?)) } } @@ -134,9 +125,7 @@ macro_rules! impl_decode_for_int { impl_decode_for_int! { i8, u8, i16, u16, i32, u32, i64, u64, i128, u128 } -pub fn start_decoder<'r, R: BufRead>( - reader: &'r mut R, -) -> Result>, DecodeError> { +pub fn start_decoder(reader: &mut R) -> Result>, DecodeError> { let Some(head) = read_atom_head(reader)? else { return Ok(None); }; @@ -191,6 +180,7 @@ impl<'r, R: BufRead> SegmentDecoder<'r, R> { Ok(()) } + #[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> Result>, DecodeError> { if self.completed { return Ok(None); @@ -227,7 +217,7 @@ pub enum Decoder<'r, R> { Value(ValueDecoder<'r, R>), } -impl<'r, R: BufRead> Decoder<'r, R> { +impl Decoder<'_, R> { pub fn skip(self) -> Result<(), DecodeError> { match self { Decoder::Segment(mut segment) => segment.skip(), @@ -254,7 +244,7 @@ pub struct ValueDecoder<'r, R> { remaining: u64, } -impl<'r, R: BufRead> ValueDecoder<'r, R> { +impl ValueDecoder<'_, R> { pub fn tag(&self) -> Tag { self.head.tag() } @@ -285,7 +275,7 @@ impl<'r, R: BufRead> ValueDecoder<'r, R> { } } -impl<'r, R: Seek> ValueDecoder<'r, R> { +impl ValueDecoder<'_, R> { pub fn skip_seek(&mut self) -> io::Result<()> { self.reader.seek_relative(self.remaining as i64)?; self.remaining = 0; diff --git a/crates/rugpi-common/src/artifact/format/macros.rs b/crates/rugpi-common/src/artifact/format/macros.rs index 440fbbf..0e7ac3e 100644 --- a/crates/rugpi-common/src/artifact/format/macros.rs +++ b/crates/rugpi-common/src/artifact/format/macros.rs @@ -18,8 +18,8 @@ macro_rules! define_struct { } impl $crate::artifact::format::decode::Decode for $name { - fn decode_segment<'r, R: std::io::BufRead>( - mut segment: $crate::artifact::format::decode::SegmentDecoder<'r, R>, + fn decode_segment( + mut segment: $crate::artifact::format::decode::SegmentDecoder<'_, R>, ) -> Result { $( let mut $field_name = <$field_type>::initial_value(); @@ -74,8 +74,8 @@ macro_rules! define_enum { } impl Decode for $name { - fn decode_segment<'r, R: BufRead>( - mut segment: SegmentDecoder<'r, R>, + fn decode_segment( + mut segment: SegmentDecoder<'_, R>, ) -> Result { let mut variant = None; while let Some(decoder) = segment.next()? { diff --git a/crates/rugpi-common/src/artifact/format/mod.rs b/crates/rugpi-common/src/artifact/format/mod.rs index 689e26c..97181ad 100644 --- a/crates/rugpi-common/src/artifact/format/mod.rs +++ b/crates/rugpi-common/src/artifact/format/mod.rs @@ -106,8 +106,8 @@ pub struct Metadata { } impl Decode for Metadata { - fn decode_segment<'r, R: BufRead>( - mut segment: SegmentDecoder<'r, R>, + fn decode_segment( + mut segment: SegmentDecoder<'_, R>, ) -> Result { let mut key = None; let mut map = HashMap::new(); diff --git a/crates/rugpi-common/src/artifact/format/stlv.rs b/crates/rugpi-common/src/artifact/format/stlv.rs index fa33568..ee7d2d5 100644 --- a/crates/rugpi-common/src/artifact/format/stlv.rs +++ b/crates/rugpi-common/src/artifact/format/stlv.rs @@ -501,7 +501,7 @@ struct DisplayTag<'r> { resolver: Option<&'r dyn TagNameResolver>, } -impl<'r> fmt::Display for DisplayTag<'r> { +impl fmt::Display for DisplayTag<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.resolver { Some(resolver) => fmt::Write::write_fmt( diff --git a/crates/rugpi-common/src/boot/grub.rs b/crates/rugpi-common/src/boot/grub.rs index a918d36..14c6611 100644 --- a/crates/rugpi-common/src/boot/grub.rs +++ b/crates/rugpi-common/src/boot/grub.rs @@ -162,10 +162,10 @@ pub type GrubEnv = HashMap; pub fn load_grub_env>(path: P) -> Result> { fn inner(path: &Path) -> Result> { - Ok(grub_envblk_decode( + grub_envblk_decode( &fs::read_to_string(path).whatever("unable to read Grub environment")?, ) - .whatever("unable to decode Grub environment")?) + .whatever("unable to decode Grub environment") } inner(path.as_ref()) } diff --git a/crates/rugpi-common/src/disk/blkdev.rs b/crates/rugpi-common/src/disk/blkdev.rs index c25d7e7..7612f32 100644 --- a/crates/rugpi-common/src/disk/blkdev.rs +++ b/crates/rugpi-common/src/disk/blkdev.rs @@ -44,7 +44,7 @@ impl BlockDevice { String::from_utf8(path.into_os_string().into_encoded_bytes()).map_err(|_| { io::Error::new( io::ErrorKind::InvalidInput, - format!("device path must be valid UTF-8"), + "device path must be valid UTF-8".to_string(), ) })?; let stat = nix::sys::stat::stat(path.as_str())?; diff --git a/crates/rugpi-common/src/disk/stream.rs b/crates/rugpi-common/src/disk/stream.rs index 405424e..786c02a 100644 --- a/crates/rugpi-common/src/disk/stream.rs +++ b/crates/rugpi-common/src/disk/stream.rs @@ -184,7 +184,7 @@ pub struct PartitionStream<'stream, R> { entry: PartitionEntry, } -impl<'stream, R> PartitionStream<'stream, R> { +impl PartitionStream<'_, R> { /// The entry of the partition. pub fn entry(&self) -> &PartitionEntry { &self.entry @@ -196,7 +196,7 @@ impl<'stream, R> PartitionStream<'stream, R> { } } -impl<'stream, R: Read> Read for PartitionStream<'stream, R> { +impl Read for PartitionStream<'_, R> { fn read(&mut self, mut buf: &mut [u8]) -> io::Result { if self.remaining < buf.len() as u64 { if self.remaining == 0 { diff --git a/crates/rugpi-common/src/system/partitions.rs b/crates/rugpi-common/src/system/partitions.rs index db6b6b1..5c45bea 100644 --- a/crates/rugpi-common/src/system/partitions.rs +++ b/crates/rugpi-common/src/system/partitions.rs @@ -18,7 +18,7 @@ pub fn resolve_data_partition( config: &PartitionConfig, ) -> Option { resolve_partition(root, config, || { - match root.map(|root| root.table.as_ref()).flatten() { + match root.and_then(|root| root.table.as_ref()) { Some(table) => Ok(if table.is_mbr() { 7 } else { 6 }), None => { bail!("no root device partition table") @@ -71,7 +71,7 @@ fn resolve_partition( bail!("unable to resolve partition {partition}: no root device") } }; - Ok(Some(device.into())) + Ok(Some(device)) } /// Config partition of the system. @@ -145,7 +145,7 @@ impl ConfigPartition { #[derive(Debug)] struct ConfigPartitionWriteGuard<'p>(&'p ConfigPartition); -impl<'p> Drop for ConfigPartitionWriteGuard<'p> { +impl Drop for ConfigPartitionWriteGuard<'_> { fn drop(&mut self) { let mut writer_count = self.0.writer_count.lock().unwrap(); if self.0.protected && *writer_count == 1 { diff --git a/crates/rugpi-common/src/utils/const_helpers.rs b/crates/rugpi-common/src/utils/const_helpers.rs index c1773fd..7ff4279 100644 --- a/crates/rugpi-common/src/utils/const_helpers.rs +++ b/crates/rugpi-common/src/utils/const_helpers.rs @@ -1,7 +1,7 @@ //! Macros for dealing with limitations of constant functions. -#[allow(unused_macros)] /// Constant unwrapping of options. +#[expect(unused_macros, reason = "not currently used")] macro_rules! const_unwrap_option { ($value:expr) => { match $value { diff --git a/crates/rugpi-ctrl/src/cli.rs b/crates/rugpi-ctrl/src/cli.rs index b2af24d..c715aa5 100644 --- a/crates/rugpi-ctrl/src/cli.rs +++ b/crates/rugpi-ctrl/src/cli.rs @@ -116,9 +116,7 @@ pub fn main() -> SystemResult<()> { None => { let Some(entry) = system .boot_entries() - .iter() - .filter(|(_, entry)| !entry.active()) - .next() + .iter().find(|(_, entry)| !entry.active()) else { bail!("unable to find an entry"); }; diff --git a/crates/rugpi-ctrl/src/utils.rs b/crates/rugpi-ctrl/src/utils.rs index 6e66397..7a022c9 100644 --- a/crates/rugpi-ctrl/src/utils.rs +++ b/crates/rugpi-ctrl/src/utils.rs @@ -23,7 +23,7 @@ pub fn reboot() -> SystemResult<()> { nix::libc::LINUX_REBOOT_MAGIC1, nix::libc::LINUX_REBOOT_MAGIC2, nix::libc::LINUX_REBOOT_CMD_RESTART2, - b"\0".as_ptr(), + c"", ); } } else {