From 49187d53f2f8b7cfca9105c3fb00d7c29e2a457b Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 6 Jan 2017 16:32:29 -0800 Subject: Add `nightly` feature, use for `unlikely` intrinsic --- src/grid.rs | 2 +- src/lib.rs | 2 +- src/term/mod.rs | 2 +- src/util.rs | 9 +++++++++ 4 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/grid.rs b/src/grid.rs index e044a8c3..5c3da769 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -150,7 +150,7 @@ impl Grid { /// better error messages by doing the bounds checking ourselves. #[inline] pub fn swap_lines(&mut self, src: index::Line, dst: index::Line) { - use std::intrinsics::unlikely; + use util::unlikely; unsafe { // check that src/dst are in bounds. Since index::Line newtypes usize, diff --git a/src/lib.rs b/src/lib.rs index c6215a80..295a674c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ #![cfg_attr(feature = "clippy", deny(if_not_else))] #![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))] #![cfg_attr(test, feature(test))] -#![feature(core_intrinsics)] +#![cfg_attr(feature = "nightly", feature(core_intrinsics))] #![feature(proc_macro)] diff --git a/src/term/mod.rs b/src/term/mod.rs index 09ed5d41..eab73e74 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -630,7 +630,7 @@ impl ansi::Handler for Term { } unsafe { - if ::std::intrinsics::unlikely(self.cursor.line == self.grid.num_lines()) { + if ::util::unlikely(self.cursor.line == self.grid.num_lines()) { panic!("cursor fell off grid"); } } diff --git a/src/util.rs b/src/util.rs index 44f7b3de..2e34b2a6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -13,6 +13,15 @@ // limitations under the License. use std::cmp; +#[cfg(not(feature = "nightly"))] +#[inline(always)] +pub unsafe fn unlikely(x: bool) -> bool { + x +} + +#[cfg(feature = "nightly")] +pub use ::std::intrinsics::unlikely; + /// Threading utilities pub mod thread { /// Like `thread::spawn`, but with a `name` argument -- cgit