mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Rollup merge of #134017 - compiler-errors:call-once-deduction, r=jieyouxu
Don't use `AsyncFnOnce::CallOnceFuture` bounds for signature deduction We shouldn't be using `AsyncFnOnce::CallOnceFuture` projection bounds to deduce anything about the return type of an async closure, **only** `AsyncFnOnce::Output`. This was accidental b/c all we were looking at was the def id of the trait, rather than the projection. This PR fixes that. This doesn't affect stable code, since `CallOnceFuture` bounds cannot be written on stable. Fixes #134015
This commit is contained in:
commit
193a95d30b
@ -454,20 +454,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
closure_kind: hir::ClosureKind,
|
closure_kind: hir::ClosureKind,
|
||||||
projection: ty::PolyProjectionPredicate<'tcx>,
|
projection: ty::PolyProjectionPredicate<'tcx>,
|
||||||
) -> Option<ExpectedSig<'tcx>> {
|
) -> Option<ExpectedSig<'tcx>> {
|
||||||
let tcx = self.tcx;
|
let def_id = projection.projection_def_id();
|
||||||
|
|
||||||
let trait_def_id = projection.trait_def_id(tcx);
|
|
||||||
|
|
||||||
// For now, we only do signature deduction based off of the `Fn` and `AsyncFn` traits,
|
// For now, we only do signature deduction based off of the `Fn` and `AsyncFn` traits,
|
||||||
// for closures and async closures, respectively.
|
// for closures and async closures, respectively.
|
||||||
match closure_kind {
|
match closure_kind {
|
||||||
hir::ClosureKind::Closure
|
hir::ClosureKind::Closure if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
|
||||||
if self.tcx.fn_trait_kind_from_def_id(trait_def_id).is_some() =>
|
|
||||||
{
|
|
||||||
self.extract_sig_from_projection(cause_span, projection)
|
self.extract_sig_from_projection(cause_span, projection)
|
||||||
}
|
}
|
||||||
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
|
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
|
||||||
if self.tcx.async_fn_trait_kind_from_def_id(trait_def_id).is_some() =>
|
if self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput) =>
|
||||||
{
|
{
|
||||||
self.extract_sig_from_projection(cause_span, projection)
|
self.extract_sig_from_projection(cause_span, projection)
|
||||||
}
|
}
|
||||||
@ -475,7 +471,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// `F: FnOnce() -> Fut, Fut: Future<Output = T>` style bound. Let's still
|
// `F: FnOnce() -> Fut, Fut: Future<Output = T>` style bound. Let's still
|
||||||
// guide inference here, since it's beneficial for the user.
|
// guide inference here, since it's beneficial for the user.
|
||||||
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
|
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
|
||||||
if self.tcx.fn_trait_kind_from_def_id(trait_def_id).is_some() =>
|
if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
|
||||||
{
|
{
|
||||||
self.extract_sig_from_projection_and_future_bound(cause_span, projection)
|
self.extract_sig_from_projection_and_future_bound(cause_span, projection)
|
||||||
}
|
}
|
||||||
|
14
tests/ui/async-await/async-closures/call-once-deduction.rs
Normal file
14
tests/ui/async-await/async-closures/call-once-deduction.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//@ edition: 2021
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#![feature(async_closure, async_fn_traits, unboxed_closures)]
|
||||||
|
|
||||||
|
fn bar<F, O>(_: F)
|
||||||
|
where
|
||||||
|
F: AsyncFnOnce<(), CallOnceFuture = O>,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
bar(async move || {});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user