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: different warnings for equivalent code (return from match arm) #4238

Closed
matthiaskrgr opened this issue Jun 28, 2019 · 0 comments · Fixed by #4262
Closed
Labels
L-style Lint: Belongs in the style lint group

Comments

@matthiaskrgr
Copy link
Member

pub fn fun(a: i32) {
    match a {
        1 => return,
        2 => {
            println!("false");
        }
        _ => {}
    }
}

this code warns:

warning: unneeded return statement
 --> src/main.rs:5:14
  |
5 |         1 => return,
  |              ^^^^^^ help: replace `return` with the unit type: `()`
  |
  = note: #[warn(clippy::needless_return)] on by default

but equivalent code

pub fn fun(a: i32) {
    match a {
        1 => {
            return;
        }
        2 => {
            println!("false");
        }
        _ => {}
    }
}

warns

warning: unneeded return statement
 --> src/main.rs:6:13
  |
6 |             return;
  |             ^^^^^^^ help: remove `return`
  |
  = note: #[warn(clippy::needless_return)] on by default

IMO, suggesting x => (), is strange and I would rather have x => {}, suggested in both cases, so maybe we could unify this?

Might be a byproduct of #4220
clippy 0.0.212 (e3cb40e 2019-06-25)

@matthiaskrgr matthiaskrgr added the L-style Lint: Belongs in the style lint group label Jun 28, 2019
bors added a commit that referenced this issue Jul 9, 2019
Use empty block instead of unit type for needless return

fixes #4238

changelog: Use empty block instead of unit type for needless return
@bors bors closed this as completed in #4262 Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-style Lint: Belongs in the style lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant