Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Apply clippy suggestions #24

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

klingtnet
Copy link
Owner

Clippy produced broken code when applying the remaining fix:

    $ cargo clippy --fix
        Checking rosc v0.6.0 (/home/alinz/code/rosc)
    warning: failed to automatically apply fixes suggested by rustc to crate `rosc`
    
    after fixes were automatically applied the compiler reported errors within these files:
    
      * src/decoder.rs
    
    This likely indicates a bug in either rustc or cargo itself,
    and we would appreciate a bug report! You're likely to see
    a number of compiler warnings after this message which cargo
    attempted to fix but failed. If you could open an issue at
    https://github.com/rust-lang/rust/issues
    quoting the full output of this command we'd be very appreciative!
    Note that you may be able to make some more progress in the near-term
    fixing code with the `--broken-code` flag
    
    The following errors were reported:
    error[E0597]: `elem_size` does not live long enough
       --> src/decoder.rs:121:18
        |
    119 | /     map_parser(
    120 | |         |input| {
        | |         ------- value captured here
    121 | |             take(elem_size)(input).map_err(|_: nom::Err<OscError>| {
        | |                  ^^^^^^^^^ borrowed value does not live long enough
    122 | |                 nom::Err::Error(OscError::BadBundle(
    ...   |
    127 | |         |input| decode_packet(input, original_input),
    128 | |     )(input)
        | |_____- a temporary with access to the borrow is created here ...
    129 |   }
        |   -
        |   |
        |   `elem_size` dropped here while still borrowed
        |   ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `impl FnMut(&[u8])-> std::result::Result<(&[u8], types::OscPacket), nom::Err<errors::OscError>>`
        |
        = note: the temporary is part of an expression at the end of a block;
                consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
    help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
        |
    119 ~     let x = map_parser(
    120 |         |input| {
    121 |             take(elem_size)(input).map_err(|_: nom::Err<OscError>| {
    122 |                 nom::Err::Error(OscError::BadBundle(
    123 |                     "Bundle shorter than expected!".to_string(),
    124 |                 ))
      ...
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0597`.
    Original diagnostics will follow.
    
    warning: returning the result of a `let` binding from a block
       --> src/decoder.rs:128:5
        |
    118 | /     let result = map_parser(
    119 | |         |input| {
    120 | |             take(elem_size)(input).map_err(|_: nom::Err<OscError>| {
    121 | |                 nom::Err::Error(OscError::BadBundle(
    ...   |
    126 | |         |input| decode_packet(input, original_input),
    127 | |     )(input);
        | |_____________- unnecessary `let` binding
    128 |       result
        |       ^^^^^^
        |
        = note: `#[warn(clippy::let_and_return)]` on by default
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
    help: return the expression directly
        |
    118 ~
    119 ~     map_parser(
    120 +         |input| {
    121 +             take(elem_size)(input).map_err(|_: nom::Err<OscError>| {
    122 +                 nom::Err::Error(OscError::BadBundle(
    123 +                     "Bundle shorter than expected!".to_string(),
      ...
    
    warning: `rosc` (lib) generated 1 warning
    warning: `rosc` (lib test) generated 1 warning (1 duplicate)
        Finished dev [unoptimized + debuginfo] target(s) in 0.69s

This would not drop the original but only the copy.  Here's the
clippy error:

    calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
    error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
       --> src/decoder.rs:128:5
	|
    128 |     drop(elem_size);
	|     ^^^^^^^^^^^^^^^
	|
	= note: `#[deny(clippy::drop_copy)]` on by default
    note: argument has type u32
       --> src/decoder.rs:128:10
	|
    128 |     drop(elem_size);
	|          ^^^^^^^^^
	= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy
This should be reverted when I sorted out why clippy failed to apply its
suggestions.
Otherwise we would need to depend on std to import f32 and f64
constants.
@klingtnet
Copy link
Owner Author

A merge is blocked by rust-lang/rust#91523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant