Skip to content

Tracking Issue for const Result methods #82814

Closed
@jhpratt

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!

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-apiRelevant to the library API team, which will review and decide on the PR/issue.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