Repository: rust
Issue: `cargo clippy --fix` created a lifetime issue by applying a fix
Labels: C-bug,A-clippy,S-needs-repro

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```sh
$ 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
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`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
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
No backtrace available.
```

</p>
</details>

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