diff --git a/tests/ui/future-sizes/future-as-arg.rs b/tests/ui/future-sizes/future-as-arg.rs new file mode 100644 index 00000000000..e021ff512e3 --- /dev/null +++ b/tests/ui/future-sizes/future-as-arg.rs @@ -0,0 +1,19 @@ +// edition: 2021 +// run-pass + +async fn test(_arg: [u8; 8192]) {} + +async fn use_future(fut: impl std::future::Future) { + fut.await +} + +fn main() { + let n = std::mem::size_of_val(&use_future(use_future(use_future(use_future(use_future( + use_future(use_future(use_future(use_future(use_future(test( + [0; 8192] + )))))) + )))))); + println!("size is: {n}"); + // Not putting an exact number in case it slightly changes over different commits + assert!(n > 8000000); +} diff --git a/tests/ui/future-sizes/large-arg.rs b/tests/ui/future-sizes/large-arg.rs new file mode 100644 index 00000000000..c543c71f13c --- /dev/null +++ b/tests/ui/future-sizes/large-arg.rs @@ -0,0 +1,17 @@ +// compile-flags: -Z print-type-sizes --crate-type=lib +// edition: 2021 +// build-pass + +pub async fn test() { + let _ = a([0u8; 1024]).await; +} + +pub async fn a(t: T) -> T { + b(t).await +} +async fn b(t: T) -> T { + c(t).await +} +async fn c(t: T) -> T { + t +} diff --git a/tests/ui/future-sizes/large-arg.stdout b/tests/ui/future-sizes/large-arg.stdout new file mode 100644 index 00000000000..cd5a22a270a --- /dev/null +++ b/tests/ui/future-sizes/large-arg.stdout @@ -0,0 +1,60 @@ +print-type-size type: `[async fn body@$DIR/large-arg.rs:5:21: 7:2]`: 3076 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Suspend0`: 3075 bytes +print-type-size field `.__awaitee`: 3075 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Unresumed`: 0 bytes +print-type-size variant `Returned`: 0 bytes +print-type-size variant `Panicked`: 0 bytes +print-type-size type: `[async fn body@$DIR/large-arg.rs:9:30: 11:2]`: 3075 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Suspend0`: 3074 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size field `.__awaitee`: 2050 bytes +print-type-size variant `Unresumed`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Returned`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Panicked`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:9:30: 11:2]>`: 3075 bytes, alignment: 1 bytes +print-type-size field `.value`: 3075 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:9:30: 11:2]>`: 3075 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 3075 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 3075 bytes +print-type-size type: `[async fn body@$DIR/large-arg.rs:12:26: 14:2]`: 2050 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Suspend0`: 2049 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size field `.__awaitee`: 1025 bytes +print-type-size variant `Unresumed`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Returned`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Panicked`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:12:26: 14:2]>`: 2050 bytes, alignment: 1 bytes +print-type-size field `.value`: 2050 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:12:26: 14:2]>`: 2050 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 2050 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 2050 bytes +print-type-size type: `[async fn body@$DIR/large-arg.rs:15:26: 17:2]`: 1025 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Returned`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Panicked`: 1024 bytes +print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:15:26: 17:2]>`: 1025 bytes, alignment: 1 bytes +print-type-size field `.value`: 1025 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:15:26: 17:2]>`: 1025 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 1025 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 1025 bytes +print-type-size type: `std::task::Poll<[u8; 1024]>`: 1025 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Ready`: 1024 bytes +print-type-size field `.0`: 1024 bytes +print-type-size variant `Pending`: 0 bytes