Preserve originally intended test semantics

This commit is contained in:
Oliver Scherer 2019-09-20 12:22:06 +02:00
parent 50ec10e605
commit 9c1ad0ff2f

View File

@ -3,8 +3,10 @@
#![feature(untagged_unions)] #![feature(untagged_unions)]
union MaybeItem<T: Iterator> where T::Item: Copy { use std::mem::ManuallyDrop;
elem: T::Item,
union MaybeItem<T: Iterator> {
elem: ManuallyDrop<T::Item>,
none: (), none: (),
} }
@ -25,7 +27,7 @@ fn main() {
let v: Vec<u8> = vec![1, 2, 3]; let v: Vec<u8> = vec![1, 2, 3];
let mut i = v.iter(); let mut i = v.iter();
i.next(); i.next();
let mi = MaybeItem::<std::slice::Iter<_>> { elem: i.next().unwrap() }; let mi = MaybeItem::<std::slice::Iter<_>> { elem: ManuallyDrop::new(i.next().unwrap()) };
assert_eq!(*mi.elem, 2); assert_eq!(**mi.elem, 2);
} }
} }