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