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 all stable methods of Ipv4Addr, Ipv6Addr and IpAddr as const #79342

Merged
merged 1 commit into from
Dec 19, 2020

Conversation

CDirkx
Copy link
Contributor

@CDirkx CDirkx commented Nov 23, 2020

This PR stabilizes all currently stable methods of Ipv4Addr, Ipv6Addr and IpAddr as const.
Tracking issue: #76205

Ipv4Addr (const_ipv4):

  • octets
  • is_loopback
  • is_private
  • is_link_local
  • is_multicast
  • is_broadcast
  • is_docmentation
  • to_ipv6_compatible
  • to_ipv6_mapped

Ipv6Addr (const_ipv6):

  • segments
  • is_unspecified
  • is_loopback
  • is_multicast
  • to_ipv4

IpAddr (const_ip):

  • is_unspecified
  • is_loopback
  • is_multicast

Motivation

The ip methods seem like prime candidates to be made const: their behavior is defined by an external spec, and based solely on the byte contents of an address. These methods have been made unstable const in the beginning of September, after the necessary const integer arithmetic was stabilized.

There is currently a PR open (#78802) to change the internal representation of IpAddr{4,6} from libc types to a byte array. This does not have any impact on the constness of the methods.

Implementation

Most of the stabilizations are straightforward, with the exception of Ipv6Addr::segments, which uses the unstable feature const_fn_transmute. The code could be rewritten to equivalent stable code, but this leads to worse code generation (#75085).
This is why segments gets marked with #[rustc_allow_const_fn_unstable(const_fn_transmute)], like the already const-stable Ipv6Addr::new, the justification being that a const-stable alternative implementation exists #76206 (comment).

Future posibilities

This PR const-stabilizes all currently stable ip methods, however there are also a number of unstable methods under the ip feature (#27709). These methods are already unstable const. There is a PR open (#76098) to stabilize those methods, which could include const-stabilization. However, stabilizing those methods as const is dependent on Ipv4Addr::octets and Ipv6Addr::segments (covered by this PR).

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 23, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Nov 27, 2020

cc @rust-lang/wg-const-eval

library/std/src/net/ip.rs Outdated Show resolved Hide resolved
@sfackler sfackler added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 27, 2020
@sfackler
Copy link
Member

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Nov 27, 2020

Team member @sfackler 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 Nov 27, 2020
…s const

`Ipv4Addr`
 - `octets`
 - `is_loopback`
 - `is_private`
 - `is_link_local`
 - `is_multicast`
 - `is_broadcast`
 - `is_docmentation`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

`Ipv6Addr`
 - `segments`
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`
 - `to_ipv4`

`IpAddr`
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Dec 9, 2020
@rfcbot
Copy link

rfcbot commented Dec 9, 2020

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

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Dec 9, 2020
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Dec 19, 2020
@rfcbot
Copy link

rfcbot commented Dec 19, 2020

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.

The RFC will be merged soon.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 19, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Dec 19, 2020

📌 Commit 4fcef4b has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 19, 2020
@bors
Copy link
Contributor

bors commented Dec 19, 2020

⌛ Testing commit 4fcef4b with merge bd2f1cb...

@bors
Copy link
Contributor

bors commented Dec 19, 2020

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing bd2f1cb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 19, 2020
@bors bors merged commit bd2f1cb into rust-lang:master Dec 19, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 19, 2020
@CDirkx CDirkx deleted the ipaddr-const branch December 19, 2020 22:14
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Dec 31, 2020
CDirkx added a commit to CDirkx/rust that referenced this pull request Feb 15, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Feb 21, 2021
Update RELEASES.md 1.50 to include methods stabilized in rust-lang#79342

I noticed that rust-lang#79342 was missing from the release notes for 1.50.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Feb 21, 2021
Update RELEASES.md 1.50 to include methods stabilized in rust-lang#79342

I noticed that rust-lang#79342 was missing from the release notes for 1.50.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Feb 21, 2021
Update RELEASES.md 1.50 to include methods stabilized in rust-lang#79342

I noticed that rust-lang#79342 was missing from the release notes for 1.50.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#81300 (BTree: share panicky test code & test panic during clear, clone)
 - rust-lang#81706 (Document BinaryHeap unsafe functions)
 - rust-lang#81833 (parallelize x.py test tidy)
 - rust-lang#81966 (Add new `rustc` target for Arm64 machines that can target the iphonesimulator)
 - rust-lang#82154 (Update RELEASES.md 1.50 to include methods stabilized in rust-lang#79342)
 - rust-lang#82177 (Do not delete bootstrap.exe on Windows during clean)
 - rust-lang#82181 (Add check for ES5 in CI)
 - rust-lang#82229 (Add [A-diagnostics] bug report template)
 - rust-lang#82233 (try-back-block-type test: Use TryFromSliceError for From test)
 - rust-lang#82302 (Remove unsafe impl Send for CompletedTest & TestResult)
 - rust-lang#82349 (test: Print test name only once on timeout)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@jplatte jplatte mentioned this pull request Aug 2, 2021
65 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants