Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Dec 22, 2024
1 parent 3f63069 commit 07a1751
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 50 deletions.
2 changes: 0 additions & 2 deletions crates/reportify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ impl<T, E> ResultExt<T, E> for Result<T, E> {
}

#[track_caller]
#[must_use]
fn whatever<F, C>(self, description: C) -> Result<T, Report<F>>
where
F: Whatever,
Expand All @@ -854,7 +853,6 @@ impl<T, E> ResultExt<T, E> for Result<T, E> {
}

#[track_caller]
#[must_use]
fn whatever_with<F, C, X>(self, description: X) -> Result<T, Report<F>>
where
F: Whatever,
Expand Down
2 changes: 1 addition & 1 deletion crates/reportify/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 17 additions & 27 deletions crates/rugpi-common/src/artifact/format/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,26 @@ 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<Self, DecodeError> {
fn decode_segment<R: BufRead>(segment: SegmentDecoder<'_, R>) -> Result<Self, DecodeError> {
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<Self, DecodeError> {
fn decode_value<R: BufRead>(value: ValueDecoder<'_, R>) -> Result<Self, DecodeError> {
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<Self, DecodeError> {
fn decode<R: BufRead>(decoder: Decoder<'_, R>) -> Result<Self, DecodeError> {
match decoder {
Decoder::Segment(segment) => Self::decode_segment(segment),
Decoder::Value(value) => Self::decode_value(value),
}
}

#[allow(unused_variables)]
fn decode_extension<'r, R: BufRead>(
&mut self,
decoder: Decoder<'r, R>,
) -> Result<(), DecodeError> {
fn decode_extension<R: BufRead>(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> {
todo!(
"cannot decode extension of {}",
std::any::type_name::<Self>()
Expand All @@ -62,14 +59,11 @@ pub trait Decode: Sized {
}

impl<T: Decode> Decode for Option<T> {
fn decode<'r, R: BufRead>(decoder: Decoder<'r, R>) -> Result<Self, DecodeError> {
fn decode<R: BufRead>(decoder: Decoder<'_, R>) -> Result<Self, DecodeError> {
Ok(Some(decoder.decode()?))
}

fn decode_extension<'r, R: BufRead>(
&mut self,
decoder: Decoder<'r, R>,
) -> Result<(), DecodeError> {
fn decode_extension<R: BufRead>(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> {
match self {
Some(inner) => inner.decode_extension(decoder),
None => {
Expand All @@ -85,14 +79,11 @@ impl<T: Decode> Decode for Option<T> {
}

impl<T: Decode> Decode for Vec<T> {
fn decode<'r, R: BufRead>(decoder: Decoder<'r, R>) -> Result<Self, DecodeError> {
fn decode<R: BufRead>(decoder: Decoder<'_, R>) -> Result<Self, DecodeError> {
Ok(vec![decoder.decode()?])
}

fn decode_extension<'r, R: BufRead>(
&mut self,
decoder: Decoder<'r, R>,
) -> Result<(), DecodeError> {
fn decode_extension<R: BufRead>(&mut self, decoder: Decoder<'_, R>) -> Result<(), DecodeError> {
self.push(decoder.decode()?);
Ok(())
}
Expand All @@ -103,19 +94,19 @@ impl<T: Decode> Decode for Vec<T> {
}

impl Decode for String {
fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result<Self, DecodeError> {
fn decode_value<R: BufRead>(mut value: ValueDecoder<'_, R>) -> Result<Self, DecodeError> {
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<Self, DecodeError> {
fn decode_value<R: BufRead>(mut value: ValueDecoder<'_, R>) -> Result<Self, DecodeError> {
Ok(value.consume_bytes()?.into())
}
}

impl Decode for bool {
fn decode_value<'r, R: BufRead>(mut value: ValueDecoder<'r, R>) -> Result<Self, DecodeError> {
fn decode_value<R: BufRead>(mut value: ValueDecoder<'_, R>) -> Result<Self, DecodeError> {
Ok(value.consume_array::<1>()?[0] != 0)
}
}
Expand All @@ -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<Self, DecodeError> {
fn decode_value<R: BufRead>(mut value: ValueDecoder<'_, R>) -> Result<Self, DecodeError> {
Ok(Self::from_be_bytes(value.consume_array()?))
}
}
Expand All @@ -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<Option<Decoder<'r, R>>, DecodeError> {
pub fn start_decoder<R: BufRead>(reader: &mut R) -> Result<Option<Decoder<'_, R>>, DecodeError> {
let Some(head) = read_atom_head(reader)? else {
return Ok(None);
};
Expand Down Expand Up @@ -191,6 +180,7 @@ impl<'r, R: BufRead> SegmentDecoder<'r, R> {
Ok(())
}

#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Result<Option<Decoder<'_, R>>, DecodeError> {
if self.completed {
return Ok(None);
Expand Down Expand Up @@ -227,7 +217,7 @@ pub enum Decoder<'r, R> {
Value(ValueDecoder<'r, R>),
}

impl<'r, R: BufRead> Decoder<'r, R> {
impl<R: BufRead> Decoder<'_, R> {
pub fn skip(self) -> Result<(), DecodeError> {
match self {
Decoder::Segment(mut segment) => segment.skip(),
Expand All @@ -254,7 +244,7 @@ pub struct ValueDecoder<'r, R> {
remaining: u64,
}

impl<'r, R: BufRead> ValueDecoder<'r, R> {
impl<R: BufRead> ValueDecoder<'_, R> {
pub fn tag(&self) -> Tag {
self.head.tag()
}
Expand Down Expand Up @@ -285,7 +275,7 @@ impl<'r, R: BufRead> ValueDecoder<'r, R> {
}
}

impl<'r, R: Seek> ValueDecoder<'r, R> {
impl<R: Seek> ValueDecoder<'_, R> {
pub fn skip_seek(&mut self) -> io::Result<()> {
self.reader.seek_relative(self.remaining as i64)?;
self.remaining = 0;
Expand Down
8 changes: 4 additions & 4 deletions crates/rugpi-common/src/artifact/format/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: std::io::BufRead>(
mut segment: $crate::artifact::format::decode::SegmentDecoder<'_, R>,
) -> Result<Self, $crate::artifact::format::decode::DecodeError> {
$(
let mut $field_name = <$field_type>::initial_value();
Expand Down Expand Up @@ -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<R: BufRead>(
mut segment: SegmentDecoder<'_, R>,
) -> Result<Self, DecodeError> {
let mut variant = None;
while let Some(decoder) = segment.next()? {
Expand Down
4 changes: 2 additions & 2 deletions crates/rugpi-common/src/artifact/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: BufRead>(
mut segment: SegmentDecoder<'_, R>,
) -> Result<Self, DecodeError> {
let mut key = None;
let mut map = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/rugpi-common/src/artifact/format/stlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions crates/rugpi-common/src/boot/grub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ pub type GrubEnv = HashMap<String, String>;

pub fn load_grub_env<P: AsRef<Path>>(path: P) -> Result<GrubEnv, Report<GrubEnvError>> {
fn inner(path: &Path) -> Result<GrubEnv, Report<GrubEnvError>> {
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())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rugpi-common/src/disk/blkdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down
4 changes: 2 additions & 2 deletions crates/rugpi-common/src/disk/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct PartitionStream<'stream, R> {
entry: PartitionEntry,
}

impl<'stream, R> PartitionStream<'stream, R> {
impl<R> PartitionStream<'_, R> {
/// The entry of the partition.
pub fn entry(&self) -> &PartitionEntry {
&self.entry
Expand All @@ -196,7 +196,7 @@ impl<'stream, R> PartitionStream<'stream, R> {
}
}

impl<'stream, R: Read> Read for PartitionStream<'stream, R> {
impl<R: Read> Read for PartitionStream<'_, R> {
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
if self.remaining < buf.len() as u64 {
if self.remaining == 0 {
Expand Down
6 changes: 3 additions & 3 deletions crates/rugpi-common/src/system/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn resolve_data_partition(
config: &PartitionConfig,
) -> Option<BlockDevice> {
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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/rugpi-common/src/utils/const_helpers.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions crates/rugpi-ctrl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down
2 changes: 1 addition & 1 deletion crates/rugpi-ctrl/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 07a1751

Please sign in to comment.