Skip to content

Commit

Permalink
Unrolled build for rust-lang#121617
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#121617 - compiler-errors:async-closure-kind-check, r=oli-obk

Actually use the right closure kind when checking async Fn goals

Dumb copy-paste mistake on my part from rust-lang#120712. Sorry!

r? oli-obk

Fixes rust-lang#121599
  • Loading branch information
rust-timer committed Feb 26, 2024
2 parents b79db43 + ff07f55 commit c937e42
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
}
ty::Closure(_, args) => {
let sig = args.as_closure().sig();
let args = args.as_closure();
let sig = args.sig();
let trait_ref = sig.map_bound(|sig| {
ty::TraitRef::new(
self.tcx(),
Expand All @@ -950,7 +951,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])
}),
));
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
(trait_ref, args.kind_ty())
}
_ => bug!("expected callable type for AsyncFn candidate"),
};
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/async-await/async-closures/wrong-fn-kind.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ edition:2021

// FIXME(async_closures): This needs a better error message!

#![feature(async_closure)]

fn main() {
Expand All @@ -12,4 +10,10 @@ fn main() {
//~^ ERROR expected a closure that implements the `async Fn` trait, but this closure only implements `async FnMut`
x += 1;
});

let x = String::new();
needs_async_fn(move || async move {
//~^ ERROR expected a closure that implements the `async Fn` trait, but this closure only implements `async FnOnce`
println!("{x}");
});
}
27 changes: 24 additions & 3 deletions tests/ui/async-await/async-closures/wrong-fn-kind.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0525]: expected a closure that implements the `async Fn` trait, but this closure only implements `async FnMut`
--> $DIR/wrong-fn-kind.rs:11:20
--> $DIR/wrong-fn-kind.rs:9:20
|
LL | needs_async_fn(async || {
| -------------- -^^^^^^^
Expand All @@ -14,11 +14,32 @@ LL | | });
| |_____- the requirement to implement `async Fn` derives from here
|
note: required by a bound in `needs_async_fn`
--> $DIR/wrong-fn-kind.rs:8:31
--> $DIR/wrong-fn-kind.rs:6:31
|
LL | fn needs_async_fn(_: impl async Fn()) {}
| ^^^^^^^^^^ required by this bound in `needs_async_fn`

error: aborting due to 1 previous error
error[E0525]: expected a closure that implements the `async Fn` trait, but this closure only implements `async FnOnce`
--> $DIR/wrong-fn-kind.rs:15:20
|
LL | needs_async_fn(move || async move {
| -------------- -^^^^^^
| | |
| _____|______________this closure implements `async FnOnce`, not `async Fn`
| | |
| | required by a bound introduced by this call
LL | |
LL | | println!("{x}");
| | - closure is `async FnOnce` because it moves the variable `x` out of its environment
LL | | });
| |_____- the requirement to implement `async Fn` derives from here
|
note: required by a bound in `needs_async_fn`
--> $DIR/wrong-fn-kind.rs:6:31
|
LL | fn needs_async_fn(_: impl async Fn()) {}
| ^^^^^^^^^^ required by this bound in `needs_async_fn`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0525`.

0 comments on commit c937e42

Please sign in to comment.