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

Make the NonZero* methods const fn #53331

Closed
oli-obk opened this issue Aug 14, 2018 · 8 comments · Fixed by #57167
Closed

Make the NonZero* methods const fn #53331

oli-obk opened this issue Aug 14, 2018 · 8 comments · Fixed by #57167
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Aug 14, 2018

and undo the const -> fn changes in https://github.com/rust-lang/rust/pull/53315/files#diff-a4a060a3c734b42317d2b9136d68918eL186

This requires changing applicable methods on NonZero* from fn to const fn, adding the #[rustc_const_unstable="const_nonzero*_methods"] attribute to all of them and adding some tests ensuring that the methods are not const fn on stable rust.

@oli-obk oli-obk added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. labels Aug 14, 2018
@eddyb
Copy link
Member

eddyb commented Aug 14, 2018

Doesn't this require panicking in constants?
Ah, no, it requires conditional control-flow.

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 14, 2018

Ah I thought there were more trivial methods.

This issue is only acctionable for get at the moment

@MagnumOpus21
Copy link
Contributor

Hi, I'd like to help out on this. I would appreciate if some one gave me pointers on what needs to be accomplished.

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 20, 2018

Steps:

  1. add const to https://github.com/rust-lang/rust/blob/master/src/libcore/num/mod.rs#L80
  2. add the rustc_const_unstable attribute
  3. add a test in src/test/ui/const that shows a const usage of the method (needs the feature gate specified in rustc_const_unstable
  4. See whether the linked commit above can be partially reverted

@TimDiekmann
Copy link
Member

@MagnumOpus21 you may take a look at #53697. These are the steps you have to do in order to add const.

@MagnumOpus21
Copy link
Contributor

@cyres I will do that sir. Was busy with my internship.

@TimDiekmann
Copy link
Member

@MagnumOpus21 If you need help, don't hesitate to ping me here, in Discord (Cyres#8322) or on StackOverflow in the rust chat room.

@MagnumOpus21
Copy link
Contributor

Thank you 😄 @cyres

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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants