Skip to content

Commit 5fac991

Browse files
author
CDirkx
committed
Add unstable const_ordering feature, and some tests.
1 parent 6b0d44e commit 5fac991

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

library/core/src/cmp.rs

+2
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ impl Ordering {
356356
/// ```
357357
#[inline]
358358
#[must_use]
359+
#[rustc_const_unstable(feature = "const_ordering", issue = "76113")]
359360
#[stable(feature = "rust1", since = "1.0.0")]
360361
pub const fn reverse(self) -> Ordering {
361362
match self {
@@ -394,6 +395,7 @@ impl Ordering {
394395
/// ```
395396
#[inline]
396397
#[must_use]
398+
#[rustc_const_unstable(feature = "const_ordering", issue = "76113")]
397399
#[stable(feature = "ordering_chaining", since = "1.17.0")]
398400
pub const fn then(self, other: Ordering) -> Ordering {
399401
match self {

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#![feature(const_ptr_offset_from)]
8787
#![feature(const_raw_ptr_comparison)]
8888
#![feature(const_result)]
89+
#![feature(const_ordering)]
8990
#![feature(const_slice_from_raw_parts)]
9091
#![feature(const_slice_ptr_len)]
9192
#![feature(const_size_of_val)]

src/test/ui/consts/const-ordering.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![feature(const_ordering)]
4+
5+
use std::cmp::Ordering;
6+
7+
// the following methods of core::cmp::Ordering are const:
8+
// - reverse
9+
// - then
10+
11+
fn main() {
12+
const REVERSE : Ordering = Ordering::Greater.reverse();
13+
assert_eq!(REVERSE, Ordering::Less);
14+
15+
const THEN : Ordering = Ordering::Equal.then(REVERSE);
16+
assert_eq!(THEN, Ordering::Less);
17+
}

0 commit comments

Comments
 (0)