rust/library/std/src/net
bors bd2f1cb278 Auto merge of #79342 - CDirkx:ipaddr-const, r=oli-obk
Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const

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 https://github.com/rust-lang/rust/pull/76206#issuecomment-685044184.

## 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).
2020-12-19 13:13:41 +00:00
..
addr Remove redundant 'static from library crates 2020-10-18 17:25:51 +02:00
ip Move const ip in ui test to unit test 2020-11-26 23:15:32 +09:00
parser Parse SocketAddrV6::scope_id 2020-10-06 22:13:15 +00:00
tcp std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
udp Use is_ok() instead of empty Ok(_) 2020-10-13 17:01:50 -04:00
addr.rs Revert "[net] clippy: needless_update" 2020-10-19 07:22:45 -04:00
ip.rs Stabilize all stable methods of Ipv4Addr, Ipv6Addr and IpAddr as const 2020-11-27 20:36:47 +01:00
mod.rs Move to intra doc links in std::net 2020-08-15 19:17:19 +02:00
parser.rs Parse SocketAddrV6::scope_id 2020-10-06 22:13:15 +00:00
tcp.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
test.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
udp.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00