Skip to content

Commit

Permalink
Fix new clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Oct 23, 2023
1 parent 21eb49b commit 6b2173b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion binrw/src/binwrite/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<T> BinWrite for PhantomData<T> {
&self,
_: &mut W,
_: Endian,
_: Self::Args<'_>,
(): Self::Args<'_>,
) -> BinResult<()> {
Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions binrw/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ where

/// Reads a 24-bit unsigned integer.
///
/// # Errors
///
/// If reading fails, an [`Error`](crate::Error) variant will be returned.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -514,6 +518,10 @@ pub fn read_u24() -> binrw::BinResult<u32> {

/// Writes a 24-bit unsigned integer.
///
/// # Errors
///
/// If writing fails, an [`Error`](crate::Error) variant will be returned.
///
/// # Examples
///
/// ```
Expand Down
14 changes: 7 additions & 7 deletions binrw_derive/src/binrw/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub(crate) struct BacktraceFrame {
}

struct Line {
line_num: usize,
num: usize,
start_col: usize,
line: String,
text: String,
}

impl BacktraceFrame {
Expand Down Expand Up @@ -58,9 +58,9 @@ impl BacktraceFrame {
(min_whitespace + 1, line)
}))
.map(|(line_num, (start_col, line))| Line {
line_num,
num: line_num,
start_col,
line,
text: line,
})
.collect::<Vec<_>>()
.into_iter(),
Expand All @@ -73,9 +73,9 @@ impl BacktraceFrame {
fn write_line(
&self,
Line {
line_num,
num: line_num,
start_col,
line,
text: line,
}: Line,
max_digits: usize,
f: &mut Formatter<'_>,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl BacktraceFrame {
.map(|x| x.0.start)
.chain(core::iter::once(start_col + line.len()));

if let Some((first_range, _)) = line_highlights.highlights.get(0) {
if let Some((first_range, _)) = line_highlights.highlights.first() {
let component = &line[..first_range.start - start_col];

write!(f, "{}", conditional_bold(&component, should_highlight))?;
Expand Down
2 changes: 1 addition & 1 deletion binrw_derive/src/binrw/parser/top_level_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ attr_struct! {
impl Struct {
pub(crate) fn is_tuple(&self) -> bool {
self.fields
.get(0)
.first()
.map_or(false, |field| field.generated_ident)
}

Expand Down
13 changes: 9 additions & 4 deletions binrw_derive/src/named_args/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ident_str! {
NAMED_ARGS = from_crate!(NamedArgs);
}

// Lint: Describing which field name is which prevents confusion.
#[cfg_attr(nightly, allow(clippy::struct_field_names))]
pub(super) struct Builder<'a> {
pub(super) owner_name: Option<&'a Ident>,
pub(super) builder_name: &'a Ident,
Expand Down Expand Up @@ -297,8 +299,12 @@ impl<'a> Builder<'a> {
quote! { #(#unwraps,)* }
};

let finalizers = self.fields.iter().enumerate().filter_map(|(i, field)| {
matches!(field.kind, BuilderFieldKind::TryOptional).then(|| {
let finalizers = self
.fields
.iter()
.enumerate()
.filter(|(_, field)| matches!(field.kind, BuilderFieldKind::TryOptional))
.map(|(i, field)| {
let current_field_ty = &field.ty;
let satisfied_generics = generics.iter().enumerate().map(|(n, generic)| {
if i == n {
Expand Down Expand Up @@ -342,8 +348,7 @@ impl<'a> Builder<'a> {
}
}
}
})
});
});

quote! { #(#finalizers)* }
}
Expand Down

0 comments on commit 6b2173b

Please sign in to comment.