about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-04-28 09:02:06 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-04-29 06:52:42 +0000
commitdd714276e5bc65960816fcdcd2859f4c34ccb680 (patch)
tree8db7075a7925ac2ea9c32920c5aee1f605383ee4
parent19fc3a1a6e9048ecf62c490023b35d41642dd07d (diff)
downloadrust-dd714276e5bc65960816fcdcd2859f4c34ccb680.tar.gz
rust-dd714276e5bc65960816fcdcd2859f4c34ccb680.zip
Always check the lang item first
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
index 99d0a383109..d643ba7f17d 100644
--- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
@@ -139,12 +139,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                                 &mut candidates,
                             );
                         }
-                        _ => {
-                            // FIXME: Put these into match arms above, since they're built-in.
-                            self.assemble_closure_candidates(obligation, &mut candidates);
+                        Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
                             self.assemble_async_closure_candidates(obligation, &mut candidates);
+                        }
+                        Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
+                            self.assemble_closure_candidates(obligation, &mut candidates);
                             self.assemble_fn_pointer_candidates(obligation, &mut candidates);
                         }
+                        _ => {}
                     }
 
                     self.assemble_candidates_from_impls(obligation, &mut candidates);
@@ -380,9 +382,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         obligation: &PolyTraitObligation<'tcx>,
         candidates: &mut SelectionCandidateSet<'tcx>,
     ) {
-        let Some(kind) = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()) else {
-            return;
-        };
+        let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
 
         // Okay to skip binder because the args on closure types never
         // touch bound regions, they just capture the in-scope
@@ -444,11 +444,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         obligation: &PolyTraitObligation<'tcx>,
         candidates: &mut SelectionCandidateSet<'tcx>,
     ) {
-        let Some(goal_kind) =
-            self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id())
-        else {
-            return;
-        };
+        let goal_kind =
+            self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
 
         match *obligation.self_ty().skip_binder().kind() {
             ty::CoroutineClosure(_, args) => {
@@ -521,11 +518,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         obligation: &PolyTraitObligation<'tcx>,
         candidates: &mut SelectionCandidateSet<'tcx>,
     ) {
-        // We provide impl of all fn traits for fn pointers.
-        if !self.tcx().is_fn_trait(obligation.predicate.def_id()) {
-            return;
-        }
-
         // Keep this function in sync with extract_tupled_inputs_and_output_from_callable
         // until the old solver (and thus this function) is removed.