]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/monomorphize/mod.rs
Auto merge of #61587 - alexcrichton:distcheck-no-assertions, r=pietroalbini
[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<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9                                            source_ty: Ty<'tcx>,
10                                            target_ty: Ty<'tcx>)
11                                            -> CustomCoerceUnsized {
12     let def_id = tcx.lang_items().coerce_unsized_trait().unwrap();
13
14     let trait_ref = ty::Binder::bind(ty::TraitRef {
15         def_id: def_id,
16         substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()])
17     });
18
19     match tcx.codegen_fulfill_obligation( (ty::ParamEnv::reveal_all(), trait_ref)) {
20         traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
21             tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
22         }
23         vtable => {
24             bug!("invalid CoerceUnsized vtable: {:?}", vtable);
25         }
26     }
27 }