Skip to content

Commit

Permalink
Updates for new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Mar 30, 2024
1 parent b4eeafa commit f4eb576
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 32 deletions.
1 change: 1 addition & 0 deletions binrw/src/binread/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
io::{self, Read, Seek},
BinRead, BinResult, Endian, Error, NamedArgs,
};
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};
use core::num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16,
Expand Down
1 change: 1 addition & 0 deletions binrw/src/binwrite/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
io::{Seek, Write},
BinResult, BinWrite, Endian,
};
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};
use core::{
any::Any,
Expand Down
1 change: 1 addition & 0 deletions binrw/src/endian.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Type definitions for byte order handling.
use crate::BinResult;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
pub use Endian::{Big as BE, Little as LE};

Expand Down
4 changes: 3 additions & 1 deletion binrw/src/error/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::{ContextExt, CustomError, Error};
use alloc::{borrow::Cow, boxed::Box, format, string::ToString, vec::Vec};
use alloc::borrow::Cow;
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
use core::fmt::{self, Write};

#[cfg(feature = "verbose-backtrace")]
Expand Down
8 changes: 4 additions & 4 deletions binrw/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
mod backtrace;

use crate::{
alloc::{borrow::Cow, boxed::Box, string::String, vec, vec::Vec},
io, BinResult,
};
use crate::{io, BinResult};
use alloc::borrow::Cow;
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, string::String, vec, vec::Vec};
pub use backtrace::*;
use core::{any::Any, fmt};

Expand Down
1 change: 1 addition & 0 deletions binrw/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
io::{self, Read, Seek},
BinRead, BinResult, Endian, Error,
};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::iter::from_fn;

Expand Down
1 change: 1 addition & 0 deletions binrw/src/io/seek.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Wrapper type that provides a fake [`Seek`](crate::io::Seek) implementation.
use super::{Error, ErrorKind, SeekFrom};
#[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec};

/// A wrapper that provides a limited implementation of
Expand Down
1 change: 1 addition & 0 deletions binrw/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! [`BinWrite`]: crate::BinWrite
use crate::Endian;
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};
use core::marker::PhantomData;

Expand Down
1 change: 1 addition & 0 deletions binrw/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
io::{Read, Seek, SeekFrom, Write},
BinRead, BinResult, BinWrite, Endian, Error,
};
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, string::String};

pub use crate::named_args::{
Expand Down
1 change: 1 addition & 0 deletions binrw/src/punctuated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Type definitions for wrappers which parse interleaved data.
use crate::{BinRead, BinResult, VecArgs};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::fmt;

Expand Down
1 change: 1 addition & 0 deletions binrw/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
io::{Read, Seek, Write},
BinRead, BinResult, BinWrite, Endian,
};
#[cfg(not(feature = "std"))]
use alloc::{string::String, vec, vec::Vec};
use core::fmt::{self, Write as _};

Expand Down
11 changes: 10 additions & 1 deletion binrw/tests/derive/write/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn map_field() {

#[test]
fn map_field_code_coverage() {
#[allow(dead_code)]
#[derive(BinWrite)]
struct Test {
#[bw(map = |&x| x as u64)]
Expand Down Expand Up @@ -92,6 +93,7 @@ fn map_repr_struct() {

#[test]
fn map_repr_struct_field() {
#[allow(dead_code)]
#[derive(BinWrite, Debug)]
#[bw(big)]
struct Test {
Expand All @@ -117,7 +119,14 @@ fn try_map() {

#[derive(BinWrite)]
struct MyType {
#[bw(try_map = |&x| -> BinResult<i8> { x.try_into().map_err(|_| todo!()) })]
#[bw(try_map = |&x| { i8::try_from(x) })]
value: u8,
}

let mut x = Cursor::new(Vec::new());
MyType { value: 127 }.write_le(&mut x).unwrap();
assert_eq!(x.into_inner(), b"\x7f");

let mut x = Cursor::new(Vec::new());
MyType { value: 128 }.write_le(&mut x).unwrap_err();
}
2 changes: 1 addition & 1 deletion binrw/tests/ui/args_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use binrw::BinRead;
struct NoDefault;

#[derive(BinRead)]
#[br(import(a: NoDefault))]
#[br(import(_a: NoDefault))]
struct Foo;

#[derive(BinRead)]
Expand Down
2 changes: 1 addition & 1 deletion binrw/tests/ui/args_missing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `NoDefault: Default` is not satisfied
--> tests/ui/args_missing.rs:12:8
|
12 | a: Foo,
| ^^^ the trait `Default` is not implemented for `NoDefault`
| ^^^ the trait `Default` is not implemented for `NoDefault`, which is required by `(NoDefault,): MissingArgsDirective`
|
= note: required for `(NoDefault,)` to implement `Default`
= note: required for `(NoDefault,)` to implement `MissingArgsDirective`
Expand Down
13 changes: 6 additions & 7 deletions binrw/tests/ui/args_vec_mistakes.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `VecArgs<()>: Default` is not satisfied
error[E0277]: the trait bound `VecArgs<()>: MissingArgsDirective` is not satisfied
--> tests/ui/args_vec_mistakes.rs:7:20
|
7 | struct MissingArgs(Vec<u8>);
| ^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`
| ^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`, which is required by `VecArgs<()>: MissingArgsDirective`
|
= note: required for `VecArgs<()>` to implement `MissingArgsDirective`
note: required by a bound in `Required::args`
Expand Down Expand Up @@ -39,17 +39,16 @@ error[E0599]: the method `finalize` exists for struct `VecArgsBuilder<(), Needed
`Needed: SatisfiedOrOptional`
= note: this error originates in the macro `binrw::args` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: From<Option<{integer}>>` is not satisfied
error[E0277]: the trait bound `usize: TryFrom<Option<{integer}>>` is not satisfied
--> tests/ui/args_vec_mistakes.rs:22:36
|
22 | struct WrongCountType(#[br(count = Some(1))] Vec<u8>);
| ^^^^^^^ the trait `From<Option<{integer}>>` is not implemented for `usize`
| ^^^^^^^ the trait `From<Option<{integer}>>` is not implemented for `usize`, which is required by `usize: TryFrom<Option<{integer}>>`
|
= help: the following other types implement trait `From<T>`:
<usize as From<bool>>
<usize as From<u8>>
<usize as From<u16>>
<usize as From<NonZeroUsize>>
<usize as From<std::ptr::Alignment>>
= note: required for `Option<{integer}>` to implement `Into<usize>`
= note: required for `usize` to implement `TryFrom<Option<{integer}>>`
Expand All @@ -70,11 +69,11 @@ error[E0599]: the method `finalize` exists for struct `VecArgsBuilder<(NoDefault
`Needed: SatisfiedOrOptional`
= note: this error originates in the macro `binrw::args` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `VecArgs<()>: Default` is not satisfied
error[E0277]: the trait bound `VecArgs<()>: Required` is not satisfied
--> tests/ui/args_vec_mistakes.rs:28:5
|
28 | Vec::<u8>::read(&mut binrw::io::Cursor::new(b"")).unwrap();
| ^^^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`
| ^^^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`, which is required by `VecArgs<()>: Required`
|
= note: required for `VecArgs<()>` to implement `Required`
note: required by a bound in `binrw::BinRead::read`
Expand Down
2 changes: 1 addition & 1 deletion binrw/tests/ui/bad_args_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use binrw::binrw;

#[binrw]
#[br(import { a: u8 })]
#[br(import { _a: u8 })]
struct Item;

#[binrw]
Expand Down
2 changes: 1 addition & 1 deletion binrw/tests/ui/binrw_br_temp_no_bw_ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use binrw::binrw;
#[binrw]
struct Test {
#[br(temp)]
len: u32,
_len: u32,
}

fn main() {}
4 changes: 2 additions & 2 deletions binrw/tests/ui/binrw_br_temp_no_bw_ignore.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ error: `#[br(temp)]` is invalid without a corresponding `#[bw(ignore)]`, `#[bw(c
--> tests/ui/binrw_br_temp_no_bw_ignore.rs:5:5
|
5 | / #[br(temp)]
6 | | len: u32,
| |____________^
6 | | _len: u32,
| |_____________^
2 changes: 1 addition & 1 deletion binrw/tests/ui/conflicting_keyword_count_args.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use binrw::BinRead;

#[derive(BinRead)]
#[br(import(a: u8))]
#[br(import(_a: u8))]
struct Item;

#[derive(BinRead)]
Expand Down
6 changes: 3 additions & 3 deletions binrw/tests/ui/fn_helper_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ fn fn_helper_missing_args_reader(...) -> BinResult<()> {
}

#[parser]
fn fn_helper_extra_args_reader(arg0: (), arg1: (), ...) -> BinResult<()> {
fn fn_helper_extra_args_reader(_arg0: (), _arg1: (), ...) -> BinResult<()> {
Ok(())
}

#[writer]
fn fn_helper_extra_args_writer(arg0: &(), arg1: (), arg2: (), ...) -> BinResult<()> {
fn fn_helper_extra_args_writer(_arg0: &(), _arg1: (), _arg2: (), ...) -> BinResult<()> {
Ok(())
}

#[writer]
fn fn_helper_missing_args_writer(obj: &(), ...) -> BinResult<()> {
fn fn_helper_missing_args_writer(_obj: &(), ...) -> BinResult<()> {
Ok(())
}

Expand Down
18 changes: 9 additions & 9 deletions binrw/tests/ui/fn_helper_errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ error: missing raw arguments parameter
| ^^^

error: unexpected extra parameter after raw arguments
--> tests/ui/fn_helper_errors.rs:57:42
--> tests/ui/fn_helper_errors.rs:57:43
|
57 | fn fn_helper_extra_args_reader(arg0: (), arg1: (), ...) -> BinResult<()> {
| ^^^^^^^^
57 | fn fn_helper_extra_args_reader(_arg0: (), _arg1: (), ...) -> BinResult<()> {
| ^^^^^^^^^

error: unexpected extra parameter after raw arguments
--> tests/ui/fn_helper_errors.rs:62:53
--> tests/ui/fn_helper_errors.rs:62:55
|
62 | fn fn_helper_extra_args_writer(arg0: &(), arg1: (), arg2: (), ...) -> BinResult<()> {
| ^^^^^^^^
62 | fn fn_helper_extra_args_writer(_arg0: &(), _arg1: (), _arg2: (), ...) -> BinResult<()> {
| ^^^^^^^^^

error: missing raw arguments parameter
--> tests/ui/fn_helper_errors.rs:67:44
--> tests/ui/fn_helper_errors.rs:67:45
|
67 | fn fn_helper_missing_args_writer(obj: &(), ...) -> BinResult<()> {
| ^^^
67 | fn fn_helper_missing_args_writer(_obj: &(), ...) -> BinResult<()> {
| ^^^

0 comments on commit f4eb576

Please sign in to comment.