]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/monomorphize/mod.rs
Rollup merge of #67233 - Luro02:cursor_traits, r=sfackler
[rust.git] / src / librustc_mir / monomorphize / mod.rs
1 use rustc::traits;
2 use rustc::ty::adjustment::CustomCoerceUnsized;
3 use rustc::ty::{self, Ty, TyCtxt};
4
5 pub mod collector;
6 pub mod partitioning;
7
8 pub fn custom_coerce_unsize_info<'tcx>(
9     tcx: TyCtxt<'tcx>,
10     source_ty: Ty<'tcx>,
11     target_ty: Ty<'tcx>,
12 ) -> CustomCoerceUnsized {
13     let def_id = tcx.lang_items().coerce_unsized_trait().unwrap();
14
15     let trait_ref = ty::Binder::bind(ty::TraitRef {
16         def_id: def_id,
17         substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
18     });
19
20     match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
21         traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
22             tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
23         }
24         vtable => {
25             bug!("invalid `CoerceUnsized` vtable: {:?}", vtable);
26         }
27     }
28 }