diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-03 04:09:43 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-03-03 04:09:43 +0000 |
| commit | e213f4beeabbb2604565a8e9324f66c5c72780c6 (patch) | |
| tree | 3fd6c7429d54b7eb967a0b971d0d6e2a1884802a /tests | |
| parent | daf59857d6d2b87af4b846316bf1561a6083ed51 (diff) | |
| download | rust-e213f4beeabbb2604565a8e9324f66c5c72780c6.tar.gz rust-e213f4beeabbb2604565a8e9324f66c5c72780c6.zip | |
Improve error message for AsyncFn trait failure for RPIT
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/async-await/async-closures/kind-due-to-rpit.rs | 14 | ||||
| -rw-r--r-- | tests/ui/async-await/async-closures/kind-due-to-rpit.stderr | 17 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/async-await/async-closures/kind-due-to-rpit.rs b/tests/ui/async-await/async-closures/kind-due-to-rpit.rs new file mode 100644 index 00000000000..ad19d93b93a --- /dev/null +++ b/tests/ui/async-await/async-closures/kind-due-to-rpit.rs @@ -0,0 +1,14 @@ +//@ edition: 2024 + +// Make sure the error message is understandable when an `AsyncFn` goal is not satisfied +// (due to closure kind), and that goal originates from an RPIT. + +fn repro(foo: impl Into<bool>) -> impl AsyncFn() { + let inner_fn = async move || { + //~^ ERROR expected a closure that implements the `AsyncFn` trait + let _ = foo.into(); + }; + inner_fn +} + +fn main() {} diff --git a/tests/ui/async-await/async-closures/kind-due-to-rpit.stderr b/tests/ui/async-await/async-closures/kind-due-to-rpit.stderr new file mode 100644 index 00000000000..982cc50e14f --- /dev/null +++ b/tests/ui/async-await/async-closures/kind-due-to-rpit.stderr @@ -0,0 +1,17 @@ +error[E0525]: expected a closure that implements the `AsyncFn` trait, but this closure only implements `AsyncFnOnce` + --> $DIR/kind-due-to-rpit.rs:7:20 + | +LL | fn repro(foo: impl Into<bool>) -> impl AsyncFn() { + | -------------- the requirement to implement `AsyncFn` derives from here +LL | let inner_fn = async move || { + | ^^^^^^^^^^^^^ this closure implements `AsyncFnOnce`, not `AsyncFn` +LL | +LL | let _ = foo.into(); + | --- closure is `AsyncFnOnce` because it moves the variable `foo` out of its environment +LL | }; +LL | inner_fn + | -------- return type was inferred to be `{async closure@$DIR/kind-due-to-rpit.rs:7:20: 7:33}` here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0525`. |
