Skip to content

Commit 7cf1f18

Browse files
committed
Test NonZero in a const item in a pattern.
(This was buggy before #46882)
1 parent 6d682c9 commit 7cf1f18

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libcore/tests/nonzero.rs

+23
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,26 @@ fn test_match_option_string() {
9898
None => panic!("unexpected None while matching on Some(String { ... })")
9999
}
100100
}
101+
102+
mod atom {
103+
use core::num::NonZeroU32;
104+
105+
#[derive(PartialEq, Eq)]
106+
pub struct Atom {
107+
index: NonZeroU32, // private
108+
}
109+
pub const FOO_ATOM: Atom = Atom { index: unsafe { NonZeroU32::new_unchecked(7) } };
110+
}
111+
112+
macro_rules! atom {
113+
("foo") => { atom::FOO_ATOM }
114+
}
115+
116+
#[test]
117+
fn test_match_nonzero_const_pattern() {
118+
match atom!("foo") {
119+
// Using as a pattern is supported by the compiler:
120+
atom!("foo") => {}
121+
_ => panic!("Expected the const item as a pattern to match.")
122+
}
123+
}

0 commit comments

Comments
 (0)