Repository navigation
Tracking Issue for const Result methods #82814
Copy link
Copy link
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This 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.The final comment period is finished for this PR / Issue.
Description
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 onResult, even outside const.take,replace: does not exist onResult.
See also #57563.
Please post a comment in this issue if you're submitting a PR that changes any of the above!
Reacted by drcatdoctor and Serhii Potapov
Reacted by León Orell Valerian Liehr, oilaba, David Himmelstrup, arial, Leandro Aguiar, leonardo-m, alex13sh, Markus Pettersson and Serhii Potapov
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This 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.The final comment period is finished for this PR / Issue.
Activity
Rollup merge of rust-lang#89977 - woppopo:result_const_as_mut, r=oli-obk
netsutetsu commentedon Nov 9, 2022
Why aren't there
unwrap_uncheckedandunwrap_err_uncheckedwhileOption::unwrap_unchecked()is going to beconstin #91930?jhpratt commentedon 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 commentedon Nov 11, 2022
Could you also add
contains,contains_err(introduced in #62358),inspect,inspect_err(introduced in #91345),flatten(introduced in #70142),copied,clonedanditersinceOption::contains(),Option::inspect(),Option::flatten(),Option::copied(),Option::cloned()andOption::iter()will beconstin #91930, #67441 and #91582?jhpratt commentedon 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 commentedon 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 commentedon 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 commentedon 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 commentedon Apr 20, 2023
#110393
Looks like any stuff related to constant bounds will take a considerable amount of time to be resolved.
RalfJung commentedon 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 commentedon Sep 22, 2024
@rust-lang/libs-api matching
Option, some long-stableResultmethods can be const-stabilized now as well. :)However, sadly it's much fewer than with
Option, because methods likeunwrapwould drop the error and we can't drop things inconst fn.3 remaining items
rfcbot commentedon Oct 1, 2024
🔔 This is now entering its final comment period, as per the review above. 🔔
rfcbot commentedon Oct 11, 2024
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.
Rollup merge of rust-lang#131287 - RalfJung:const_result, r=tgross35
Rollup merge of rust-lang#131287 - RalfJung:const_result, r=tgross35
Unrolled build for rust-lang#131287