about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-02-16 11:02:06 +0100
committerSimon Sapin <simon.sapin@exyr.org>2018-03-17 23:07:40 +0100
commit67f46ce1122121849890ad51c35f0eb6ded14b6f (patch)
tree8523a2ef4a2ebe803ec55ae60f282a34caf71951
parent2d13ddb6e14322edcd07135a436d0d848d127fb2 (diff)
downloadrust-67f46ce1122121849890ad51c35f0eb6ded14b6f.tar.gz
rust-67f46ce1122121849890ad51c35f0eb6ded14b6f.zip
Use num::NonZero* instead of NonZero<_> in rustc and tests
-rw-r--r--src/libcore/tests/nonzero.rs14
-rw-r--r--src/librustc/ty/subst.rs6
-rw-r--r--src/librustc_data_structures/obligation_forest/node_index.rs6
-rw-r--r--src/librustc_mir/dataflow/move_paths/mod.rs6
-rw-r--r--src/test/run-pass/enum-null-pointer-opt.rs9
-rw-r--r--src/test/run-pass/issue-23433.rs2
-rw-r--r--src/test/ui/print_type_sizes/niche-filling.rs31
-rw-r--r--src/test/ui/print_type_sizes/niche-filling.stdout10
8 files changed, 38 insertions, 46 deletions
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs
index a795dd57504..9eaf7529dd3 100644
--- a/src/libcore/tests/nonzero.rs
+++ b/src/libcore/tests/nonzero.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use core::nonzero::NonZero;
+use core::num::NonZeroU32;
 use core::option::Option;
 use core::option::Option::{Some, None};
 use std::mem::size_of;
@@ -16,28 +16,28 @@ use std::mem::size_of;
 #[test]
 fn test_create_nonzero_instance() {
     let _a = unsafe {
-        NonZero::new_unchecked(21)
+        NonZeroU32::new_unchecked(21)
     };
 }
 
 #[test]
 fn test_size_nonzero_in_option() {
-    assert_eq!(size_of::<NonZero<u32>>(), size_of::<Option<NonZero<u32>>>());
+    assert_eq!(size_of::<NonZeroU32>(), size_of::<Option<NonZeroU32>>());
 }
 
 #[test]
 fn test_match_on_nonzero_option() {
     let a = Some(unsafe {
-        NonZero::new_unchecked(42)
+        NonZeroU32::new_unchecked(42)
     });
     match a {
         Some(val) => assert_eq!(val.get(), 42),
-        None => panic!("unexpected None while matching on Some(NonZero(_))")
+        None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
     }
 
-    match unsafe { Some(NonZero::new_unchecked(43)) } {
+    match unsafe { Some(NonZeroU32::new_unchecked(43)) } {
         Some(val) => assert_eq!(val.get(), 43),
-        None => panic!("unexpected None while matching on Some(NonZero(_))")
+        None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
     }
 }
 
diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs
index a301049fe1c..e7b58ae1564 100644
--- a/src/librustc/ty/subst.rs
+++ b/src/librustc/ty/subst.rs
@@ -19,11 +19,11 @@ use syntax_pos::{Span, DUMMY_SP};
 use rustc_data_structures::accumulate_vec::AccumulateVec;
 
 use core::intrinsics;
-use core::nonzero::NonZero;
 use std::fmt;
 use std::iter;
 use std::marker::PhantomData;
 use std::mem;
+use std::num::NonZeroUsize;
 
 /// An entity in the Rust typesystem, which can be one of
 /// several kinds (only types and lifetimes for now).
@@ -32,7 +32,7 @@ use std::mem;
 /// indicate the type (`Ty` or `Region`) it points to.
 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
 pub struct Kind<'tcx> {
-    ptr: NonZero<usize>,
+    ptr: NonZeroUsize,
     marker: PhantomData<(Ty<'tcx>, ty::Region<'tcx>)>
 }
 
@@ -63,7 +63,7 @@ impl<'tcx> UnpackedKind<'tcx> {
 
         Kind {
             ptr: unsafe {
-                NonZero::new_unchecked(ptr | tag)
+                NonZeroUsize::new_unchecked(ptr | tag)
             },
             marker: PhantomData
         }
diff --git a/src/librustc_data_structures/obligation_forest/node_index.rs b/src/librustc_data_structures/obligation_forest/node_index.rs
index a72cc6b57ea..37512e4bcd5 100644
--- a/src/librustc_data_structures/obligation_forest/node_index.rs
+++ b/src/librustc_data_structures/obligation_forest/node_index.rs
@@ -8,18 +8,18 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use core::nonzero::NonZero;
+use std::num::NonZeroU32;
 use std::u32;
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub struct NodeIndex {
-    index: NonZero<u32>,
+    index: NonZeroU32,
 }
 
 impl NodeIndex {
     pub fn new(value: usize) -> NodeIndex {
         assert!(value < (u32::MAX as usize));
-        NodeIndex { index: NonZero::new((value as u32) + 1).unwrap() }
+        NodeIndex { index: NonZeroU32::new((value as u32) + 1).unwrap() }
     }
 
     pub fn get(self) -> usize {
diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs
index 7b6ebc6fba8..9f6cf8c036e 100644
--- a/src/librustc_mir/dataflow/move_paths/mod.rs
+++ b/src/librustc_mir/dataflow/move_paths/mod.rs
@@ -29,17 +29,17 @@ mod abs_domain;
 // (which is likely to yield a subtle off-by-one error).
 pub(crate) mod indexes {
     use std::fmt;
-    use core::nonzero::NonZero;
+    use std::num::NonZeroUsize;
     use rustc_data_structures::indexed_vec::Idx;
 
     macro_rules! new_index {
         ($Index:ident, $debug_name:expr) => {
             #[derive(Copy, Clone, PartialEq, Eq, Hash)]
-            pub struct $Index(NonZero<usize>);
+            pub struct $Index(NonZeroUsize);
 
             impl Idx for $Index {
                 fn new(idx: usize) -> Self {
-                    $Index(NonZero::new(idx + 1).unwrap())
+                    $Index(NonZeroUsize::new(idx + 1).unwrap())
                 }
                 fn index(self) -> usize {
                     self.0.get() - 1
diff --git a/src/test/run-pass/enum-null-pointer-opt.rs b/src/test/run-pass/enum-null-pointer-opt.rs
index e296aff2782..12f17a1575e 100644
--- a/src/test/run-pass/enum-null-pointer-opt.rs
+++ b/src/test/run-pass/enum-null-pointer-opt.rs
@@ -10,10 +10,9 @@
 
 #![feature(nonzero, core)]
 
-extern crate core;
-
-use core::nonzero::NonZero;
 use std::mem::size_of;
+use std::num::NonZeroUsize;
+use std::ptr::NonNull;
 use std::rc::Rc;
 use std::sync::Arc;
 
@@ -59,8 +58,8 @@ fn main() {
     assert_eq!(size_of::<[Box<isize>; 1]>(), size_of::<Option<[Box<isize>; 1]>>());
 
     // Should apply to NonZero
-    assert_eq!(size_of::<NonZero<usize>>(), size_of::<Option<NonZero<usize>>>());
-    assert_eq!(size_of::<NonZero<*mut i8>>(), size_of::<Option<NonZero<*mut i8>>>());
+    assert_eq!(size_of::<NonZeroUsize>(), size_of::<Option<NonZeroUsize>>());
+    assert_eq!(size_of::<NonNull<i8>>(), size_of::<Option<NonNull<i8>>>());
 
     // Should apply to types that use NonZero internally
     assert_eq!(size_of::<Vec<isize>>(), size_of::<Option<Vec<isize>>>());
diff --git a/src/test/run-pass/issue-23433.rs b/src/test/run-pass/issue-23433.rs
index 7af732f561d..9547b2f08a6 100644
--- a/src/test/run-pass/issue-23433.rs
+++ b/src/test/run-pass/issue-23433.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// Don't fail if we encounter a NonZero<*T> where T is an unsized type
+// Don't fail if we encounter a NonNull<T> where T is an unsized type
 
 use std::ptr::NonNull;
 
diff --git a/src/test/ui/print_type_sizes/niche-filling.rs b/src/test/ui/print_type_sizes/niche-filling.rs
index 7f234e243e9..875883a2cca 100644
--- a/src/test/ui/print_type_sizes/niche-filling.rs
+++ b/src/test/ui/print_type_sizes/niche-filling.rs
@@ -14,7 +14,7 @@
 // This file illustrates how niche-filling enums are handled,
 // modelled after cases like `Option<&u32>`, `Option<bool>` and such.
 //
-// It uses NonZero directly, rather than `&_` or `Unique<_>`, because
+// It uses NonZeroU32 rather than `&_` or `Unique<_>`, because
 // the test is not set up to deal with target-dependent pointer width.
 //
 // It avoids using u64/i64 because on some targets that is only 4-byte
@@ -25,8 +25,7 @@
 #![feature(nonzero)]
 #![allow(dead_code)]
 
-extern crate core;
-use core::nonzero::{NonZero, Zeroable};
+use std::num::NonZeroU32;
 
 pub enum MyOption<T> { None, Some(T) }
 
@@ -36,7 +35,7 @@ impl<T> Default for MyOption<T> {
 
 pub enum EmbeddedDiscr {
     None,
-    Record { pre: u8, val: NonZero<u32>, post: u16 },
+    Record { pre: u8, val: NonZeroU32, post: u16 },
 }
 
 impl Default for EmbeddedDiscr {
@@ -44,32 +43,24 @@ impl Default for EmbeddedDiscr {
 }
 
 #[derive(Default)]
-pub struct IndirectNonZero<T: Zeroable + One> {
+pub struct IndirectNonZero {
     pre: u8,
-    nested: NestedNonZero<T>,
+    nested: NestedNonZero,
     post: u16,
 }
 
-pub struct NestedNonZero<T: Zeroable> {
+pub struct NestedNonZero {
     pre: u8,
-    val: NonZero<T>,
+    val: NonZeroU32,
     post: u16,
 }
 
-impl<T: Zeroable+One> Default for NestedNonZero<T> {
+impl Default for NestedNonZero {
     fn default() -> Self {
-        NestedNonZero { pre: 0, val: NonZero::new(T::one()).unwrap(), post: 0 }
+        NestedNonZero { pre: 0, val: NonZeroU32::new(1).unwrap(), post: 0 }
     }
 }
 
-pub trait One {
-    fn one() -> Self;
-}
-
-impl One for u32 {
-    fn one() -> Self { 1 }
-}
-
 pub enum Enum4<A, B, C, D> {
     One(A),
     Two(B),
@@ -79,9 +70,9 @@ pub enum Enum4<A, B, C, D> {
 
 #[start]
 fn start(_: isize, _: *const *const u8) -> isize {
-    let _x: MyOption<NonZero<u32>> = Default::default();
+    let _x: MyOption<NonZeroU32> = Default::default();
     let _y: EmbeddedDiscr = Default::default();
-    let _z: MyOption<IndirectNonZero<u32>> = Default::default();
+    let _z: MyOption<IndirectNonZero> = Default::default();
     let _a: MyOption<bool> = Default::default();
     let _b: MyOption<char> = Default::default();
     let _c: MyOption<std::cmp::Ordering> = Default::default();
diff --git a/src/test/ui/print_type_sizes/niche-filling.stdout b/src/test/ui/print_type_sizes/niche-filling.stdout
index 0f53e7722dd..79f9ef5a231 100644
--- a/src/test/ui/print_type_sizes/niche-filling.stdout
+++ b/src/test/ui/print_type_sizes/niche-filling.stdout
@@ -1,9 +1,9 @@
-print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
+print-type-size type: `IndirectNonZero`: 12 bytes, alignment: 4 bytes
 print-type-size     field `.nested`: 8 bytes
 print-type-size     field `.post`: 2 bytes
 print-type-size     field `.pre`: 1 bytes
 print-type-size     end padding: 1 bytes
-print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
+print-type-size type: `MyOption<IndirectNonZero>`: 12 bytes, alignment: 4 bytes
 print-type-size     variant `None`: 0 bytes
 print-type-size     variant `Some`: 12 bytes
 print-type-size         field `.0`: 12 bytes
@@ -14,7 +14,7 @@ print-type-size         field `.val`: 4 bytes
 print-type-size         field `.post`: 2 bytes
 print-type-size         field `.pre`: 1 bytes
 print-type-size     end padding: 1 bytes
-print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
+print-type-size type: `NestedNonZero`: 8 bytes, alignment: 4 bytes
 print-type-size     field `.val`: 4 bytes
 print-type-size     field `.post`: 2 bytes
 print-type-size     field `.pre`: 1 bytes
@@ -32,12 +32,14 @@ print-type-size type: `MyOption<char>`: 4 bytes, alignment: 4 bytes
 print-type-size     variant `None`: 0 bytes
 print-type-size     variant `Some`: 4 bytes
 print-type-size         field `.0`: 4 bytes
-print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
+print-type-size type: `MyOption<std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
 print-type-size     variant `None`: 0 bytes
 print-type-size     variant `Some`: 4 bytes
 print-type-size         field `.0`: 4 bytes
 print-type-size type: `core::nonzero::NonZero<u32>`: 4 bytes, alignment: 4 bytes
 print-type-size     field `.0`: 4 bytes
+print-type-size type: `std::num::NonZeroU32`: 4 bytes, alignment: 4 bytes
+print-type-size     field `.0`: 4 bytes
 print-type-size type: `Enum4<(), (), (), MyOption<u8>>`: 2 bytes, alignment: 1 bytes
 print-type-size     variant `One`: 0 bytes
 print-type-size         field `.0`: 0 bytes