@@ -148,7 +148,7 @@ impl IpAddr {
148
148
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true);
149
149
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true);
150
150
/// ```
151
- #[ rustc_const_unstable ( feature = "const_ip" , issue = "76205 " ) ]
151
+ #[ rustc_const_stable ( feature = "const_ip" , since = "1.50.0 " ) ]
152
152
#[ stable( feature = "ip_shared" , since = "1.12.0" ) ]
153
153
pub const fn is_unspecified ( & self ) -> bool {
154
154
match self {
@@ -170,7 +170,7 @@ impl IpAddr {
170
170
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true);
171
171
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true);
172
172
/// ```
173
- #[ rustc_const_unstable ( feature = "const_ip" , issue = "76205 " ) ]
173
+ #[ rustc_const_stable ( feature = "const_ip" , since = "1.50.0 " ) ]
174
174
#[ stable( feature = "ip_shared" , since = "1.12.0" ) ]
175
175
pub const fn is_loopback ( & self ) -> bool {
176
176
match self {
@@ -215,7 +215,7 @@ impl IpAddr {
215
215
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true);
216
216
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true);
217
217
/// ```
218
- #[ rustc_const_unstable ( feature = "const_ip" , issue = "76205 " ) ]
218
+ #[ rustc_const_stable ( feature = "const_ip" , since = "1.50.0 " ) ]
219
219
#[ stable( feature = "ip_shared" , since = "1.12.0" ) ]
220
220
pub const fn is_multicast ( & self ) -> bool {
221
221
match self {
@@ -301,8 +301,8 @@ impl Ipv4Addr {
301
301
///
302
302
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
303
303
/// ```
304
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
305
304
#[ rustc_const_stable( feature = "const_ipv4" , since = "1.32.0" ) ]
305
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
306
306
pub const fn new ( a : u8 , b : u8 , c : u8 , d : u8 ) -> Ipv4Addr {
307
307
// `s_addr` is stored as BE on all machine and the array is in BE order.
308
308
// So the native endian conversion method is used so that it's never swapped.
@@ -358,7 +358,7 @@ impl Ipv4Addr {
358
358
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
359
359
/// assert_eq!(addr.octets(), [127, 0, 0, 1]);
360
360
/// ```
361
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
361
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
362
362
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
363
363
pub const fn octets ( & self ) -> [ u8 ; 4 ] {
364
364
// This returns the order we want because s_addr is stored in big-endian.
@@ -380,8 +380,8 @@ impl Ipv4Addr {
380
380
/// assert_eq!(Ipv4Addr::new(0, 0, 0, 0).is_unspecified(), true);
381
381
/// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false);
382
382
/// ```
383
- #[ stable( feature = "ip_shared" , since = "1.12.0" ) ]
384
383
#[ rustc_const_stable( feature = "const_ipv4" , since = "1.32.0" ) ]
384
+ #[ stable( feature = "ip_shared" , since = "1.12.0" ) ]
385
385
pub const fn is_unspecified ( & self ) -> bool {
386
386
self . inner . s_addr == 0
387
387
}
@@ -400,7 +400,7 @@ impl Ipv4Addr {
400
400
/// assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_loopback(), true);
401
401
/// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_loopback(), false);
402
402
/// ```
403
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
403
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
404
404
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
405
405
pub const fn is_loopback ( & self ) -> bool {
406
406
self . octets ( ) [ 0 ] == 127
@@ -429,7 +429,7 @@ impl Ipv4Addr {
429
429
/// assert_eq!(Ipv4Addr::new(192, 168, 0, 2).is_private(), true);
430
430
/// assert_eq!(Ipv4Addr::new(192, 169, 0, 2).is_private(), false);
431
431
/// ```
432
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
432
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
433
433
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
434
434
pub const fn is_private ( & self ) -> bool {
435
435
match self . octets ( ) {
@@ -455,7 +455,7 @@ impl Ipv4Addr {
455
455
/// assert_eq!(Ipv4Addr::new(169, 254, 10, 65).is_link_local(), true);
456
456
/// assert_eq!(Ipv4Addr::new(16, 89, 10, 65).is_link_local(), false);
457
457
/// ```
458
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
458
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
459
459
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
460
460
pub const fn is_link_local ( & self ) -> bool {
461
461
matches ! ( self . octets( ) , [ 169 , 254 , ..] )
@@ -675,7 +675,7 @@ impl Ipv4Addr {
675
675
/// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_multicast(), true);
676
676
/// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_multicast(), false);
677
677
/// ```
678
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
678
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
679
679
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
680
680
pub const fn is_multicast ( & self ) -> bool {
681
681
self . octets ( ) [ 0 ] >= 224 && self . octets ( ) [ 0 ] <= 239
@@ -695,7 +695,7 @@ impl Ipv4Addr {
695
695
/// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_broadcast(), true);
696
696
/// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_broadcast(), false);
697
697
/// ```
698
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
698
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
699
699
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
700
700
pub const fn is_broadcast ( & self ) -> bool {
701
701
u32:: from_be_bytes ( self . octets ( ) ) == u32:: from_be_bytes ( Self :: BROADCAST . octets ( ) )
@@ -721,7 +721,7 @@ impl Ipv4Addr {
721
721
/// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_documentation(), true);
722
722
/// assert_eq!(Ipv4Addr::new(193, 34, 17, 19).is_documentation(), false);
723
723
/// ```
724
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
724
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
725
725
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
726
726
pub const fn is_documentation ( & self ) -> bool {
727
727
match self . octets ( ) {
@@ -751,7 +751,7 @@ impl Ipv4Addr {
751
751
/// Ipv6Addr::new(0, 0, 0, 0, 0, 0, 49152, 767)
752
752
/// );
753
753
/// ```
754
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
754
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
755
755
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
756
756
pub const fn to_ipv6_compatible ( & self ) -> Ipv6Addr {
757
757
let [ a, b, c, d] = self . octets ( ) ;
@@ -774,7 +774,7 @@ impl Ipv4Addr {
774
774
/// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_mapped(),
775
775
/// Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 49152, 767));
776
776
/// ```
777
- #[ rustc_const_unstable ( feature = "const_ipv4" , issue = "76205 " ) ]
777
+ #[ rustc_const_stable ( feature = "const_ipv4" , since = "1.50.0 " ) ]
778
778
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
779
779
pub const fn to_ipv6_mapped ( & self ) -> Ipv6Addr {
780
780
let [ a, b, c, d] = self . octets ( ) ;
@@ -1043,9 +1043,9 @@ impl Ipv6Addr {
1043
1043
///
1044
1044
/// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);
1045
1045
/// ```
1046
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1047
- #[ rustc_const_stable( feature = "const_ipv6" , since = "1.32.0" ) ]
1048
1046
#[ rustc_allow_const_fn_unstable( const_fn_transmute) ]
1047
+ #[ rustc_const_stable( feature = "const_ipv6" , since = "1.32.0" ) ]
1048
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1049
1049
pub const fn new ( a : u16 , b : u16 , c : u16 , d : u16 , e : u16 , f : u16 , g : u16 , h : u16 ) -> Ipv6Addr {
1050
1050
let addr16 = [
1051
1051
a. to_be ( ) ,
@@ -1061,6 +1061,8 @@ impl Ipv6Addr {
1061
1061
inner : c:: in6_addr {
1062
1062
// All elements in `addr16` are big endian.
1063
1063
// SAFETY: `[u16; 8]` is always safe to transmute to `[u8; 16]`.
1064
+ // rustc_allow_const_fn_unstable: the transmute could be written as stable const
1065
+ // code, but that leads to worse code generation (#75085)
1064
1066
s6_addr : unsafe { transmute :: < _ , [ u8 ; 16 ] > ( addr16) } ,
1065
1067
} ,
1066
1068
}
@@ -1102,11 +1104,14 @@ impl Ipv6Addr {
1102
1104
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(),
1103
1105
/// [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]);
1104
1106
/// ```
1105
- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
1107
+ #[ rustc_allow_const_fn_unstable( const_fn_transmute) ]
1108
+ #[ rustc_const_stable( feature = "const_ipv6" , since = "1.50.0" ) ]
1106
1109
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1107
1110
pub const fn segments ( & self ) -> [ u16 ; 8 ] {
1108
1111
// All elements in `s6_addr` must be big endian.
1109
1112
// SAFETY: `[u8; 16]` is always safe to transmute to `[u16; 8]`.
1113
+ // rustc_allow_const_fn_unstable: the transmute could be written as stable const code, but
1114
+ // that leads to worse code generation (#75085)
1110
1115
let [ a, b, c, d, e, f, g, h] = unsafe { transmute :: < _ , [ u16 ; 8 ] > ( self . inner . s6_addr ) } ;
1111
1116
// We want native endian u16
1112
1117
[
@@ -1135,7 +1140,7 @@ impl Ipv6Addr {
1135
1140
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unspecified(), false);
1136
1141
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).is_unspecified(), true);
1137
1142
/// ```
1138
- #[ rustc_const_unstable ( feature = "const_ipv6" , issue = "76205 " ) ]
1143
+ #[ rustc_const_stable ( feature = "const_ipv6" , since = "1.50.0 " ) ]
1139
1144
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
1140
1145
pub const fn is_unspecified ( & self ) -> bool {
1141
1146
u128:: from_be_bytes ( self . octets ( ) ) == u128:: from_be_bytes ( Ipv6Addr :: UNSPECIFIED . octets ( ) )
@@ -1155,7 +1160,7 @@ impl Ipv6Addr {
1155
1160
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_loopback(), false);
1156
1161
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_loopback(), true);
1157
1162
/// ```
1158
- #[ rustc_const_unstable ( feature = "const_ipv6" , issue = "76205 " ) ]
1163
+ #[ rustc_const_stable ( feature = "const_ipv6" , since = "1.50.0 " ) ]
1159
1164
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
1160
1165
pub const fn is_loopback ( & self ) -> bool {
1161
1166
u128:: from_be_bytes ( self . octets ( ) ) == u128:: from_be_bytes ( Ipv6Addr :: LOCALHOST . octets ( ) )
@@ -1465,7 +1470,7 @@ impl Ipv6Addr {
1465
1470
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_multicast(), true);
1466
1471
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_multicast(), false);
1467
1472
/// ```
1468
- #[ rustc_const_unstable ( feature = "const_ipv6" , issue = "76205 " ) ]
1473
+ #[ rustc_const_stable ( feature = "const_ipv6" , since = "1.50.0 " ) ]
1469
1474
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
1470
1475
pub const fn is_multicast ( & self ) -> bool {
1471
1476
( self . segments ( ) [ 0 ] & 0xff00 ) == 0xff00
@@ -1520,7 +1525,7 @@ impl Ipv6Addr {
1520
1525
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(),
1521
1526
/// Some(Ipv4Addr::new(0, 0, 0, 1)));
1522
1527
/// ```
1523
- #[ rustc_const_unstable ( feature = "const_ipv6" , issue = "76205 " ) ]
1528
+ #[ rustc_const_stable ( feature = "const_ipv6" , since = "1.50.0 " ) ]
1524
1529
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1525
1530
pub const fn to_ipv4 ( & self ) -> Option < Ipv4Addr > {
1526
1531
if let [ 0 , 0 , 0 , 0 , 0 , 0 | 0xffff , ab, cd] = self . segments ( ) {
@@ -1540,8 +1545,8 @@ impl Ipv6Addr {
1540
1545
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(),
1541
1546
/// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
1542
1547
/// ```
1543
- #[ stable( feature = "ipv6_to_octets" , since = "1.12.0" ) ]
1544
1548
#[ rustc_const_stable( feature = "const_ipv6" , since = "1.32.0" ) ]
1549
+ #[ stable( feature = "ipv6_to_octets" , since = "1.12.0" ) ]
1545
1550
pub const fn octets ( & self ) -> [ u8 ; 16 ] {
1546
1551
self . inner . s6_addr
1547
1552
}
0 commit comments