mentioned_items: record all callee and coerced closure types, whether they are FnDef/Closure or not

They may become FnDef during monomorphization!
This commit is contained in:
Ralf Jung 2024-03-18 11:36:53 +01:00
parent f1ec494c32
commit 0d6a16ac4b
15 changed files with 355 additions and 76 deletions

View file

@ -45,6 +45,7 @@ use std::ops::{Index, IndexMut};
use std::{iter, mem};
pub use self::query::*;
use self::visit::TyContext;
pub use basic_blocks::BasicBlocks;
mod basic_blocks;
@ -317,15 +318,15 @@ impl<'tcx> CoroutineInfo<'tcx> {
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeFoldable, TypeVisitable)]
pub enum MentionedItem<'tcx> {
Fn(DefId, GenericArgsRef<'tcx>),
/// A function that gets called. We don't necessarily know its precise type yet, since it can be
/// hidden behind a generic.
Fn(Ty<'tcx>),
/// A type that has its drop shim called.
Drop(Ty<'tcx>),
/// Unsizing casts might require vtables, so we have to record them.
UnsizeCast {
source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>,
},
UnsizeCast { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> },
/// A closure that is coerced to a function pointer.
Closure(DefId, GenericArgsRef<'tcx>),
Closure(Ty<'tcx>),
}
/// The lowered representation of a single function.
@ -610,6 +611,17 @@ impl<'tcx> Body<'tcx> {
}
}
pub fn span_for_ty_context(&self, ty_context: TyContext) -> Span {
match ty_context {
TyContext::UserTy(span) => span,
TyContext::ReturnTy(source_info)
| TyContext::LocalDecl { source_info, .. }
| TyContext::YieldTy(source_info)
| TyContext::ResumeTy(source_info) => source_info.span,
TyContext::Location(loc) => self.source_info(loc).span,
}
}
/// Returns the return type; it always return first element from `local_decls` array.
#[inline]
pub fn return_ty(&self) -> Ty<'tcx> {