Skip to content

Make the NonZero* methods const fn #53331

New issue

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

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

Already on GitHub? # to your account

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-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) 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 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

bors added a commit that referenced this issue Dec 28, 2018
Make the getter for NonZero types into a const fn

Closes #53331

Rework of #56739

cc @Lokathor

r? @oli-obk
@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) 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.

5 participants