]> git.lizzy.rs Git - rust.git/commitdiff
Test NonZero in a const item in a pattern.
authorSimon Sapin <simon.sapin@exyr.org>
Fri, 16 Feb 2018 18:28:13 +0000 (19:28 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Sat, 17 Mar 2018 22:07:40 +0000 (23:07 +0100)
(This was buggy before https://github.com/rust-lang/rust/pull/46882)

src/libcore/tests/nonzero.rs

index 9eaf7529dd3cf89ac03b953b4025c59029890ccb..8d39298bac3d1b1b3cd13210987fac5e94a1bf71 100644 (file)
@@ -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.")
+    }
+}