Skip to content

Suggested code does not compile with or_fun_call #2186

Closed
@jDomantas

Description

@jDomantas

In some cases suggested change regarding or_fun_call lint does not compile. Here's an example:

struct Pair {
    a: u32,
    b: u32,
}

fn foo(x: u32) -> u32 { x }

fn bar(pair: &mut Pair) {
    let borrow = &mut pair.a;
    let b = None.unwrap_or(foo(pair.b));
}

pair is partially borrowed. Calling id(pair.b) is valid, because compiler can see that only field a is borrowed, so field b can be freely used. Clippy suggests to use unwrap_or_else, and move function call into a closure. However, the closure will borrow pair fully which is not possible, and the code will not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-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