Skip to content

Commit a4896a3

Browse files
author
bors-servo
authored
Auto merge of #20474 - servo:nonzero, r=nox
Use new std::num::NonZero* types instead of deprecated core::nonzero::NonZero <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20474) <!-- Reviewable:end -->
2 parents d232705 + 7c73d98 commit a4896a3

File tree

7 files changed

+19
-162
lines changed

7 files changed

+19
-162
lines changed

components/canvas_traits/webgl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use euclid::Size2D;
6-
use nonzero::NonZero;
6+
use nonzero::NonZeroU32;
77
use offscreen_gl_context::{GLContextAttributes, GLLimits};
88
use serde_bytes::ByteBuf;
99
use std::fmt;
@@ -281,13 +281,13 @@ pub enum WebGLCommand {
281281
macro_rules! define_resource_id_struct {
282282
($name:ident) => {
283283
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
284-
pub struct $name(NonZero<u32>);
284+
pub struct $name(NonZeroU32);
285285

286286
impl $name {
287287
#[allow(unsafe_code)]
288288
#[inline]
289289
pub unsafe fn new(id: u32) -> Self {
290-
$name(NonZero::new_unchecked(id))
290+
$name(NonZeroU32::new_unchecked(id))
291291
}
292292

293293
#[inline]

components/compositing/compositor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ipc_channel::ipc::{self, IpcSharedMemory};
1414
use libc::c_void;
1515
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
1616
use net_traits::image::base::{Image, PixelFormat};
17-
use nonzero::NonZero;
17+
use nonzero::NonZeroU32;
1818
use profile_traits::time::{self, ProfilerCategory, profile};
1919
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};
2020
use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId};
@@ -64,7 +64,7 @@ impl ConvertPipelineIdFromWebRender for webrender_api::PipelineId {
6464
fn from_webrender(&self) -> PipelineId {
6565
PipelineId {
6666
namespace_id: PipelineNamespaceId(self.0),
67-
index: PipelineIndex(NonZero::new(self.1).expect("Webrender pipeline zero?")),
67+
index: PipelineIndex(NonZeroU32::new(self.1).expect("Webrender pipeline zero?")),
6868
}
6969
}
7070
}

components/msg/constellation_msg.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! The high-level interface from script to constellation. Using this abstract interface helps
66
//! reduce coupling between these two components.
77
8-
use nonzero::NonZero;
8+
use nonzero::NonZeroU32;
99
use std::cell::Cell;
1010
use std::fmt;
1111
use webrender_api;
@@ -195,9 +195,9 @@ impl PipelineNamespace {
195195
});
196196
}
197197

198-
fn next_index(&mut self) -> NonZero<u32> {
198+
fn next_index(&mut self) -> NonZeroU32 {
199199
self.index += 1;
200-
NonZero::new(self.index).expect("pipeline id index wrapped!")
200+
NonZeroU32::new(self.index).expect("pipeline id index wrapped!")
201201
}
202202

203203
fn next_pipeline_id(&mut self) -> PipelineId {
@@ -221,7 +221,7 @@ thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = C
221221
pub struct PipelineNamespaceId(pub u32);
222222

223223
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
224-
pub struct PipelineIndex(pub NonZero<u32>);
224+
pub struct PipelineIndex(pub NonZeroU32);
225225
malloc_size_of_is_0!(PipelineIndex);
226226

227227
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@@ -252,7 +252,7 @@ impl PipelineId {
252252
unsafe {
253253
PipelineId {
254254
namespace_id: PipelineNamespaceId(namespace_id),
255-
index: PipelineIndex(NonZero::new_unchecked(index)),
255+
index: PipelineIndex(NonZeroU32::new_unchecked(index)),
256256
}
257257
}
258258
}
@@ -279,7 +279,7 @@ impl fmt::Display for PipelineId {
279279
}
280280

281281
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
282-
pub struct BrowsingContextIndex(pub NonZero<u32>);
282+
pub struct BrowsingContextIndex(pub NonZeroU32);
283283
malloc_size_of_is_0!(BrowsingContextIndex);
284284

285285
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@@ -355,13 +355,13 @@ impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
355355
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
356356
#[allow(unsafe_code)]
357357
#[cfg(feature = "unstable")]
358-
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZero::new_unchecked(5678)) };
358+
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZeroU32::new_unchecked(5678)) };
359359
#[cfg(feature = "unstable")]
360360
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
361361
#[allow(unsafe_code)]
362362
#[cfg(feature = "unstable")]
363363
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
364-
unsafe { BrowsingContextIndex(NonZero::new_unchecked(8765)) };
364+
unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) };
365365
#[cfg(feature = "unstable")]
366366
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
367367
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };

components/nonzero/lib.rs

Lines changed: 0 additions & 141 deletions
This file was deleted.

components/remutex/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern crate nonzero;
1414
#[macro_use] extern crate lazy_static;
1515
#[macro_use] extern crate log;
1616

17-
use nonzero::NonZero;
17+
use nonzero::NonZeroUsize;
1818
use std::cell::{Cell, UnsafeCell};
1919
use std::ops::Deref;
2020
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult};
@@ -25,15 +25,15 @@ use std::sync::atomic::{AtomicUsize, Ordering};
2525
// TODO: can we use the thread-id crate for this?
2626

2727
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
28-
pub struct ThreadId(NonZero<usize>);
28+
pub struct ThreadId(NonZeroUsize);
2929

3030
lazy_static!{ static ref THREAD_COUNT: AtomicUsize = AtomicUsize::new(1); }
3131

3232
impl ThreadId {
3333
#[allow(unsafe_code)]
3434
fn new() -> ThreadId {
3535
let number = THREAD_COUNT.fetch_add(1, Ordering::SeqCst);
36-
ThreadId(NonZero::new(number).unwrap())
36+
ThreadId(NonZeroUsize::new(number).unwrap())
3737
}
3838
pub fn current() -> ThreadId {
3939
THREAD_ID.with(|tls| tls.clone())
@@ -57,13 +57,13 @@ impl AtomicOptThreadId {
5757
#[allow(unsafe_code)]
5858
pub fn load(&self, ordering: Ordering) -> Option<ThreadId> {
5959
let number = self.0.load(ordering);
60-
NonZero::new(number).map(ThreadId)
60+
NonZeroUsize::new(number).map(ThreadId)
6161
}
6262
#[allow(unsafe_code)]
6363
pub fn swap(&self, value: Option<ThreadId>, ordering: Ordering) -> Option<ThreadId> {
6464
let number = value.map(|id| id.0.get()).unwrap_or(0);
6565
let number = self.0.swap(number, ordering);
66-
NonZero::new(number).map(ThreadId)
66+
NonZeroUsize::new(number).map(ThreadId)
6767
}
6868
}
6969

components/script/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#![cfg_attr(feature = "unstable", feature(core_intrinsics))]
66
#![cfg_attr(feature = "unstable", feature(on_unimplemented))]
7-
#![feature(ascii_ctype)]
8-
#![feature(conservative_impl_trait)]
97
#![feature(const_fn)]
108
#![feature(mpsc_select)]
119
#![feature(plugin)]

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2018-01-27
1+
nightly-2018-03-29

0 commit comments

Comments
 (0)