Skip to content

Stabilize all stable methods of Ipv4Addr, Ipv6Addr and IpAddr as const - #79342

Merged
bors merged 1 commit into
rust-lang:masterfrom
CDirkx:ipaddr-const
Dec 19, 2020
Merged

Stabilize all stable methods of Ipv4Addr, Ipv6Addr and IpAddr as const#79342
bors merged 1 commit into
rust-lang:masterfrom
CDirkx:ipaddr-const

Conversation

@CDirkx

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @sfackler

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

@rust-highfiverust-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
Copy Markdown
Member

cc @rust-lang/wg-const-eval

Comment threadlibrary/std/src/net/ip.rs Outdated
@sfacklersfackler added the T-libs-api [DEPRECATED; DO NOT USE] label Nov 27, 2020
@sfackler

Copy link
Copy Markdown
Member

@rfcbot fcp merge

@rfcbot

rfcbot commented Nov 27, 2020

Copy link
Copy Markdown

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.

@rfcbotrfcbot 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`
@rfcbotrfcbot 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
Copy Markdown

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

@rfcbotrfcbot 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
@rfcbotrfcbot 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
Copy Markdown

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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 19, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 4fcef4b has been approved by oli-obk

@borsbors 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

bors commented Dec 19, 2020

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 4fcef4b with merge bd2f1cb...

@bors

bors commented Dec 19, 2020

Copy link
Copy Markdown
Collaborator

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

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Dec 19, 2020
@bors
bors merged commit bd2f1cb into rust-lang:masterDec 19, 2020
@rustbotrustbot added this to the 1.50.0 milestone Dec 19, 2020
@borsbors mentioned this pull request Dec 19, 2020
@CDirkx
CDirkx deleted the ipaddr-const branch December 19, 2020 22:14
@spastorinospastorino 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.
@JohnTitorJohnTitor mentioned this pull request Feb 21, 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.
@JohnTitorJohnTitor mentioned this pull request Feb 21, 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.
@JohnTitorJohnTitor mentioned this pull request Feb 21, 2021
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
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis 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.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@CDirkx@rust-highfive@m-ou-se@sfackler@rfcbot@oli-obk@bors@spastorino@rustbot