Closed
Description
I tried this code:
pub enum Type {
None,
Wep,
}
// minimized from https://cs.opensource.google/fuchsia/fuchsia/+/main:src/connectivity/wlan/wlancfg/tool/src/policy/mod.rs;l=97;drc=819ca746f9fe944467c8c92178355ebe88fb1eeb
pub fn extract_network_id(
network_id: Option<Type>,
) -> (String, String) {
match network_id {
Some(id) => {
let ssid = std::string::String::new();
let security_type = match id {
Type::None => "",
Type::Wep => "wep",
};
return (ssid, security_type.to_string());
}
None => return ("".to_string(), "".to_string()),
};
}
And used --fix
I expected to see this happen:
Needless returns removed, with extra semicolon deleted.
Instead, this happened:
Needless returns removed, but extra semicolon still present, so compile fails:
warning: failed to automatically apply fixes suggested by rustc to crate `clippy_example`
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:9:6
|
7 | pub fn extract_network_id(
| ------------------ implicitly returns `()` as its body has no tail or `return` expression
8 | network_id: Option<Type>,
9 | ) -> (String, String) {
| ^^^^^^^^^^^^^^^^ expected tuple, found `()`
...
20 | };
| - help: consider removing this semicolon
|
= note: expected tuple `(std::string::String, std::string::String)`
found unit type `()`
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:17:13
|
17 | return (ssid, security_type.to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `(ssid, security_type.to_string())`
|
= 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: unneeded `return` statement
--> src/lib.rs:19:17
|
19 | None => return ("".to_string(), "".to_string()),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `("".to_string(), "".to_string())`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
Meta
cargo clippy -V
: clippy 0.1.54 (607d6b0 2021-06-15)rustc -Vv
:rustc 1.55.0-nightly (607d6b00d 2021-06-15) binary: rustc commit-hash: 607d6b00d4e0e0475b8de9d0c870b7126fdcdf6b commit-date: 2021-06-15 host: x86_64-unknown-linux-gnu release: 1.55.0-nightly LLVM version: 12.0.1