about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-03-23 09:27:06 -0500
committerGitHub <noreply@github.com>2018-03-23 09:27:06 -0500
commit7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25 (patch)
tree9997fb91ff9e2a46755aabf8fb2ae2c141eae380 /src/libcore/tests
parent55e1104dd918a809d2751d325c11d59c85485a2e (diff)
parenta23f685296b2edd59acc998411340184b958ec82 (diff)
downloadrust-7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25.tar.gz
rust-7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25.zip
Rollup merge of #48265 - SimonSapin:nonzero, r=KodrAus
Add 12 num::NonZero* types for primitive integers, deprecate core::nonzero

RFC: https://github.com/rust-lang/rfcs/pull/2307
Tracking issue: ~~https://github.com/rust-lang/rust/issues/27730~~ https://github.com/rust-lang/rust/issues/49137
Fixes https://github.com/rust-lang/rust/issues/27730
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/nonzero.rs37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs
index a795dd57504..8d39298bac3 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(_))")
     }
 }
 
@@ -98,3 +98,26 @@ fn test_match_option_string() {
         None => panic!("unexpected None while matching on Some(String { ... })")
     }
 }
+
+mod atom {
+    use core::num::NonZeroU32;
+
+    #[derive(PartialEq, Eq)]
+    pub struct Atom {
+        index: NonZeroU32, // private
+    }
+    pub const FOO_ATOM: Atom = Atom { index: unsafe { NonZeroU32::new_unchecked(7) } };
+}
+
+macro_rules! atom {
+    ("foo") => { atom::FOO_ATOM }
+}
+
+#[test]
+fn test_match_nonzero_const_pattern() {
+    match atom!("foo") {
+        // Using as a pattern is supported by the compiler:
+        atom!("foo") => {}
+        _ => panic!("Expected the const item as a pattern to match.")
+    }
+}