@@ -2,7 +2,6 @@ use super::display_buffer::DisplayBuffer;
2
2
use crate :: cmp:: Ordering ;
3
3
use crate :: fmt:: { self , Write } ;
4
4
use crate :: hash:: { Hash , Hasher } ;
5
- use crate :: iter;
6
5
use crate :: mem:: transmute;
7
6
use crate :: ops:: { BitAnd , BitAndAssign , BitOr , BitOrAssign , Not } ;
8
7
@@ -2337,20 +2336,24 @@ impl From<[u16; 8]> for IpAddr {
2337
2336
}
2338
2337
2339
2338
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2340
- impl Not for Ipv4Addr {
2339
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2340
+ impl const Not for Ipv4Addr {
2341
2341
type Output = Ipv4Addr ;
2342
2342
2343
2343
#[ inline]
2344
2344
fn not ( mut self ) -> Ipv4Addr {
2345
- for octet in & mut self . octets {
2346
- * octet = !* octet;
2345
+ let mut idx = 0 ;
2346
+ while idx < 4 {
2347
+ self . octets [ idx] = !self . octets [ idx] ;
2348
+ idx += 1 ;
2347
2349
}
2348
2350
self
2349
2351
}
2350
2352
}
2351
2353
2352
2354
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2353
- impl Not for & ' _ Ipv4Addr {
2355
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2356
+ impl const Not for & ' _ Ipv4Addr {
2354
2357
type Output = Ipv4Addr ;
2355
2358
2356
2359
#[ inline]
@@ -2360,20 +2363,24 @@ impl Not for &'_ Ipv4Addr {
2360
2363
}
2361
2364
2362
2365
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2363
- impl Not for Ipv6Addr {
2366
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2367
+ impl const Not for Ipv6Addr {
2364
2368
type Output = Ipv6Addr ;
2365
2369
2366
2370
#[ inline]
2367
2371
fn not ( mut self ) -> Ipv6Addr {
2368
- for octet in & mut self . octets {
2369
- * octet = !* octet;
2372
+ let mut idx = 0 ;
2373
+ while idx < 16 {
2374
+ self . octets [ idx] = !self . octets [ idx] ;
2375
+ idx += 1 ;
2370
2376
}
2371
2377
self
2372
2378
}
2373
2379
}
2374
2380
2375
2381
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2376
- impl Not for & ' _ Ipv6Addr {
2382
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2383
+ impl const Not for & ' _ Ipv6Addr {
2377
2384
type Output = Ipv6Addr ;
2378
2385
2379
2386
#[ inline]
@@ -2389,23 +2396,25 @@ macro_rules! bitop_impls {
2389
2396
) * ) => {
2390
2397
$(
2391
2398
$( #[ $attr] ) *
2392
- impl $BitOpAssign for $ty {
2399
+ impl const $BitOpAssign for $ty {
2393
2400
fn $bitop_assign( & mut self , rhs: $ty) {
2394
- for ( lhs, rhs) in iter:: zip( & mut self . octets, rhs. octets) {
2395
- lhs. $bitop_assign( rhs) ;
2401
+ let mut idx = 0 ;
2402
+ while idx < self . octets. len( ) {
2403
+ self . octets[ idx] . $bitop_assign( rhs. octets[ idx] ) ;
2404
+ idx += 1 ;
2396
2405
}
2397
2406
}
2398
2407
}
2399
2408
2400
2409
$( #[ $attr] ) *
2401
- impl $BitOpAssign<& ' _ $ty> for $ty {
2410
+ impl const $BitOpAssign<& ' _ $ty> for $ty {
2402
2411
fn $bitop_assign( & mut self , rhs: & ' _ $ty) {
2403
2412
self . $bitop_assign( * rhs) ;
2404
2413
}
2405
2414
}
2406
2415
2407
2416
$( #[ $attr] ) *
2408
- impl $BitOp for $ty {
2417
+ impl const $BitOp for $ty {
2409
2418
type Output = $ty;
2410
2419
2411
2420
#[ inline]
@@ -2416,7 +2425,7 @@ macro_rules! bitop_impls {
2416
2425
}
2417
2426
2418
2427
$( #[ $attr] ) *
2419
- impl $BitOp<& ' _ $ty> for $ty {
2428
+ impl const $BitOp<& ' _ $ty> for $ty {
2420
2429
type Output = $ty;
2421
2430
2422
2431
#[ inline]
@@ -2427,7 +2436,7 @@ macro_rules! bitop_impls {
2427
2436
}
2428
2437
2429
2438
$( #[ $attr] ) *
2430
- impl $BitOp<$ty> for & ' _ $ty {
2439
+ impl const $BitOp<$ty> for & ' _ $ty {
2431
2440
type Output = $ty;
2432
2441
2433
2442
#[ inline]
@@ -2439,7 +2448,7 @@ macro_rules! bitop_impls {
2439
2448
}
2440
2449
2441
2450
$( #[ $attr] ) *
2442
- impl $BitOp<& ' _ $ty> for & ' _ $ty {
2451
+ impl const $BitOp<& ' _ $ty> for & ' _ $ty {
2443
2452
type Output = $ty;
2444
2453
2445
2454
#[ inline]
@@ -2455,12 +2464,16 @@ macro_rules! bitop_impls {
2455
2464
2456
2465
bitop_impls ! {
2457
2466
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2467
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2458
2468
impl ( BitAnd , BitAndAssign ) for Ipv4Addr = ( bitand, bitand_assign) ;
2459
2469
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2470
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2460
2471
impl ( BitOr , BitOrAssign ) for Ipv4Addr = ( bitor, bitor_assign) ;
2461
2472
2462
2473
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2474
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2463
2475
impl ( BitAnd , BitAndAssign ) for Ipv6Addr = ( bitand, bitand_assign) ;
2464
2476
#[ stable( feature = "ip_bitops" , since = "1.75.0" ) ]
2477
+ #[ rustc_const_unstable( feature = "const_ops" , issue = "143802" ) ]
2465
2478
impl ( BitOr , BitOrAssign ) for Ipv6Addr = ( bitor, bitor_assign) ;
2466
2479
}
0 commit comments