-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking Issue for const_option_ext
#91930
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Out of interest as I found this in std: where can I find details about the |
You can find the most recent proposal on Rust Internals |
What about things like Current workaround: /// Obtains an Instant using seconds and an adjustment in nanoseconds since '1970-01-01 00:00:00.000000000Z'.
///
/// # Parameters
/// - `epoch_seconds`: the seconds since the epoch.
/// - `nano_adjustment`: the adjustment amount from the given second.
///
/// # Panics
/// - if the adjusted amount of seconds would overflow the instant.
pub const fn of_epoch_second_and_adjustment(
epoch_seconds: i64,
nano_adjustment: i64,
) -> Instant {
match Instant::of_epoch_second_and_adjustment_checked(epoch_seconds, nano_adjustment) {
Some(i) => i,
_ => panic!("nano adjustment would overflow instant"),
}
} |
In #94317 I noticed this feature is WIP for similar methods, but I don't understand it enough to be confident that what I wrote was correct. Please help me verify, thanks. |
Greetings! Any way to do such thing in stable? pub const FOO: usize = option_env!("FOO")
.unwrap_or("123456")
.parse()
.unwrap(); |
Parsing an integer is not converted to const code yet I believe. So you can't do this yet even in nightly. |
Hi, I followed the link from the |
I'm new to Rust. I'm using rust 1.60.0. I'm trying to use this code: pub const VERSION: &'static str = option_env!("VERSION").unwrap_or_else(|| "dev"); but I'm getting this error:
Can you help me understand what's wrong with it? |
You could use pub const VERSION: &'static str = option_env!("VERSION").unwrap_or("dev"); Ideally the errors message should be improved. I will work on that. |
|
Hmm. Are you using nightly? If you aren't using nightly, none of these would work. |
1.60. |
I fixed with: pub const VERSION: &'static str = match option_env!("VERSION") {
Some(v) => v,
None => "dev",
}; |
Is it possible to stabilize the methods that do not depend on impl<T> Option<T> {
pub const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>;
pub const fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>;
pub const unsafe fn unwrap_unchecked(self) -> T;
}
impl<T: Copy> Option<&mut T> {
pub const fn copied(self) -> Option<T>
} |
@poliorcetics Yes. Feel free to open a PR. |
Make Option::as_[mut_]slice const These two functions can both be made `const`. I have added them to the `const_option_ext` feature, rust-lang#91930. I don't believe there is anything blocking stabilization of `as_slice`, but `as_mut_slice` contains mutable references so depends on `const_mut_refs`.
Make Option::as_[mut_]slice const These two functions can both be made `const`. I have added them to the `const_option_ext` feature, rust-lang#91930. I don't believe there is anything blocking stabilization of `as_slice`, but `as_mut_slice` contains mutable references so depends on `const_mut_refs`.
Rollup merge of rust-lang#126711 - GKFX:const-option-as-slice, r=oli-obk Make Option::as_[mut_]slice const These two functions can both be made `const`. I have added them to the `const_option_ext` feature, rust-lang#91930. I don't believe there is anything blocking stabilization of `as_slice`, but `as_mut_slice` contains mutable references so depends on `const_mut_refs`.
A lot of this got removed by #110393. I updated the list above. |
…rieb move Option::unwrap_unchecked into const_option feature gate That's where `unwrap` and `expect` are so IMO it makes more sense to group them together. Part of rust-lang#91930, rust-lang#67441
Rollup merge of rust-lang#130118 - RalfJung:unwrap_unchecked, r=Noratrieb move Option::unwrap_unchecked into const_option feature gate That's where `unwrap` and `expect` are so IMO it makes more sense to group them together. Part of rust-lang#91930, rust-lang#67441
@rust-lang/libs-api with #130136 having passed FCP, this should not have any blockers any more. All functions tracked here are already stable, and just waiting for their const-stability. :-) |
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. |
@Amanieu @BurntSushi @m-ou-se friendly FCP checkbox reminder :) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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#132966 - RalfJung:const_option_ext, r=jhpratt stabilize const_option_ext Fixes rust-lang#91930 FCP passed in that issue.
Feature gate:
#![feature(const_option_ext)]
This is a tracking issue for option methods.
Public API
Steps / History
Option
methods #91928Unresolved Questions
The text was updated successfully, but these errors were encountered: