Skip to content

Commit

Permalink
Test NonZero in a const item in a pattern.
Browse files Browse the repository at this point in the history
(This was buggy before rust-lang#46882)
  • Loading branch information
SimonSapin committed Mar 17, 2018
1 parent 6d682c9 commit 7cf1f18
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libcore/tests/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

0 comments on commit 7cf1f18

Please sign in to comment.