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

cargo clippy --fix created a lifetime issue by applying a fix #91523

Open
klingtnet opened this issue Dec 4, 2021 · 1 comment
Open

cargo clippy --fix created a lifetime issue by applying a fix #91523

klingtnet opened this issue Dec 4, 2021 · 1 comment
Labels
A-clippy Area: Clippy C-bug Category: This is a bug. S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.

Comments

@klingtnet
Copy link
Contributor

I tried this code:

$ cargo clippy --fix

I expected to see this happen: That clippy can apply the fixes without generating broken code.

Instead, this happened: Clippy created a lifetime issue and aborted.

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (532d2b14c 2021-12-03)
binary: rustc
commit-hash: 532d2b14c05f9bc20b2d27cbb5f4550d28343a36
commit-date: 2021-12-03
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
Backtrace

No backtrace available.

Here's the full output of 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 can be reproduced by applying the command to github.com/klingtnet/rosc@apply-clippy-suggestions https://github.com/klingtnet/rosc/compare/apply-clippy-suggestions

@klingtnet klingtnet added the C-bug Category: This is a bug. label Dec 4, 2021
klingtnet added a commit to klingtnet/rosc that referenced this issue Mar 20, 2022
Clippy fails but we cannot fix the error it shows at the moment.  We
should fail again on clippy reporting when rust-lang/rust#91523 is
resolved.
@fmease fmease added A-clippy Area: Clippy S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed needs-triage-legacy labels Jan 24, 2024
@fmease
Copy link
Member

fmease commented Jan 24, 2024

Could you please check if this is still an issue? If so, could you please close this issue and report one over at https://github.com/rust-lang/rust-clippy instead? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-clippy Area: Clippy C-bug Category: This is a bug. S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.
Projects
None yet
Development

No branches or pull requests

3 participants