Skip to content

Another false positive: match_same_arms vs. &Any #1218

Closed
@llogiq

Description

@llogiq

If the two arms do not have the same actual type, pulling them together with | will fail. The lint should not trigger if the actual types of the match arms differ.

E.g.

enum Foo<'a> {
    Bar(&'a FooBar),
    Baz(&'a Buzz),
}

let x: &Any = match foo {
    Bar(ref bar) => bar,
    Baz(ref bar) => bar,
}

Changing it to

let x: &Any = match foo {
    Bar(ref bar) |
    Baz(ref bar) => bar,
}

will fail with a type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.E-needs-mcveCall for participation: This issue needs a Minimal Complete and Verifiable ExampleI-false-positiveIssue: The lint was triggered on code it shouldn't haveL-correctnessLint: Belongs in the correctness lint groupT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions