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

Support dividing NonZero integers without zero check #73545

Closed
upsuper opened this issue Jun 20, 2020 · 2 comments
Closed

Support dividing NonZero integers without zero check #73545

upsuper opened this issue Jun 20, 2020 · 2 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@upsuper
Copy link
Contributor

upsuper commented Jun 20, 2020

Currently for the following function

fn foo(a: i32, b: i32) -> i32 { a / b }

it always checks first that b is not zero. It's an unnecessary extra cost when people can logically ensure that the divisor would never be zero.

It would probably be ideal if one can write

fn foo(a: i32, b: NonZeroI32) -> i32 { a / b }

and it doesn't do zero-checking.

@jonas-schievink jonas-schievink added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jun 20, 2020
@leonardo-m
Copy link

You need b.get(). This seems a dupe of #54868

@upsuper
Copy link
Contributor Author

upsuper commented Jun 20, 2020

Yeah, looks like a dupe. Thanks.

@upsuper upsuper closed this as completed Jun 20, 2020
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.
Projects
None yet
Development

No branches or pull requests

3 participants