Skip to content

Commit e925043

Browse files
committed
Make diagnostics know about more coro closures than async closures
1 parent e83e369 commit e925043

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1893,9 +1893,7 @@ impl CoroutineKind {
18931893
CoroutineKind::Coroutine(mov) => mov,
18941894
}
18951895
}
1896-
}
18971896

1898-
impl CoroutineKind {
18991897
pub fn is_fn_like(self) -> bool {
19001898
matches!(self, CoroutineKind::Desugared(_, CoroutineSource::Fn))
19011899
}

compiler/rustc_trait_selection/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ trait_selection_adjust_signature_remove_borrow = consider adjusting the signatur
7272
7373
trait_selection_ascribe_user_type_prove_predicate = ...so that the where clause holds
7474
75-
trait_selection_async_closure_not_fn = async closure does not implement `{$kind}` because it captures state from its environment
75+
trait_selection_coro_closure_not_fn = {$coro_kind} closure does not implement `{$kind}` because it captures state from its environment
7676
7777
trait_selection_await_both_futures = consider `await`ing on both `Future`s
7878
trait_selection_await_future = consider `await`ing on the `Future`

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ use super::{
3737
use crate::error_reporting::TypeErrCtxt;
3838
use crate::error_reporting::infer::TyCategory;
3939
use crate::error_reporting::traits::report_dyn_incompatibility;
40-
use crate::errors::{
41-
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
42-
};
40+
use crate::errors::{ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch, CoroClosureNotFn};
4341
use crate::infer::{self, InferCtxt, InferCtxtExt as _};
4442
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
4543
use crate::traits::{
@@ -887,15 +885,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
887885
}
888886

889887
// If the closure has captures, then perhaps the reason that the trait
890-
// is unimplemented is because async closures don't implement `Fn`/`FnMut`
888+
// is unimplemented is because coro closures don't implement `Fn`/`FnMut`
891889
// if they have captures.
892890
if let Some(by_ref_captures) = by_ref_captures
893891
&& let ty::FnPtr(sig_tys, _) = by_ref_captures.kind()
894892
&& !sig_tys.skip_binder().output().is_unit()
895893
{
896-
let mut err = self.dcx().create_err(AsyncClosureNotFn {
894+
let mut err = self.dcx().create_err(CoroClosureNotFn {
897895
span: self.tcx.def_span(closure_def_id),
898896
kind: expected_kind.as_str(),
897+
coro_kind: self.tcx.coroutine_kind(closure_def_id).unwrap().to_string(),
899898
});
900899
self.note_obligation_cause(&mut err, &obligation);
901900
return Some(err.emit());

compiler/rustc_trait_selection/src/errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ pub struct ClosureFnMutLabel {
170170
}
171171

172172
#[derive(Diagnostic)]
173-
#[diag(trait_selection_async_closure_not_fn)]
174-
pub(crate) struct AsyncClosureNotFn {
173+
#[diag(trait_selection_coro_closure_not_fn)]
174+
pub(crate) struct CoroClosureNotFn {
175175
#[primary_span]
176176
pub span: Span,
177177
pub kind: &'static str,
178+
pub coro_kind: String,
178179
}
179180

180181
#[derive(Diagnostic)]

0 commit comments

Comments
 (0)