about summary refs log tree commit diff
path: root/src/test/ui/consts/std
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-09-01 23:55:17 +0200
committerChristiaan Dirkx <christiaan@dirkx.email>2020-09-01 23:55:17 +0200
commit0c77257e56a20a81f5b4e4452cae5e460ad30140 (patch)
treea657927ddb301b0719923239c6edb32f8ae79df3 /src/test/ui/consts/std
parentfb64e6dcf0a7ea0518c8f2d499327a2b6974f859 (diff)
downloadrust-0c77257e56a20a81f5b4e4452cae5e460ad30140.tar.gz
rust-0c77257e56a20a81f5b4e4452cae5e460ad30140.zip
Make all remaining methods of `std::net::Ipv4Addr` const
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature:
 - `is_global`
 - `is_reserved`
 - `is_broadcast`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

This results in all methods of `Ipv4Addr` being const.

Also adds tests for these methods in a const context.
Diffstat (limited to 'src/test/ui/consts/std')
-rw-r--r--src/test/ui/consts/std/net/ipv4.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/test/ui/consts/std/net/ipv4.rs b/src/test/ui/consts/std/net/ipv4.rs
index eca42f297e5..8c676999ae7 100644
--- a/src/test/ui/consts/std/net/ipv4.rs
+++ b/src/test/ui/consts/std/net/ipv4.rs
@@ -3,7 +3,7 @@
 #![feature(ip)]
 #![feature(const_ipv4)]
 
-use std::net::Ipv4Addr;
+use std::net::{Ipv4Addr, Ipv6Addr};
 
 fn main() {
     const IP_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
@@ -24,6 +24,9 @@ fn main() {
     const IS_LINK_LOCAL : bool = IP_ADDRESS.is_link_local();
     assert!(!IS_LINK_LOCAL);
 
+    const IS_GLOBAL : bool = IP_ADDRESS.is_global();
+    assert!(!IS_GLOBAL);
+
     const IS_SHARED : bool = IP_ADDRESS.is_shared();
     assert!(!IS_SHARED);
 
@@ -33,9 +36,23 @@ fn main() {
     const IS_BENCHMARKING : bool = IP_ADDRESS.is_benchmarking();
     assert!(!IS_BENCHMARKING);
 
+    const IS_RESERVED : bool = IP_ADDRESS.is_reserved();
+    assert!(!IS_RESERVED);
+
     const IS_MULTICAST : bool = IP_ADDRESS.is_multicast();
     assert!(!IS_MULTICAST);
 
+    const IS_BROADCAST : bool = IP_ADDRESS.is_broadcast();
+    assert!(!IS_BROADCAST);
+
     const IS_DOCUMENTATION : bool = IP_ADDRESS.is_documentation();
     assert!(!IS_DOCUMENTATION);
+
+    const IP_V6_COMPATIBLE : Ipv6Addr = IP_ADDRESS.to_ipv6_compatible();
+    assert_eq!(IP_V6_COMPATIBLE,
+        Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]));
+
+    const IP_V6_MAPPED : Ipv6Addr = IP_ADDRESS.to_ipv6_mapped();
+    assert_eq!(IP_V6_MAPPED,
+        Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1]));
 }