Skip to content

Euclidean operations combined with sign casting cannot result in loss of a sign #4818

Closed
@jhpratt

Description

@jhpratt

.rem_euclid and .div_euclid always results in a non-negative value, so casting to the same or larger size (except unsigned) should be allowed.

(-1_001).rem_euclid(1_000 as i16) as u16

There are also checked versions of these functions (.checked_rem_euclid and .checked_div_euclid) which should also be handled.

Version: clippy 0.0.212 (c8e3cfb 2019-10-28)

Related: #4605 (.abs), #4743 (.checked_abs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions