Skip to content

Commit

Permalink
Add unstable const_ordering feature, and some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
CDirkx committed Aug 30, 2020
1 parent 6b0d44e commit 5fac991
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/core/src/cmp.rs
Expand Up @@ -356,6 +356,7 @@ impl Ordering {
/// ```
#[inline]
#[must_use]
#[rustc_const_unstable(feature = "const_ordering", issue = "76113")]
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn reverse(self) -> Ordering {
match self {
Expand Down Expand Up @@ -394,6 +395,7 @@ impl Ordering {
/// ```
#[inline]
#[must_use]
#[rustc_const_unstable(feature = "const_ordering", issue = "76113")]
#[stable(feature = "ordering_chaining", since = "1.17.0")]
pub const fn then(self, other: Ordering) -> Ordering {
match self {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Expand Up @@ -86,6 +86,7 @@
#![feature(const_ptr_offset_from)]
#![feature(const_raw_ptr_comparison)]
#![feature(const_result)]
#![feature(const_ordering)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_slice_ptr_len)]
#![feature(const_size_of_val)]
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/consts/const-ordering.rs
@@ -0,0 +1,17 @@
// run-pass

#![feature(const_ordering)]

use std::cmp::Ordering;

// the following methods of core::cmp::Ordering are const:
// - reverse
// - then

fn main() {
const REVERSE : Ordering = Ordering::Greater.reverse();
assert_eq!(REVERSE, Ordering::Less);

const THEN : Ordering = Ordering::Equal.then(REVERSE);
assert_eq!(THEN, Ordering::Less);
}

0 comments on commit 5fac991

Please sign in to comment.