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 attempted to fix let_and_return but failed #11056

Closed
Mcdostone opened this issue Jul 1, 2023 · 0 comments · Fixed by #11061
Closed

cargo clippy attempted to fix let_and_return but failed #11056

Mcdostone opened this issue Jul 1, 2023 · 0 comments · Fixed by #11061
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Mcdostone
Copy link

Summary

Hi, I'm learning rust. I was not able to identify the issue: Clippy attempted to fix a function but it failed.
It looks similar to #91523.

Lint Name

let_and_return

Reproducer

git clone git@github.com:Mcdostone/kconfig.git
cd kconfig
cargo clippy --fix
Backtrace

cargo clippy   --fix --allow-dirty

    Checking kconfig v0.1.0
warning: failed to automatically apply fixes suggested by rustc to crate `kconfig`

after fixes were automatically applied the compiler reported errors within these files:

  * src/kconfig.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]: `file` does not live long enough
  --> src/kconfig.rs:23:19
   |
21 |       map(delimited(ws_comment, many0(parse_entry), ws_comment), |d| {
   |       -                                                          --- value captured here
   |  _____|
   | |
22 | |         Kconfig {
23 | |             file: file.display().to_string(), //input.extra.file.display().to_string(),
   | |                   ^^^^ borrowed value does not live long enough
24 | |             entries: d,
25 | |             //architecture: Noneis_architecture_related(&input.extra.0.clone(), &input.extra.1),
26 | |         }
27 | |     })(input)
   | |______- a temporary with access to the borrow is created here ...
28 |   }
   |   -
   |   |
   |   `file` 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(nom_locate::LocatedSpan<&str, KconfigFile>) -> std::result::Result<(nom_locate::LocatedSpan<&str, KconfigFile>, kconfig::Kconfig), nom::Err<nom::error::Error<nom_locate::LocatedSpan<&str, KconfigFile>>>>`
   |
   = 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
   |
21 ~     let x = map(delimited(ws_comment, many0(parse_entry), ws_comment), |d| {
22 |         Kconfig {
 ...
26 |         }
27 ~     })(input); x
   |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
Original diagnostics will follow.

Version

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

Additional Labels

No response

@Mcdostone Mcdostone added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 1, 2023
@Alexendoo Alexendoo added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jul 2, 2023
@Alexendoo Alexendoo self-assigned this Jul 2, 2023
@bors bors closed this as completed in 83d0682 Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants