Skip to content

Division by NonZero* checks for zero #76960

Closed
@bugadani

Description

@bugadani

https://rust.godbolt.org/z/eTPzE6

Technically, NonZero* types are not meant to be used for optimizing arithmetic, but people (like myself) may or may not know that or may assume otherwise.

It is possible to create a NonZero* object with 0 inner value, but since that is a misuse of the type and deliberate violation of the safety guarantees, I think it would make sense to teach the compiler that get() can't return 0.

Edit: unfortunately, since NonZero* methods are const, it's not as simple as adding an assume.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions