about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Lapkin <waffle.lapkin@gmail.com>2024-11-29 20:25:57 +0100
committerMaybe Lapkin <waffle.lapkin@gmail.com>2024-11-29 20:25:57 +0100
commitd93ea6bc79a06bcf6c8cbbd3af24f8724acd5009 (patch)
tree480af23d895032d98714f4ab0ff0862d86d90607
parent3208b8649e2e117b08e5bbcae46061d44bf72203 (diff)
downloadrust-d93ea6bc79a06bcf6c8cbbd3af24f8724acd5009.tar.gz
rust-d93ea6bc79a06bcf6c8cbbd3af24f8724acd5009.zip
simplify things by using `tcx.fn_trait_kind_from_def_id`
-rw-r--r--compiler/rustc_mir_build/src/check_tail_calls.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/compiler/rustc_mir_build/src/check_tail_calls.rs b/compiler/rustc_mir_build/src/check_tail_calls.rs
index 911a6cb7de6..f7264341c0a 100644
--- a/compiler/rustc_mir_build/src/check_tail_calls.rs
+++ b/compiler/rustc_mir_build/src/check_tail_calls.rs
@@ -91,22 +91,16 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
         // Closures in thir look something akin to
         // `for<'a> extern "rust-call" fn(&'a [closure@...], ()) -> <[closure@...] as FnOnce<()>>::Output {<[closure@...] as Fn<()>>::call}`
         // So we have to check for them in this weird way...
-        if let &ty::FnDef(did, substs) = ty.kind() {
+        if let &ty::FnDef(did, args) = ty.kind() {
             let parent = self.tcx.parent(did);
-            let fn_ = self.tcx.require_lang_item(LangItem::Fn, Some(expr.span));
-            let fn_once = self.tcx.require_lang_item(LangItem::FnOnce, Some(expr.span));
-            let fn_mut = self.tcx.require_lang_item(LangItem::FnMut, Some(expr.span));
-            if [fn_, fn_once, fn_mut].contains(&parent) {
-                if substs.first().and_then(|arg| arg.as_type()).is_some_and(|t| t.is_closure()) {
-                    self.report_calling_closure(
-                        &self.thir[fun],
-                        substs[1].as_type().unwrap(),
-                        expr,
-                    );
-
-                    // Tail calling is likely to cause unrelated errors (ABI, argument mismatches)
-                    return;
-                }
+            if self.tcx.fn_trait_kind_from_def_id(parent).is_some()
+                && args.first().and_then(|arg| arg.as_type()).is_some_and(Ty::is_closure)
+            {
+                self.report_calling_closure(&self.thir[fun], args[1].as_type().unwrap(), expr);
+
+                // Tail calling is likely to cause unrelated errors (ABI, argument mismatches),
+                // skip them, producing an error about calling a closure is enough.
+                return;
             };
         }