-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 the use of ?
in constants
#74935
Comments
#60964 also needs to be resolved to be able to implement |
Constify ?-operator for Result and Option Try to make `?`-operator usable in `const fn` with `Result` and `Option`, see rust-lang#74935 . Note that the try-operator itself was constified in rust-lang#87237. TODO * [x] Add tests for const T -> T conversions * [x] cleanup commits * [x] Remove `#![allow(incomplete_features)]` * [?] Await decision in rust-lang#86808 - I'm not sure * [x] Await support for parsing `~const` in bootstrapping compiler * [x] Tracking issue(s)? - rust-lang#88674
Would it be reasonable to permit |
You mean to make the desugaring different if we're in a const fn? |
I don't see any reason we couldn't desugar to this unconditionally for match opt {
Some(val) => val,
None => return None,
} Sure, the If it's possible to stabilize it on Plus, who knows. There might be a small performance benefit to changing the desugaring to something simpler. |
The reason we can't do this is that during desugaring we don't know what the type is. We compute types after desugaring. |
Ah, dang. For some reason I thought the order was the other way around. |
1db4b72 Mark function as const (yancy) Pull request description: We discussed marking from_vb as const here: #3602 However, from what I can tell, map() isn't const and I don't see a tracking issue for changing it. Also, the question mark operator isn't available in const context either, although there is a tracking issue for that: rust-lang/rust#74935. It will be a long while before that makes it into this projects MSRV if/when it lands. There are some other functions in this module that could use the same re-write to make them const as well it looks like. ACKs for top commit: tcharding: ACK 1db4b72 apoelstra: ACK 1db4b72; successfully ran local tests Tree-SHA512: 62b612791dd3ce2f6ebf27f586a1262633a46566b9fd3583984171f62209714ad979439345fe86d8ef87d2f78a2cee21d619e2eb3621689faf59d81640e9f77c
The
?
operator expands to invokingTry::into_result
for the argument andInto::into
for the error of the result. In order to support these, we need toimpl const
and~const
in the standard library #110395impl const Trait for Type
items Tracking issue for RFC 2632,impl const Trait for Ty
and~const
(tilde const) syntax #67792const Try
forResult
andOption
in libstdconst Into
for their error typesimpl<T> From<T> for T
, we have to make this a const impl, too, as well as theimpl<T: From<U>, U> Into<T> for U
implThe text was updated successfully, but these errors were encountered: