Closed
Description
Summary
Hi,
Thanks for your work on clippy.
It seems like clippy's fix for an unnecessary return doesn't account for trailing semicolons and fixes return true;;
to true;
, causing an error. I was able to reproduce it on stable, nightly and on master (commit 46981dca3622f5d53c88219f35113e553de20e1a
).
Reproducer
Minimised:
// lib.rs
fn _breaks_clippy_fix() -> bool {
return true;;
}
〉cargo clippy --fix
Checking sandbox_rs v0.1.0 (/drive/ssd_ext4/Dev/sandbox/sandbox_rs)
warning: failed to automatically apply fixes suggested by rustc to crate `sandbox_rs`
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:31
|
1 | pub fn breaks_clippy_fix() -> bool {
| ----------------- ^^^^ expected `bool`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
2 | true;
| - help: remove this semicolon to return this value
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.
warning: unnecessary trailing semicolon
--> src/lib.rs:2:17
|
2 | return true;;
| ^ help: remove this semicolon
|
= note: `#[warn(redundant_semicolons)]` on by default
warning: unneeded `return` statement
--> src/lib.rs:2:5
|
2 | return true;;
| ^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
= note: `#[warn(clippy::needless_return)]` on by default
= help: remove `return`
warning: `sandbox_rs` (lib) generated 2 warnings
warning: `sandbox_rs` (lib test) generated 2 warnings (2 duplicates)
Finished dev [unoptimized + debuginfo] target(s) in 0.35s
Version
rustc +stable --version --verbose
:
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2
rustc +nightly --version --verbose
:
rustc 1.68.0-nightly (cc47b0699 2023-01-08)
binary: rustc
commit-hash: cc47b069983292e4ee8982d5dabe6301452c5f25
commit-date: 2023-01-08
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6