Skip to content

Implicit return with brackets only #6480

Open
@Aunmag

Description

@Aunmag

What it does

Improve implicit return lint. It wood be more classic-like style to omit the return keyword on visually inlined closures. Like Java and JS do with lambdas.

Categories (optional)

  • style

What is the advantage of the recommended code over the original code

  • Seems more classic-like as Java's and JS' lambdas.

Drawbacks

None.

Example

fn foo_1(bar: Bar) -> Baz {
    return bar.map(|b| return b.baz.clone());  // needless closure return
}

fn foo_2(bar: Bar) -> Baz {
    return bar.map(|b| {
        b.baz.clone() // missing return, since we use curly brackets
    });
}

Could be written as:

fn foo_1(bar: Bar) -> Baz {
    return bar.map(|b| b.baz.clone());
}

fn foo_2(bar: Bar) -> Baz {
    return bar.map(|b| {
        return b.baz.clone();
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-restrictionLint: Belongs in the restriction lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions