summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty/instance.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle/src/ty/instance.rs')
-rw-r--r--compiler/rustc_middle/src/ty/instance.rs63
1 files changed, 40 insertions, 23 deletions
diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs
index 6c1414f7b..586460986 100644
--- a/compiler/rustc_middle/src/ty/instance.rs
+++ b/compiler/rustc_middle/src/ty/instance.rs
@@ -276,28 +276,45 @@ impl<'tcx> InstanceDef<'tcx> {
}
}
-impl<'tcx> fmt::Display for Instance<'tcx> {
+fn fmt_instance(
+ f: &mut fmt::Formatter<'_>,
+ instance: &Instance<'_>,
+ type_length: rustc_session::Limit,
+) -> fmt::Result {
+ ty::tls::with(|tcx| {
+ let substs = tcx.lift(instance.substs).expect("could not lift for printing");
+
+ let s = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
+ .print_def_path(instance.def_id(), substs)?
+ .into_buffer();
+ f.write_str(&s)
+ })?;
+
+ match instance.def {
+ InstanceDef::Item(_) => Ok(()),
+ InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
+ InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
+ InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
+ InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
+ InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
+ InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
+ InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
+ InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
+ InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
+ }
+}
+
+pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
+
+impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- ty::tls::with(|tcx| {
- let substs = tcx.lift(self.substs).expect("could not lift for printing");
- let s = FmtPrinter::new(tcx, Namespace::ValueNS)
- .print_def_path(self.def_id(), substs)?
- .into_buffer();
- f.write_str(&s)
- })?;
+ fmt_instance(f, self.0, rustc_session::Limit(self.1))
+ }
+}
- match self.def {
- InstanceDef::Item(_) => Ok(()),
- InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
- InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
- InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
- InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
- InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
- InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
- InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
- InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
- InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
- }
+impl<'tcx> fmt::Display for Instance<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
}
}
@@ -511,12 +528,12 @@ impl<'tcx> Instance<'tcx> {
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
}
+ #[instrument(level = "debug", skip(tcx), ret)]
pub fn fn_once_adapter_instance(
tcx: TyCtxt<'tcx>,
closure_did: DefId,
substs: ty::SubstsRef<'tcx>,
) -> Option<Instance<'tcx>> {
- debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
let fn_once = tcx.require_lang_item(LangItem::FnOnce, None);
let call_once = tcx
.associated_items(fn_once)
@@ -534,9 +551,9 @@ impl<'tcx> Instance<'tcx> {
let sig =
tcx.try_normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig).ok()?;
assert_eq!(sig.inputs().len(), 1);
- let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
+ let substs = tcx.mk_substs_trait(self_ty, [sig.inputs()[0].into()]);
- debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
+ debug!(?self_ty, ?sig);
Some(Instance { def, substs })
}