Skip to content

needless_return: different warnings for equivalent code (return from match arm) #4238

Closed
@matthiaskrgr

Description

@matthiaskrgr
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-styleLint: Belongs in the style lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions