Skip to content

Bad suggestion of useless_let_if_seq when having side effects. #4124

Open
@oxalica

Description

@oxalica

The version of clippy is 0.0.212.

Here's an example:

pub fn func() {
    // This need to be called first always.
    let mut ret = foo1();
    if cond() {
        // Overwrite with some complex expr.
        ret = (foo2() * 2).to_string().len() as _;
    }
    
    baz(ret)
}

It suggest writing let <mut> ret = if cond() { .. foo2() .. } else { foo1() };, which cause 3 function calls (may have side-effects) being reordered, and foo1() not always being called.

Well, I'm not sure how to write make it more idiomatic in this case...

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions