@@ -397,6 +397,12 @@ pub enum Ordering {
397
397
}
398
398
399
399
impl Ordering {
400
+ #[ inline]
401
+ const fn as_raw ( self ) -> i8 {
402
+ // FIXME(const-hack): just use `PartialOrd` against `Equal` once that's const
403
+ crate :: intrinsics:: discriminant_value ( & self )
404
+ }
405
+
400
406
/// Returns `true` if the ordering is the `Equal` variant.
401
407
///
402
408
/// # Examples
@@ -413,7 +419,7 @@ impl Ordering {
413
419
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
414
420
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
415
421
pub const fn is_eq ( self ) -> bool {
416
- matches ! ( self , Equal )
422
+ self . as_raw ( ) == 0
417
423
}
418
424
419
425
/// Returns `true` if the ordering is not the `Equal` variant.
@@ -432,7 +438,7 @@ impl Ordering {
432
438
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
433
439
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
434
440
pub const fn is_ne ( self ) -> bool {
435
- ! matches ! ( self , Equal )
441
+ self . as_raw ( ) != 0
436
442
}
437
443
438
444
/// Returns `true` if the ordering is the `Less` variant.
@@ -451,7 +457,7 @@ impl Ordering {
451
457
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
452
458
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
453
459
pub const fn is_lt ( self ) -> bool {
454
- matches ! ( self , Less )
460
+ self . as_raw ( ) < 0
455
461
}
456
462
457
463
/// Returns `true` if the ordering is the `Greater` variant.
@@ -470,7 +476,7 @@ impl Ordering {
470
476
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
471
477
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
472
478
pub const fn is_gt ( self ) -> bool {
473
- matches ! ( self , Greater )
479
+ self . as_raw ( ) > 0
474
480
}
475
481
476
482
/// Returns `true` if the ordering is either the `Less` or `Equal` variant.
@@ -489,7 +495,7 @@ impl Ordering {
489
495
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
490
496
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
491
497
pub const fn is_le ( self ) -> bool {
492
- ! matches ! ( self , Greater )
498
+ self . as_raw ( ) <= 0
493
499
}
494
500
495
501
/// Returns `true` if the ordering is either the `Greater` or `Equal` variant.
@@ -508,7 +514,7 @@ impl Ordering {
508
514
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
509
515
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
510
516
pub const fn is_ge ( self ) -> bool {
511
- ! matches ! ( self , Less )
517
+ self . as_raw ( ) >= 0
512
518
}
513
519
514
520
/// Reverses the `Ordering`.
@@ -1369,7 +1375,9 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1369
1375
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1370
1376
#[ rustc_diagnostic_item = "cmp_partialord_lt" ]
1371
1377
fn lt ( & self , other : & Rhs ) -> bool {
1372
- self . partial_cmp ( other) . is_some_and ( Ordering :: is_lt)
1378
+ // FIXME(#137901): weirdly, passing these as `Ordering::is_lt` doesn't
1379
+ // MIR-inline, thus the "unnecessary" closure form here.
1380
+ self . partial_cmp ( other) . is_some_and ( |c| c. is_lt ( ) )
1373
1381
}
1374
1382
1375
1383
/// Tests less than or equal to (for `self` and `other`) and is used by the
@@ -1387,7 +1395,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1387
1395
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1388
1396
#[ rustc_diagnostic_item = "cmp_partialord_le" ]
1389
1397
fn le ( & self , other : & Rhs ) -> bool {
1390
- self . partial_cmp ( other) . is_some_and ( Ordering :: is_le)
1398
+ self . partial_cmp ( other) . is_some_and ( |c| c . is_le ( ) )
1391
1399
}
1392
1400
1393
1401
/// Tests greater than (for `self` and `other`) and is used by the `>`
@@ -1405,7 +1413,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1405
1413
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1406
1414
#[ rustc_diagnostic_item = "cmp_partialord_gt" ]
1407
1415
fn gt ( & self , other : & Rhs ) -> bool {
1408
- self . partial_cmp ( other) . is_some_and ( Ordering :: is_gt)
1416
+ self . partial_cmp ( other) . is_some_and ( |c| c . is_gt ( ) )
1409
1417
}
1410
1418
1411
1419
/// Tests greater than or equal to (for `self` and `other`) and is used by
@@ -1423,7 +1431,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1423
1431
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1424
1432
#[ rustc_diagnostic_item = "cmp_partialord_ge" ]
1425
1433
fn ge ( & self , other : & Rhs ) -> bool {
1426
- self . partial_cmp ( other) . is_some_and ( Ordering :: is_ge)
1434
+ self . partial_cmp ( other) . is_some_and ( |c| c . is_ge ( ) )
1427
1435
}
1428
1436
}
1429
1437
0 commit comments