Skip to content

cargo clippy --fix fails to fix unneeded return #9192

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

Closed
Seeker14491 opened this issue Jul 17, 2022 · 1 comment · Fixed by #9497
Closed

cargo clippy --fix fails to fix unneeded return #9192

Seeker14491 opened this issue Jul 17, 2022 · 1 comment · Fixed by #9497
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Seeker14491
Copy link

Running cargo clippy --fix fails to fix the following code:

fn f() -> i32 {
    {
        return 0;
    };
}

It tries to convert the return 0; into an implicit return, but it fails to remove the semicolon on the following line, which causes the error.

Full Output

$ cargo clippy --fix
    Checking rustfmt-debug v0.1.0 (/home/seekr/Desktop/rustfmt-debug)
warning: failed to automatically apply fixes suggested by rustc to crate `rustfmt_debug`

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

  * src/lib.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[E0308]: mismatched types
 --> src/lib.rs:1:15
  |
1 | pub fn f() -> i32 {
  |        -      ^^^ expected `i32`, found `()`
  |        |
  |        implicitly returns `()` as its body has no tail or `return` expression
...
4 |     };
  |      - help: remove this semicolon

error: aborting due to previous error

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

warning: unneeded `return` statement
 --> src/lib.rs:3:9
  |
3 |         return 0;
  |         ^^^^^^^^^ help: remove `return`: `0`
  |
  = note: `#[warn(clippy::needless_return)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: `rustfmt-debug` (lib) generated 1 warning (1 duplicate)
warning: `rustfmt-debug` (lib test) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (c2f428d2f 2022-07-14)
binary: rustc
commit-hash: c2f428d2f3340a0e7d995f4726223db91b93704c
commit-date: 2022-07-14
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6
@Seeker14491 Seeker14491 added the C-bug Category: Clippy is not doing the correct thing label Jul 17, 2022
@matthiaskrgr matthiaskrgr transferred this issue from rust-lang/rust Jul 17, 2022
@Alexendoo Alexendoo added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jul 17, 2022
@kraktus
Copy link
Contributor

kraktus commented Sep 18, 2022

This should be catch by unused_braces compiler lint in the first place

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-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.

3 participants