Skip to content

Remove unsafe code from core::cmp #31084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use self::Ordering::*;

use mem;
use marker::Sized;
use option::Option::{self, Some};

Expand Down Expand Up @@ -119,10 +118,6 @@ pub enum Ordering {
}

impl Ordering {
unsafe fn from_i8_unchecked(v: i8) -> Ordering {
mem::transmute(v)
}

/// Reverse the `Ordering`.
///
/// * `Less` becomes `Greater`.
Expand Down Expand Up @@ -155,14 +150,10 @@ impl Ordering {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reverse(self) -> Ordering {
unsafe {
// this compiles really nicely (to a single instruction);
// an explicit match has a pile of branches and
// comparisons.
//
// NB. it is safe because of the explicit discriminants
// given above.
Ordering::from_i8_unchecked(-(self as i8))
match self {
Less => Greater,
Equal => Equal,
Greater => Less,
}
}
}
Expand Down