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

needless_return fix doesn't compile with extra semicolon present #7358

Closed
ComputerDruid opened this issue Jun 16, 2021 · 0 comments · Fixed by #9497
Closed

needless_return fix doesn't compile with extra semicolon present #7358

ComputerDruid opened this issue Jun 16, 2021 · 0 comments · Fixed by #9497
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

@ComputerDruid
Copy link

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=795f032d10430e5954f6a119e2e5bcbd

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
    
@ComputerDruid ComputerDruid added the C-bug Category: Clippy is not doing the correct thing label Jun 16, 2021
@giraffate giraffate added 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 labels Jun 30, 2021
@bors bors closed this as completed in 47c9145 Sep 27, 2022
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