Skip to content

overloaded unary "-" operator in match arms bug #114380

@dlamei

Description

@dlamei

this doesn't work

match v {
    true => -b?,
    false => None,
}

but this does

match v {
    true => {
        let neg = -b?;
        neg
    }
    false => None,
}

when running cargo clippy:


18 |             let neg = -b?;
   |             -------------- unnecessary `let` binding
19 |             neg
   |             ^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
   = note: `#[warn(clippy::let_and_return)]` on by default
help: return the expression directly
   |
18 ~             
19 ~             -b?

running clippy --fix fails.

sandbox link

rustc --version --verbose:

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceA-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions