summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-03-17 13:42:54 +0100
committerRalf Jung <post@ralfj.de>2024-03-20 11:07:12 +0100
commitf1ec494c322a2eabbba0bf93867170f702e7a05a (patch)
treee225dd8a85d2131df7600ca6d9359d7ac086c41a /compiler/rustc_mir_transform/src
parent347ca50bc82734b45ed1834fd3a15ed978aba258 (diff)
downloadrust-f1ec494c322a2eabbba0bf93867170f702e7a05a.tar.gz
rust-f1ec494c322a2eabbba0bf93867170f702e7a05a.zip
mentioned items: also handle closure-to-fn-ptr coercions
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/mentioned_items.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs
index 0e0114c9d2c..63f898630ab 100644
--- a/compiler/rustc_mir_transform/src/mentioned_items.rs
+++ b/compiler/rustc_mir_transform/src/mentioned_items.rs
@@ -74,6 +74,22 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> {
                     span,
                 });
             }
+            // Similarly, record closures that are turned into function pointers.
+            mir::Rvalue::Cast(
+                mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)),
+                ref operand,
+                _,
+            ) => {
+                let span = self.body.source_info(location).span;
+                let source_ty = operand.ty(self.body, self.tcx);
+                match *source_ty.kind() {
+                    ty::Closure(def_id, args) => {
+                        self.mentioned_items
+                            .push(Spanned { node: MentionedItem::Closure(def_id, args), span });
+                    }
+                    _ => bug!(),
+                }
+            }
             // Function pointer casts are already handled by `visit_constant` above.
             _ => {}
         }