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

NonZero* type constructors should be const fn #58732

Closed
dhardy opened this issue Feb 25, 2019 · 3 comments
Closed

NonZero* type constructors should be const fn #58732

dhardy opened this issue Feb 25, 2019 · 3 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dhardy
Copy link
Contributor

dhardy commented Feb 25, 2019

E.g. NonZeroU32::new_unchecked is a const fn but NonZeroU32::new is not; this means that defining constant values is unsafe.

pub const X: NonZeroU32 = unsafe {
    NonZeroU32::new_unchecked(123)
};
@dhardy dhardy changed the title NonZero* type constructions should be const fn NonZero* type constructors should be const fn Feb 25, 2019
@SimonSapin
Copy link
Contributor

This depends on #49146.

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Feb 26, 2019

@rustbot modify labels: +A-const-fn.

Testing the new bot!

@rustbot rustbot added the A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. label Feb 26, 2019
@JohnTitor JohnTitor added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 12, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Sep 17, 2020

This has been fixed in 1.47. NonZero*::new is const now.

m-ou-se added a commit to fusion-engineering-forks/rust that referenced this issue Sep 17, 2020
It was blocked by rust-lang#58732 (const fn NonZeroU32::new), which is fixed now.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 1, 2020
…ero, r=petrochenkov

Fix 'FIXME' about using NonZeroU32 instead of u32.

It was blocked by rust-lang#58732 (const fn NonZeroU32::new), which is fixed now.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 1, 2020
…ero, r=petrochenkov

Fix 'FIXME' about using NonZeroU32 instead of u32.

It was blocked by rust-lang#58732 (const fn NonZeroU32::new), which is fixed now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants