Skip to content

Commit 6a63183

Browse files
Signature deduction is only done for Fn traits
1 parent 50e1580 commit 6a63183

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+7-27
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
1414
use rustc_middle::ty::GenericArgs;
1515
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
1616
use rustc_span::def_id::LocalDefId;
17-
use rustc_span::{sym, Span};
17+
use rustc_span::Span;
1818
use rustc_target::spec::abi::Abi;
1919
use rustc_trait_selection::traits;
2020
use rustc_trait_selection::traits::error_reporting::ArgKind;
@@ -347,36 +347,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
347347
let tcx = self.tcx;
348348

349349
let trait_def_id = projection.trait_def_id(tcx);
350-
351-
let is_fn = tcx.is_fn_trait(trait_def_id);
352-
353-
let coroutine_trait = tcx.lang_items().coroutine_trait();
354-
let is_gen = coroutine_trait == Some(trait_def_id);
355-
356-
if !is_fn && !is_gen {
357-
debug!("not fn or coroutine");
358-
return None;
359-
}
360-
361-
// Check that we deduce the signature from the `<_ as std::ops::Coroutine>::Return`
362-
// associated item and not yield.
363-
if is_gen && self.tcx.associated_item(projection.projection_def_id()).name != sym::Return {
364-
debug!("not `Return` assoc item of `Coroutine`");
350+
// For now, we only do signature deduction based off of the `Fn` traits.
351+
if !tcx.is_fn_trait(trait_def_id) {
365352
return None;
366353
}
367354

368-
let input_tys = if is_fn {
369-
let arg_param_ty = projection.skip_binder().projection_ty.args.type_at(1);
370-
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
371-
debug!(?arg_param_ty);
355+
let arg_param_ty = projection.skip_binder().projection_ty.args.type_at(1);
356+
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
357+
debug!(?arg_param_ty);
372358

373-
match arg_param_ty.kind() {
374-
&ty::Tuple(tys) => tys,
375-
_ => return None,
376-
}
377-
} else {
378-
// Coroutines with a `()` resume type may be defined with 0 or 1 explicit arguments,
379-
// else they must have exactly 1 argument. For now though, just give up in this case.
359+
let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
380360
return None;
381361
};
382362

0 commit comments

Comments
 (0)