Skip to content

Commit adf37ec

Browse files
committed
Always check the lang item first
1 parent 134b4ef commit adf37ec

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
143143
&mut candidates,
144144
);
145145
}
146-
_ => {
147-
// FIXME: Put these into match arms above, since they're built-in.
148-
self.assemble_closure_candidates(obligation, &mut candidates);
146+
Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
149147
self.assemble_async_closure_candidates(obligation, &mut candidates);
148+
}
149+
Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
150+
self.assemble_closure_candidates(obligation, &mut candidates);
150151
self.assemble_fn_pointer_candidates(obligation, &mut candidates);
151152
}
153+
_ => {}
152154
}
153155

154156
self.assemble_candidates_from_impls(obligation, &mut candidates);
@@ -384,9 +386,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
384386
obligation: &PolyTraitObligation<'tcx>,
385387
candidates: &mut SelectionCandidateSet<'tcx>,
386388
) {
387-
let Some(kind) = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()) else {
388-
return;
389-
};
389+
let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
390390

391391
// Okay to skip binder because the args on closure types never
392392
// touch bound regions, they just capture the in-scope
@@ -448,11 +448,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
448448
obligation: &PolyTraitObligation<'tcx>,
449449
candidates: &mut SelectionCandidateSet<'tcx>,
450450
) {
451-
let Some(goal_kind) =
452-
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id())
453-
else {
454-
return;
455-
};
451+
let goal_kind =
452+
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
456453

457454
match *obligation.self_ty().skip_binder().kind() {
458455
ty::CoroutineClosure(_, args) => {
@@ -525,11 +522,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
525522
obligation: &PolyTraitObligation<'tcx>,
526523
candidates: &mut SelectionCandidateSet<'tcx>,
527524
) {
528-
// We provide impl of all fn traits for fn pointers.
529-
if !self.tcx().is_fn_trait(obligation.predicate.def_id()) {
530-
return;
531-
}
532-
533525
// Keep this function in sync with extract_tupled_inputs_and_output_from_callable
534526
// until the old solver (and thus this function) is removed.
535527

0 commit comments

Comments
 (0)