Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing different-size int <-> NonZeroInt conversions #84352

Open
clarfonthey opened this issue Apr 19, 2021 · 2 comments
Open

Missing different-size int <-> NonZeroInt conversions #84352

clarfonthey opened this issue Apr 19, 2021 · 2 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

Right now, we have most of the integer type interconversions implemented, but we're missing some falliable NonZero conversions. Namely these:

  • iN -> NonZeroIM (where N != M)
  • uN -> NonZeroIM (where N != M)
  • iN -> NonZeroUM (where N != M)
  • uN -> NonZeroUM (where N != M)
  • NonZeroIN -> iM (where N != M)
  • NonZeroIN -> uM (where N != M)
  • NonZeroUN -> iM (where N != M)
  • NonZeroUN -> uM (where N != M)

Right now, all of the integer <-> non-zero integer conversions only operate on types of the same size, rather than all the different sizes that the usual conversions allow.

Not sure if these sorts of conversions would be accepted, but my guess is that closing the transitive gap would be a good idea.

@leonardo-m
Copy link

You're right, they are useful, this conversion contains an useless division by zero test:

#[cfg(target_pointer_width = "64")]
pub fn foo(x: u64, y: NonZeroUsize) -> u64 {
    x / (y.get() as u64)
}

@clarfonthey
Copy link
Contributor Author

There is an implementation for division by nonzero now, but yeah, there are cases where it'd be nice. But the question is mostly if they are worth the effort to add.

@Dylan-DPC Dylan-DPC added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants