Skip to content

Make the NonZero* methods const fn #53331

Description

@oli-obk

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.

Activity

  1. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Aug 14, 2018
  2. eddyb commented on Aug 14, 2018

    @eddyb
    Contributor

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

  3. oli-obk commented on Aug 14, 2018

    @oli-obk
    ContributorAuthor

    Ah I thought there were more trivial methods.

    This issue is only acctionable for get at the moment

  4. MagnumOpus21 commented on Aug 18, 2018

    @MagnumOpus21
    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.

  5. oli-obk commented on Aug 20, 2018

    @oli-obk
    ContributorAuthor

    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
  6. TimDiekmann commented on Sep 1, 2018

    @TimDiekmann
    Contributor

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

  7. MagnumOpus21 commented on Sep 1, 2018

    @MagnumOpus21
    Contributor

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

  8. TimDiekmann commented on Sep 1, 2018

    @TimDiekmann
    Contributor

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

  9. MagnumOpus21 commented on Sep 1, 2018

    @MagnumOpus21
    Contributor

    Thank you 😄 @cyres

  10. added a commit that references this issue on Dec 28, 2018
  11. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions