1 // Test that we don't duplicate storage for futures moved around in .await, and
2 // for futures moved into other futures.
4 // The exact sizes can change by a few bytes (we'd like to know when they do).
5 // What we don't want to see is the wrong multiple of 1024 (the size of BigFut)
6 // being reflected in the size.
8 // See issue #59123 for a full explanation.
10 // ignore-emscripten (sizes don't match)
15 use std::future::Future;
17 use std::task::{Context, Poll};
19 const BIG_FUT_SIZE: usize = 1024;
20 struct BigFut([u8; BIG_FUT_SIZE]);
24 BigFut([0; BIG_FUT_SIZE])
28 impl Drop for BigFut {
32 impl Future for BigFut {
35 fn poll(self: Pin<&mut Self>, _ctx: &mut Context<'_>) -> Poll<Self::Output> {
47 impl Future for Joiner {
50 fn poll(self: Pin<&mut Self>, _ctx: &mut Context<'_>) -> Poll<Self::Output> {
58 let x = BigFut::new();
62 async fn single_with_noop() {
63 let x = BigFut::new();
69 let a = BigFut::new();
70 let b = BigFut::new();
71 let c = BigFut::new();
81 async fn joined_with_noop() {
82 let a = BigFut::new();
83 let b = BigFut::new();
84 let c = BigFut::new();
95 async fn mixed_sizes() {
96 let a = BigFut::new();
97 let b = BigFut::new();
98 let c = BigFut::new();
99 let d = BigFut::new();
100 let e = BigFut::new();
101 let joiner = Joiner {
113 assert_eq!(1025, std::mem::size_of_val(&single()));
114 assert_eq!(1026, std::mem::size_of_val(&single_with_noop()));
115 assert_eq!(3078, std::mem::size_of_val(&joined()));
116 assert_eq!(3079, std::mem::size_of_val(&joined_with_noop()));
117 assert_eq!(7181, std::mem::size_of_val(&mixed_sizes()));