|
1 | 1 | use rustc_middle::mir::visit::Visitor;
|
2 |
| -use rustc_middle::mir::{self, ConstOperand, Location, MentionedItem, MirPass}; |
| 2 | +use rustc_middle::mir::{self, Location, MentionedItem, MirPass}; |
| 3 | +use rustc_middle::ty::Ty; |
3 | 4 | use rustc_middle::ty::{self, adjustment::PointerCoercion, TyCtxt};
|
4 | 5 | use rustc_session::Session;
|
5 | 6 | use rustc_span::source_map::Spanned;
|
@@ -30,22 +31,21 @@ impl<'tcx> MirPass<'tcx> for MentionedItems {
|
30 | 31 | }
|
31 | 32 |
|
32 | 33 | impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> {
|
33 |
| - fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, _: Location) { |
34 |
| - let const_ = constant.const_; |
35 |
| - // This is how function items get referenced: via constants of `FnDef` type. This handles |
36 |
| - // both functions that are called and those that are just turned to function pointers. |
37 |
| - if let ty::FnDef(def_id, args) = const_.ty().kind() { |
| 34 | + fn visit_ty(&mut self, ty: Ty<'tcx>, ty_context: mir::visit::TyContext) { |
| 35 | + if let ty::FnDef(def_id, args) = ty.kind() { |
38 | 36 | debug!("adding to required_items: {def_id:?}");
|
39 |
| - self.mentioned_items |
40 |
| - .push(Spanned { node: MentionedItem::Fn(*def_id, args), span: constant.span }); |
| 37 | + self.mentioned_items.push(Spanned { |
| 38 | + node: MentionedItem::Fn(*def_id, args), |
| 39 | + span: self.body.span_for_ty_context(ty_context), |
| 40 | + }); |
41 | 41 | }
|
42 | 42 | }
|
43 | 43 |
|
44 | 44 | fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
45 | 45 | self.super_terminator(terminator, location);
|
46 | 46 | match terminator.kind {
|
47 | 47 | // We don't need to handle `Call` as we already handled all function type operands in
|
48 |
| - // `visit_constant`. But we do need to handle `Drop`. |
| 48 | + // `visit_ty`. But we do need to handle `Drop`. |
49 | 49 | mir::TerminatorKind::Drop { place, .. } => {
|
50 | 50 | let ty = place.ty(self.body, self.tcx).ty;
|
51 | 51 | let span = self.body.source_info(location).span;
|
@@ -90,7 +90,7 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> {
|
90 | 90 | _ => bug!(),
|
91 | 91 | }
|
92 | 92 | }
|
93 |
| - // Function pointer casts are already handled by `visit_constant` above. |
| 93 | + // Function pointer casts are already handled by `visit_ty` above. |
94 | 94 | _ => {}
|
95 | 95 | }
|
96 | 96 | }
|
|
0 commit comments