diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml index d60efb69ad4..8c514312511 100644 --- a/components/canvas_traits/Cargo.toml +++ b/components/canvas_traits/Cargo.toml @@ -9,9 +9,6 @@ publish = false name = "canvas_traits" path = "lib.rs" -[features] -unstable = ["nonzero/unstable"] - [dependencies] cssparser = "0.22.0" euclid = "0.15" diff --git a/components/canvas_traits/lib.rs b/components/canvas_traits/lib.rs index 8ca51a3ddde..4664a082fdd 100644 --- a/components/canvas_traits/lib.rs +++ b/components/canvas_traits/lib.rs @@ -5,8 +5,6 @@ #![crate_name = "canvas_traits"] #![crate_type = "rlib"] -#![cfg_attr(feature = "unstable", feature(nonzero))] - #![deny(unsafe_code)] extern crate cssparser; diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index 236cf14443c..e8ed7c5d497 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -9,9 +9,6 @@ publish = false name = "compositing" path = "lib.rs" -[features] -unstable = ["nonzero/unstable"] - [dependencies] euclid = "0.15" gfx_traits = {path = "../gfx_traits"} diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index ee053c47182..b2abdcbf94d 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #![deny(unsafe_code)] -#![cfg_attr(feature = "unstable", feature(nonzero))] extern crate euclid; extern crate gfx_traits; diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index b9d6177273b..2d659bd4342 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -9,9 +9,6 @@ publish = false name = "constellation" path = "lib.rs" -[features] -unstable = ["servo_remutex/unstable"] - [dependencies] backtrace = "0.3" bluetooth_traits = { path = "../bluetooth_traits" } diff --git a/components/layout/lib.rs b/components/layout/lib.rs index a55fcac4520..efab7c69752 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -5,7 +5,6 @@ #![deny(unsafe_code)] #![feature(box_patterns)] #![feature(conservative_impl_trait)] -#![feature(nonzero)] #![feature(raw)] extern crate app_units; diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 1fe552588bf..3132eccf68a 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -6,7 +6,6 @@ //! painted. #![feature(mpsc_select)] -#![cfg_attr(feature = "unstable", feature(nonzero))] extern crate app_units; extern crate atomic_refcell; diff --git a/components/msg/lib.rs b/components/msg/lib.rs index b1743ad02a9..6181e2d3cc6 100644 --- a/components/msg/lib.rs +++ b/components/msg/lib.rs @@ -2,9 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![cfg_attr(feature = "unstable", feature(nonzero))] -#![cfg_attr(feature = "unstable", feature(const_fn))] -#![cfg_attr(feature = "unstable", feature(const_nonzero_new))] #![deny(unsafe_code)] #[macro_use] diff --git a/components/nonzero/lib.rs b/components/nonzero/lib.rs index 078bd0f5b2c..6682740f34e 100644 --- a/components/nonzero/lib.rs +++ b/components/nonzero/lib.rs @@ -6,8 +6,9 @@ //! or some stable types with an equivalent API (but no memory layout optimization). #![cfg_attr(feature = "unstable", feature(nonzero))] +#![cfg_attr(feature = "unstable", feature(const_fn))] +#![cfg_attr(feature = "unstable", feature(const_nonzero_new))] -#[cfg(not(feature = "unstable"))] #[macro_use] extern crate serde; @@ -18,8 +19,23 @@ mod imp { extern crate core; use self::core::nonzero::NonZero; - pub type NonZeroU32 = NonZero; - pub type NonZeroUsize = NonZero; + #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] + pub struct NonZeroU32(NonZero); + + #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] + pub struct NonZeroUsize(NonZero); + + impl NonZeroU32 { + #[inline] pub const unsafe fn new_unchecked(x: u32) -> Self { NonZeroU32(NonZero::new_unchecked(x)) } + #[inline] pub fn new(x: u32) -> Option { NonZero::new(x).map(NonZeroU32) } + #[inline] pub fn get(self) -> u32 { self.0.get() } + } + + impl NonZeroUsize { + #[inline] pub const unsafe fn new_unchecked(x: usize) -> Self { NonZeroUsize(NonZero::new_unchecked(x)) } + #[inline] pub fn new(x: usize) -> Option { NonZero::new(x).map(NonZeroUsize) } + #[inline] pub fn get(self) -> usize { self.0.get() } + } } #[cfg(not(feature = "unstable"))] diff --git a/components/remutex/Cargo.toml b/components/remutex/Cargo.toml index b3937587a62..f03fa5ada18 100644 --- a/components/remutex/Cargo.toml +++ b/components/remutex/Cargo.toml @@ -9,9 +9,6 @@ publish = false name = "servo_remutex" path = "lib.rs" -[features] -unstable = ["nonzero/unstable"] - [dependencies] lazy_static = "0.2" log = "0.3.5" diff --git a/components/remutex/lib.rs b/components/remutex/lib.rs index 6793429bf1e..2589a6d1162 100644 --- a/components/remutex/lib.rs +++ b/components/remutex/lib.rs @@ -10,8 +10,6 @@ //! It provides the same interface as https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/remutex.rs //! so if those types are ever exported, we should be able to replace this implemtation. -#![cfg_attr(feature = "unstable", feature(nonzero))] - extern crate nonzero; #[macro_use] extern crate lazy_static; #[macro_use] extern crate log; diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index acdea4bca17..9dfad06a89c 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -9,9 +9,6 @@ publish = false name = "script_layout_interface" path = "lib.rs" -[features] -unstable = ["nonzero/unstable"] - [dependencies] app_units = "0.5" atomic_refcell = "0.1" diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index f81092a8492..7b45d9688f1 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -7,7 +7,6 @@ //! to depend on script. #![deny(unsafe_code)] -#![cfg_attr(feature = "unstable", feature(nonzero))] extern crate app_units; extern crate atomic_refcell; diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 4858ef1b3f3..27358a388b1 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -20,14 +20,9 @@ googlevr = ["webvr/googlevr"] oculusvr = ["webvr/oculusvr"] unstable = [ "euclid/unstable", - "layout_thread/unstable", "msg/unstable", - "canvas_traits/unstable", - "compositing/unstable", - "constellation/unstable", "gfx/unstable", "profile/unstable", - "script_layout_interface/unstable", ] [dependencies]