-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #76206 - CDirkx:const-ipv6, r=ecstatic-morse
Make all methods of `std::net::Ipv6Addr` const Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature: - `segments` - `is_unspecified` - `is_loopback` - `is_global` (unstable) - `is_unique_local` - `is_unicast_link_local_strict` - `is_documentation` - `multicast_scope` - `is_multicast` - `to_ipv4_mapped` - `to_ipv4` This would make all methods of `Ipv6Addr` const. Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`, all other methods did not require a change. All these methods are dependent on `segments`, the current implementation of which requires unstable `const_fn_transmute` ([PR#75085](#75085)). Part of #76205
- Loading branch information
Showing
3 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// run-pass | ||
|
||
#![feature(ip)] | ||
#![feature(const_ipv6)] | ||
|
||
use std::net::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope}; | ||
|
||
fn main() { | ||
const IP_ADDRESS : Ipv6Addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1); | ||
assert_eq!(IP_ADDRESS, Ipv6Addr::LOCALHOST); | ||
|
||
const SEGMENTS : [u16; 8] = IP_ADDRESS.segments(); | ||
assert_eq!(SEGMENTS, [0 ,0 ,0 ,0 ,0 ,0 ,0, 1]); | ||
|
||
const OCTETS : [u8; 16] = IP_ADDRESS.octets(); | ||
assert_eq!(OCTETS, [0 ,0 ,0 ,0 ,0 ,0 ,0, 0 ,0 ,0 ,0 ,0 ,0 ,0, 0, 1]); | ||
|
||
const IS_UNSPECIFIED : bool = IP_ADDRESS.is_unspecified(); | ||
assert!(!IS_UNSPECIFIED); | ||
|
||
const IS_LOOPBACK : bool = IP_ADDRESS.is_loopback(); | ||
assert!(IS_LOOPBACK); | ||
|
||
const IS_GLOBAL : bool = IP_ADDRESS.is_global(); | ||
assert!(!IS_GLOBAL); | ||
|
||
const IS_UNIQUE_LOCAL : bool = IP_ADDRESS.is_unique_local(); | ||
assert!(!IS_UNIQUE_LOCAL); | ||
|
||
const IS_UNICAST_LINK_LOCAL_STRICT : bool = IP_ADDRESS.is_unicast_link_local_strict(); | ||
assert!(!IS_UNICAST_LINK_LOCAL_STRICT); | ||
|
||
const IS_UNICAST_LINK_LOCAL : bool = IP_ADDRESS.is_unicast_link_local(); | ||
assert!(!IS_UNICAST_LINK_LOCAL); | ||
|
||
const IS_UNICAST_SITE_LOCAL : bool = IP_ADDRESS.is_unicast_site_local(); | ||
assert!(!IS_UNICAST_SITE_LOCAL); | ||
|
||
const IS_DOCUMENTATION : bool = IP_ADDRESS.is_documentation(); | ||
assert!(!IS_DOCUMENTATION); | ||
|
||
const IS_UNICAST_GLOBAL : bool = IP_ADDRESS.is_unicast_global(); | ||
assert!(!IS_UNICAST_GLOBAL); | ||
|
||
const MULTICAST_SCOPE : Option<Ipv6MulticastScope> = IP_ADDRESS.multicast_scope(); | ||
assert_eq!(MULTICAST_SCOPE, None); | ||
|
||
const IS_MULTICAST : bool = IP_ADDRESS.is_multicast(); | ||
assert!(!IS_MULTICAST); | ||
|
||
const IP_V4 : Option<Ipv4Addr> = IP_ADDRESS.to_ipv4(); | ||
assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1)); | ||
} |