diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2018-02-16 19:28:13 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2018-03-17 23:07:40 +0100 |
| commit | 7cf1f18cb9209156108e3871e11cb5d63f7f1cf1 (patch) | |
| tree | 1665a029ff20f72d7ba0ad42294ccb600cac48bf /src/libcore/tests | |
| parent | 6d682c9adc12c5aee1bac37afa15f01b420be8ee (diff) | |
| download | rust-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.rs | 23 |
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.") + } +} |
