parent
9486f72879
commit
4f859fbcfc
2 changed files with 16 additions and 12 deletions
|
@ -356,3 +356,19 @@ fn test_replace() {
|
|||
assert_eq!(x, Some(3));
|
||||
assert_eq!(old, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_const() {
|
||||
// test that the methods of `Option` are usable in a const context
|
||||
|
||||
const OPTION: Option<usize> = Some(32);
|
||||
|
||||
const REF: Option<&usize> = OPTION.as_ref();
|
||||
assert_eq!(REF, Some(&32));
|
||||
|
||||
const IS_SOME: bool = OPTION.is_some();
|
||||
assert!(IS_SOME);
|
||||
|
||||
const IS_NONE: bool = OPTION.is_none();
|
||||
assert!(!IS_NONE);
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
// run-pass
|
||||
|
||||
const X: Option<i32> = Some(32);
|
||||
const Y: Option<&i32> = X.as_ref();
|
||||
|
||||
const IS_SOME: bool = X.is_some();
|
||||
const IS_NONE: bool = Y.is_none();
|
||||
|
||||
fn main() {
|
||||
assert!(IS_SOME);
|
||||
assert!(!IS_NONE)
|
||||
}
|
Loading…
Add table
Reference in a new issue