]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/generator/size-moved-locals.rs
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
16 #![feature(generators, generator_trait)]
18 use std
::ops
::Generator
;
20 const FOO_SIZE
: usize = 1024;
21 struct Foo(#[allow(unused_tuple_struct_fields)] [u8; FOO_SIZE]);
27 fn move_before_yield() -> impl Generator
<Yield
= (), Return
= ()> {
29 let first
= Foo([0; FOO_SIZE
]);
32 // _second dropped here
38 fn move_before_yield_with_noop() -> impl Generator
<Yield
= (), Return
= ()> {
40 let first
= Foo([0; FOO_SIZE
]);
44 // _second dropped here
48 // Today we don't have NRVO (we allocate space for both `first` and `second`,)
49 // but we can overlap `first` with `_third`.
50 fn overlap_move_points() -> impl Generator
<Yield
= (), Return
= ()> {
52 let first
= Foo([0; FOO_SIZE
]);
61 fn overlap_x_and_y() -> impl Generator
<Yield
= (), Return
= ()> {
63 let x
= Foo([0; FOO_SIZE
]);
66 let y
= Foo([0; FOO_SIZE
]);
73 assert_eq
!(1025, std
::mem
::size_of_val(&move_before_yield()));
74 assert_eq
!(1026, std
::mem
::size_of_val(&move_before_yield_with_noop()));
75 assert_eq
!(2051, std
::mem
::size_of_val(&overlap_move_points()));
76 assert_eq
!(1026, std
::mem
::size_of_val(&overlap_x_and_y()));