From f1ec494c322a2eabbba0bf93867170f702e7a05a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Mar 2024 13:42:54 +0100 Subject: mentioned items: also handle closure-to-fn-ptr coercions --- compiler/rustc_mir_transform/src/mentioned_items.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'compiler/rustc_mir_transform/src') 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. _ => {} } -- cgit 1.4.1-3-g733a5