2 // Test that we don't duplicate storage for a variable that is moved to another
3 // binding. This used to happen in the presence of unwind and drop edges (see
6 // The exact sizes here can change (we'd like to know when they do). What we
7 // don't want to see is the `complex` generator size being upwards of 2048 bytes
8 // (which would indicate it is reserving space for two copies of Foo.)
10 // See issue #59123 for a full explanation.
13 // ignore-wasm32 issue #62807
14 // ignore-asmjs issue #62807
15 // needs-unwind Size of Closures change on panic=abort
17 #![feature(generators, generator_trait)]
19 use std::ops::Generator;
21 const FOO_SIZE: usize = 1024;
22 struct Foo(#[allow(unused_tuple_struct_fields)] [u8; FOO_SIZE]);
28 fn move_before_yield() -> impl Generator<Yield = (), Return = ()> {
30 let first = Foo([0; FOO_SIZE]);
33 // _second dropped here
39 fn move_before_yield_with_noop() -> impl Generator<Yield = (), Return = ()> {
41 let first = Foo([0; FOO_SIZE]);
45 // _second dropped here
49 // Today we don't have NRVO (we allocate space for both `first` and `second`,)
50 // but we can overlap `first` with `_third`.
51 fn overlap_move_points() -> impl Generator<Yield = (), Return = ()> {
53 let first = Foo([0; FOO_SIZE]);
62 fn overlap_x_and_y() -> impl Generator<Yield = (), Return = ()> {
64 let x = Foo([0; FOO_SIZE]);
67 let y = Foo([0; FOO_SIZE]);
74 assert_eq!(1025, std::mem::size_of_val(&move_before_yield()));
75 assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));
76 assert_eq!(2051, std::mem::size_of_val(&overlap_move_points()));
77 assert_eq!(1026, std::mem::size_of_val(&overlap_x_and_y()));