Skip to content

Lint negation "followed" by method call #3903

@oli-obk

Description

@oli-obk

Calling -x.foo() will first call foo and then negate. While this is correct as per the precedence rules, it can be surprising (see rust-lang/rust#59388). We should suggest a cleanup either by writing (-x).foo() if that was intended, by writing -(x.foo()) for by introducing an intermediate variable:

let x_foo = x.foo();
-x_foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-complexityLint: Belongs in the complexity lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions