2017-10-25 16:14:51 +02:00
|
|
|
use rustc::traits;
|
|
|
|
use rustc::ty::adjustment::CustomCoerceUnsized;
|
2019-05-23 13:10:11 -05:00
|
|
|
use rustc::ty::{self, Ty, TyCtxt};
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2017-10-25 15:39:54 +02:00
|
|
|
pub mod collector;
|
2017-11-23 16:02:02 +01:00
|
|
|
pub mod partitioning;
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2019-06-12 00:11:55 +03:00
|
|
|
pub fn custom_coerce_unsize_info<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx, 'tcx>,
|
|
|
|
source_ty: Ty<'tcx>,
|
|
|
|
target_ty: Ty<'tcx>,
|
|
|
|
) -> CustomCoerceUnsized {
|
2017-10-25 16:14:51 +02:00
|
|
|
let def_id = tcx.lang_items().coerce_unsized_trait().unwrap();
|
|
|
|
|
2018-04-24 21:45:49 -05:00
|
|
|
let trait_ref = ty::Binder::bind(ty::TraitRef {
|
2017-10-25 16:14:51 +02:00
|
|
|
def_id: def_id,
|
2018-05-16 09:34:09 +03:00
|
|
|
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()])
|
2017-10-25 16:14:51 +02:00
|
|
|
});
|
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
match tcx.codegen_fulfill_obligation( (ty::ParamEnv::reveal_all(), trait_ref)) {
|
2017-10-25 16:14:51 +02:00
|
|
|
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
|
|
|
|
tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
|
|
|
|
}
|
|
|
|
vtable => {
|
|
|
|
bug!("invalid CoerceUnsized vtable: {:?}", vtable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|