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

Tracking Issue for const Result methods #82814

Open
jhpratt opened this issue Mar 5, 2021 · 13 comments · May be fixed by #131287
Open

Tracking Issue for const Result methods #82814

jhpratt opened this issue Mar 5, 2021 · 13 comments · May be fixed by #131287
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jhpratt
Copy link
Member

jhpratt commented Mar 5, 2021

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!

@jhpratt jhpratt added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 5, 2021
@rustbot rustbot added the A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. label Mar 5, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 17, 2021
Make Result::as_mut const

Adding `const` for `Result::as_mut`.

Tracking issue: rust-lang#82814
@netsutetsu
Copy link

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

@jhpratt
Copy link
Member Author

jhpratt commented Nov 10, 2022

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

@netsutetsu
Copy link

netsutetsu commented Nov 11, 2022

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?

@jhpratt
Copy link
Member Author

jhpratt commented Nov 13, 2022

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.

@pitaj
Copy link
Contributor

pitaj commented Jan 29, 2023

@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}

@jhpratt
Copy link
Member Author

jhpratt commented Jan 29, 2023

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

@Pzixel
Copy link

Pzixel commented Apr 20, 2023

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?

@c410-f3r
Copy link
Contributor

#110393

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

@RalfJung
Copy link
Member

RalfJung commented Sep 9, 2024

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. :)

@RalfJung
Copy link
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.

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 22, 2024
@dtolnay
Copy link
Member

dtolnay commented Sep 22, 2024

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Sep 22, 2024

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 22, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 22, 2024
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 1, 2024
@rfcbot
Copy link

rfcbot commented Oct 1, 2024

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

@RalfJung RalfJung linked a pull request Oct 5, 2024 that will close this issue
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. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants