Skip to content

Commit

Permalink
Fix new nightly lints
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Jun 7, 2024
1 parent 5a63ecd commit 4f4c690
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions binrw/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
fn main() {
println!("cargo:rustc-check-cfg=cfg(coverage)");
println!("cargo:rustc-check-cfg=cfg(coverage_nightly)");
println!("cargo:rustc-check-cfg=cfg(nightly)");
if is_nightly().unwrap_or(false) {
println!("cargo:rustc-cfg=nightly");
}
Expand Down
8 changes: 4 additions & 4 deletions binrw/doc/attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,18 @@ started.

# Backtrace

When an error is raised during parsing, BinRead forms a backtrace, bubbling the
When an error is raised during parsing, `BinRead` forms a backtrace, bubbling the
error upwards and attaching additional information (surrounding code, line numbers,
messages, etc.) in order to aid in debugging.

The `#[br(err_context(...))]` attribute can work in one of two ways:

1. If the first (or only) item is a string literal, it will be a message format string,
with any other arguments being used as arguments. This uses the same formatting as `format!`,
`println!`, and other standard library formatters.
with any other arguments being used as arguments. This uses the same formatting as `format!`,
`println!`, and other standard library formatters.

2. Otherwise, only a single argument is allowed, which will then be attached as a context
type. This type must implement [`Display`](std::fmt::Display), [`Debug`], [`Send`], and [`Sync`].
type. This type must implement [`Display`](std::fmt::Display), [`Debug`], [`Send`], and [`Sync`].

## Example

Expand Down
4 changes: 2 additions & 2 deletions binrw/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ See the [`BinRead`](BinRead#foreign-impls) and
[`BinWrite`](BinWrite#foreign-impls) traits for the full list of built-in
implementations.

# no_std support
# `no_std` support

binrw supports no_std and includes a compatible subset of [`io`]
binrw supports `no_std` and includes a compatible subset of [`io`]
functionality. The [`alloc`] crate is required.
15 changes: 12 additions & 3 deletions binrw/tests/ui/args_vec_mistakes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ error[E0277]: the trait bound `usize: TryFrom<Option<{integer}>>` is not satisfi
|
= help: the following other types implement trait `From<T>`:
<usize as From<bool>>
<usize as From<u8>>
<usize as From<u16>>
<usize as From<std::ptr::Alignment>>
<usize as From<u16>>
<usize as From<u8>>
= note: required for `Option<{integer}>` to implement `Into<usize>`
= note: required for `usize` to implement `TryFrom<Option<{integer}>>`

error[E0599]: the method `finalize` exists for struct `VecArgsBuilder<(NoDefault,), Satisfied, Needed>`, but its trait bounds were not satisfied
--> tests/ui/args_vec_mistakes.rs:25:42
|
4 | struct NoDefault;
| ---------------- doesn't satisfy `NoDefault: Default`
...
25 | struct MissingInnerArgs(#[br(count = 1)] Vec<Inner>);
| ^^^^^^^^^^ method cannot be called on `VecArgsBuilder<(NoDefault,), Satisfied, Needed>` due to unsatisfied trait bounds
|
Expand All @@ -65,9 +68,15 @@ error[E0599]: the method `finalize` exists for struct `VecArgsBuilder<(NoDefault
| ----------------- doesn't satisfy `Needed: SatisfiedOrOptional`
|
= note: the following trait bounds were not satisfied:
`(NoDefault,): Default`
`NoDefault: Default`
which is required by `(NoDefault,): Default`
`Needed: SatisfiedOrOptional`
= note: this error originates in the macro `binrw::args` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `NoDefault` with `#[derive(Default)]`
|
4 + #[derive(Default)]
5 | struct NoDefault;
|

error[E0277]: the trait bound `VecArgs<()>: Required` is not satisfied
--> tests/ui/args_vec_mistakes.rs:28:5
Expand Down
6 changes: 5 additions & 1 deletion binrw/tests/ui/bad_parse_with_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0277]: expected a `FnOnce(&mut _, binrw::Endian, _)` closure, found `{int
10 | #[br(parse_with = 56)]
| ^^ expected an `FnOnce(&mut _, binrw::Endian, _)` closure, found `{integer}`
|
= help: the trait `for<'a> FnOnce<(&'a mut _, binrw::Endian, _)>` is not implemented for `{integer}`
= help: the trait `for<'a> FnOnce(&'a mut _, binrw::Endian, _)` is not implemented for `{integer}`
note: required by a bound in `parse_fn_type_hint`
--> src/private.rs
|
Expand Down Expand Up @@ -44,9 +44,13 @@ error[E0308]: mismatched types
|
14 | #[br(parse_with = |_, _, _| { Ok(true) })]
| ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `bool`
15 | c: i32,
| --- expected `i32` because of return type

error[E0308]: mismatched types
--> tests/ui/bad_parse_with_fn.rs:16:23
|
16 | #[br(parse_with = wrong)]
| ^^^^^ expected `i32`, found `bool`
17 | d: i32,
| --- expected `i32` because of return type
3 changes: 3 additions & 0 deletions binrw_derive/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
fn main() {
println!("cargo:rustc-check-cfg=cfg(coverage)");
println!("cargo:rustc-check-cfg=cfg(coverage_nightly)");
println!("cargo:rustc-check-cfg=cfg(nightly)");
if is_nightly().unwrap_or(false) {
println!("cargo:rustc-cfg=nightly");
}
Expand Down
2 changes: 1 addition & 1 deletion binrw_derive/src/binrw/backtrace/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn visit_expr_attributes(field: &StructField, visitor: &mut Visitor) {
visit!(err);
}

for context_expr in &field.err_context {
if let Some(context_expr) = &field.err_context {
match context_expr {
ErrContext::Context(expr) => visit!(expr.to_token_stream()),
ErrContext::Format(fmt, exprs) => {
Expand Down
4 changes: 4 additions & 0 deletions binrw_derive/src/meta_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,31 @@ type Fields<T> = Punctuated<T, Token![,]>;
/// Takes two forms:
/// * ident(expr)
/// * ident = expr
///
/// both are always allowed
pub(crate) type MetaExpr<Keyword> = MetaValue<Keyword, Expr>;

/// `MetaType` represents a key/ty pair
/// Takes two forms:
/// * ident(ty)
/// * ident = ty
///
/// both are always allowed
pub(crate) type MetaType<Keyword> = MetaValue<Keyword, Type>;

/// `MetaIdent` represents a key/ident pair
/// Takes two forms:
/// * ident(ident)
/// * ident = ident
///
/// both are always allowed
pub(crate) type MetaIdent<Keyword> = MetaValue<Keyword, Ident>;

/// `MetaLit` represents a key/lit pair
/// Takes two forms:
/// * ident(lit)
/// * ident = lit
///
/// both are always allowed
pub(crate) type MetaLit<Keyword> = MetaValue<Keyword, Lit>;

Expand Down

0 comments on commit 4f4c690

Please sign in to comment.