-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
cc @rust-lang/wg-const-eval |
@rfcbot fcp merge |
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. |
…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`
🔔 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. The RFC will be merged soon. |
@bors r+ |
📌 Commit 4fcef4b has been approved by |
☀️ Test successful - checks-actions |
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.
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.
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.
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
This PR stabilizes all currently stable methods of
Ipv4Addr
,Ipv6Addr
andIpAddr
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}
fromlibc
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 featureconst_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-stableIpv6Addr::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 onIpv4Addr::octets
andIpv6Addr::segments
(covered by this PR).