Error on using yield without also using #[coroutine] on the closure

And suggest adding the `#[coroutine]` to the closure
This commit is contained in:
Oli Scherer 2024-04-11 13:15:34 +00:00
parent 53b5056977
commit 3fc9537624
5 changed files with 13 additions and 15 deletions

View File

@ -1,9 +1,9 @@
// Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 // Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562
#![feature(coroutines, coroutine_trait)] #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
fn main() { fn main() {
let _ = || { let _ = #[coroutine] || {
yield; yield;
}; };
} }

View File

@ -1,4 +1,3 @@
#![feature(coroutines)]
#![warn(clippy::large_futures)] #![warn(clippy::large_futures)]
#![allow(clippy::never_loop)] #![allow(clippy::never_loop)]
#![allow(clippy::future_not_send)] #![allow(clippy::future_not_send)]

View File

@ -1,4 +1,3 @@
#![feature(coroutines)]
#![warn(clippy::large_futures)] #![warn(clippy::large_futures)]
#![allow(clippy::never_loop)] #![allow(clippy::never_loop)]
#![allow(clippy::future_not_send)] #![allow(clippy::future_not_send)]

View File

@ -1,5 +1,5 @@
error: large future with a size of 16385 bytes error: large future with a size of 16385 bytes
--> tests/ui/large_futures.rs:11:9 --> tests/ui/large_futures.rs:10:9
| |
LL | big_fut([0u8; 1024 * 16]).await; LL | big_fut([0u8; 1024 * 16]).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))`
@ -8,37 +8,37 @@ LL | big_fut([0u8; 1024 * 16]).await;
= help: to override `-D warnings` add `#[allow(clippy::large_futures)]` = help: to override `-D warnings` add `#[allow(clippy::large_futures)]`
error: large future with a size of 16386 bytes error: large future with a size of 16386 bytes
--> tests/ui/large_futures.rs:15:5 --> tests/ui/large_futures.rs:14:5
| |
LL | f.await LL | f.await
| ^ help: consider `Box::pin` on it: `Box::pin(f)` | ^ help: consider `Box::pin` on it: `Box::pin(f)`
error: large future with a size of 16387 bytes error: large future with a size of 16387 bytes
--> tests/ui/large_futures.rs:20:9 --> tests/ui/large_futures.rs:19:9
| |
LL | wait().await; LL | wait().await;
| ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())`
error: large future with a size of 16387 bytes error: large future with a size of 16387 bytes
--> tests/ui/large_futures.rs:25:13 --> tests/ui/large_futures.rs:24:13
| |
LL | wait().await; LL | wait().await;
| ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())`
error: large future with a size of 65540 bytes error: large future with a size of 65540 bytes
--> tests/ui/large_futures.rs:33:5 --> tests/ui/large_futures.rs:32:5
| |
LL | foo().await; LL | foo().await;
| ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())`
error: large future with a size of 49159 bytes error: large future with a size of 49159 bytes
--> tests/ui/large_futures.rs:35:5 --> tests/ui/large_futures.rs:34:5
| |
LL | calls_fut(fut).await; LL | calls_fut(fut).await;
| ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))` | ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))`
error: large future with a size of 65540 bytes error: large future with a size of 65540 bytes
--> tests/ui/large_futures.rs:48:5 --> tests/ui/large_futures.rs:47:5
| |
LL | / async { LL | / async {
LL | | LL | |
@ -59,7 +59,7 @@ LL + })
| |
error: large future with a size of 65540 bytes error: large future with a size of 65540 bytes
--> tests/ui/large_futures.rs:60:13 --> tests/ui/large_futures.rs:59:13
| |
LL | / async { LL | / async {
LL | | let x = [0i32; 1024 * 16]; LL | | let x = [0i32; 1024 * 16];

View File

@ -1,7 +1,7 @@
//@aux-build:proc_macros.rs //@aux-build:proc_macros.rs
#![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)] #![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)]
#![warn(clippy::redundant_locals)] #![warn(clippy::redundant_locals)]
#![feature(async_closure, coroutines)] #![feature(async_closure, coroutines, stmt_expr_attributes)]
extern crate proc_macros; extern crate proc_macros;
use proc_macros::{external, with_span}; use proc_macros::{external, with_span};
@ -191,11 +191,11 @@ fn assert_static<T: 'static>(_: T) {}
let v4 = v4; let v4 = v4;
dbg!(&v4); dbg!(&v4);
}); });
assert_static(static || { assert_static(#[coroutine] static || {
let v5 = v5; let v5 = v5;
yield; yield;
}); });
assert_static(|| { assert_static(#[coroutine] || {
let v6 = v6; let v6 = v6;
yield; yield;
}); });