about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-02-16 19:28:13 +0100
committerSimon Sapin <simon.sapin@exyr.org>2018-03-17 23:07:40 +0100
commit7cf1f18cb9209156108e3871e11cb5d63f7f1cf1 (patch)
tree1665a029ff20f72d7ba0ad42294ccb600cac48bf /src/libcore/tests
parent6d682c9adc12c5aee1bac37afa15f01b420be8ee (diff)
downloadrust-7cf1f18cb9209156108e3871e11cb5d63f7f1cf1.tar.gz
rust-7cf1f18cb9209156108e3871e11cb5d63f7f1cf1.zip
Test NonZero in a const item in a pattern.
(This was buggy before https://github.com/rust-lang/rust/pull/46882)
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/nonzero.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs
index 9eaf7529dd3..8d39298bac3 100644
--- a/src/libcore/tests/nonzero.rs
+++ b/src/libcore/tests/nonzero.rs
@@ -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.")
+    }
+}