-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Feature Request: NonZeroInt literal coersion #69329
Copy link
Copy link
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
Description
Activity
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
It should be possible for an integer literal to initialize a
NonZeroInttype, likeNonZeroUsize. For instance, this should be legal:The compiler can easily check whether the literal is zero and fail if it is.
While I know that the
NonZerotypes are "just" regular structs, it seems as though they already have so many special compiler attributes attached to them to ensure that they work with Option correctly that it seems like it wouldn't be much of a stretch to have this one as well (though I'm happy to be corrected there).