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

Stabilize enum is_variant methods as const #76225

Closed
5 of 6 tasks
Tracked by #16
CDirkx opened this issue Sep 1, 2020 · 2 comments
Closed
5 of 6 tasks
Tracked by #16

Stabilize enum is_variant methods as const #76225

CDirkx opened this issue Sep 1, 2020 · 2 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@CDirkx
Copy link
Contributor

CDirkx commented Sep 1, 2020

Recently const control flow was stabilized, which enables a lot of methods within the standard library to be made stable const; specifically all of the enum is_variant methods:

  • Option: is_some and is_none
  • Result: is_ok and is_err
  • Poll: is_ready and is_pending
  • Cow: is_borrowed and is_owned (methods themselves are unstable)
  • IpAddr: is_ipv4 and is_ipv6
  • std::path::Prefix: is_verbatim

This issue aims to collect discussion about the stabilization of these methods, due to their similarities and trivial implementations.

Stabilization

  • Option: stabilized in PR#76135 (note: also contains as_ref)
  • Result: stabilized in PR#76136 (note: also contains as_ref)
  • Poll stabilized in PR#76227
  • Cow: methods made const in PR#76139, the methods themselves are still unstable under cow_is_borrowed
  • IpAddr: stabilized in PR#76226
  • Prefix: stabilization proposed in PR#76232, but there is not enough motivation to stabilize this method on its own
@jonas-schievink jonas-schievink added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 1, 2020
@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 2, 2020

These were all the instances of enums with is_variant methods I could find in the standard library.

PRs opened for all of them, @ecstatic-morse

RalfJung added a commit to RalfJung/rust that referenced this issue Sep 19, 2020
Stabilize some Option methods as const

Stabilize the following methods of `Option` as const:
 - `is_some`
 - `is_none`
 - `as_ref`

These methods are currently const under the unstable feature `const_option` (tracking issue: rust-lang#67441).
I believe these methods to be eligible for stabilization because of the stabilization of rust-lang#49146 (Allow if and match in constants) and the trivial implementations, see also:  [PR#75463](rust-lang#75463).

Related: rust-lang#76225
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 20, 2020
Stabilize some Result methods as const

Stabilize the following methods of Result as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

A test is also included, analogous to the test for `const_option`.

These methods are currently const under the unstable feature `const_result` (tracking issue: rust-lang#67520).
I believe these methods to be eligible for stabilization because of the stabilization of rust-lang#49146 (Allow if and match in constants) and the trivial implementations, see also: [PR#75463](rust-lang#75463) and [PR#76135](rust-lang#76135).

Note: these methods are the only methods currently under the `const_result` feature, thus this PR results in the removal of the feature.

Related: rust-lang#76225
RalfJung added a commit to RalfJung/rust that referenced this issue Sep 21, 2020
Stabilize some Option methods as const

Stabilize the following methods of `Option` as const:
 - `is_some`
 - `is_none`
 - `as_ref`

These methods are currently const under the unstable feature `const_option` (tracking issue: rust-lang#67441).
I believe these methods to be eligible for stabilization because of the stabilization of rust-lang#49146 (Allow if and match in constants) and the trivial implementations, see also:  [PR#75463](rust-lang#75463).

Related: rust-lang#76225
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 24, 2020
Stabilize some Result methods as const

Stabilize the following methods of Result as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

A test is also included, analogous to the test for `const_option`.

These methods are currently const under the unstable feature `const_result` (tracking issue: rust-lang#67520).
I believe these methods to be eligible for stabilization because of the stabilization of rust-lang#49146 (Allow if and match in constants) and the trivial implementations, see also: [PR#75463](rust-lang#75463) and [PR#76135](rust-lang#76135).

Note: these methods are the only methods currently under the `const_result` feature, thus this PR results in the removal of the feature.

Related: rust-lang#76225
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 7, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 7, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 7, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 7, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 8, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 8, 2020
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 23, 2020
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const

Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225 and rust-lang#76205.
@CDirkx
Copy link
Contributor Author

CDirkx commented May 25, 2021

Closing as all is_variant methods have been stabilized as const, with the exception of Prefix which on its own doesn't seem worth it.

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-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants