Skip to content

Tracking Issue for const Result methods #82814

Closed

Description

@jhpratt

Feature gate: #![feature(const_result)]

This is a tracking issue for making a number of Result methods const fn.

Public API

NB: Many of these methods will need ~const Drop. They're omitted here for brevity.

impl<T, E> Result<T, E> {
    pub const fn as_mut(&mut self) -> Result<&mut T, &mut E>;
}

impl<T, E> Result<Option<T>, E> {
    pub const fn transpose(self) -> Option<Result<T, E>>;
}

impl<T, E> Result<&T, E> {
    pub const fn copied(self) -> Result<T, E>
    where
        T: Copy;
}

impl<T, E> Result<&mut T, E> {
    pub const fn copied(self) -> Result<T, E>
    where
        T: Copy;
}

Note some things are missing compared with Option (#67441):

  • unwrap, expect: drops the error, so cannot be done in const.
  • flatten: is not stable yet on Result, even outside const.
  • take, replace: does not exist on Result.

See also #57563.

Please post a comment in this issue if you're submitting a PR that changes any of the above!

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Mar 5, 2021
  2. added a commit that references this issue on Oct 17, 2021
  3. netsutetsu commented on Nov 9, 2022

    @netsutetsu

    Why aren't there unwrap_unchecked and unwrap_err_unchecked while Option::unwrap_unchecked() is going to be const in #91930?

  4. jhpratt commented on Nov 10, 2022

    @jhpratt
    MemberAuthor

    The methods probably didn't exist when this issue was created. I'll add them when I'm on my laptop.

  5. netsutetsu commented on Nov 11, 2022

    @netsutetsu

    Could you also add contains, contains_err (introduced in #62358), inspect, inspect_err (introduced in #91345), flatten (introduced in #70142), copied, cloned and iter since Option::contains(), Option::inspect(), Option::flatten(), Option::copied(), Option::cloned() and Option::iter() will be const in #91930, #67441 and #91582?

  6. jhpratt commented on Nov 13, 2022

    @jhpratt
    MemberAuthor

    Going through the full list now. I'm only going to be adding methods that are already stable, as the unstable methods are tracked in their associated issues.

  7. pitaj commented on Jan 29, 2023

    @pitaj
    Contributor

    @jhpratt PR #104407 for Result::{map, map_or, map_or_else, map_err, as_deref, as_deref_mut, unwrap_or_default, and_then, or_else, unwrap_or_else, unwrap_unchecked, unwrap_err_unchecked, copied, cloned}

  8. jhpratt commented on Jan 29, 2023

    @jhpratt
    MemberAuthor

    @pitaj Thanks. I was already subscribed to the issue, but there's nothing actionable in this tracking issue at the moment.

  9. Pzixel commented on Apr 20, 2023

    @Pzixel

    What happened to const_result? About a week ago everything was fine and now feature gate is gone and with it some of my code started to fail. I understand it's nightly and things change but I don't see any motivation/discussion why this happened. Does anyone have any insights?

  10. c410-f3r commented on Apr 20, 2023

    @c410-f3r
    Contributor

    #110393

    Looks like any stuff related to constant bounds will take a considerable amount of time to be resolved.

  11. RalfJung commented on Sep 9, 2024

    @RalfJung
    Member

    Yeah, most of the things that were in this feature gate unfortunately depend on "const traits" and that's still very experimental.

    The remaining methods listed here, however, can probably be stabilized fairly soon. :)

  12. RalfJung commented on Sep 22, 2024

    @RalfJung
    Member

    @rust-lang/libs-api matching Option, some long-stable Result methods can be const-stabilized now as well. :)
    However, sadly it's much fewer than with Option, because methods like unwrap would drop the error and we can't drop things in const fn.

  13. 3 remaining items

  14. added
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    on Sep 22, 2024
  15. added
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    and removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Oct 1, 2024
  16. rfcbot commented on Oct 1, 2024

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  17. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Oct 11, 2024
  18. rfcbot commented on Oct 11, 2024

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  19. added 2 commits that reference this issue on Oct 11, 2024
  20. added a commit that references this issue on Oct 12, 2024
  21. 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, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions