]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_monomorphize/src/lib.rs
Rollup merge of #97363 - wackbyte:sliceindex-doc-typo, r=JohnTitor
[rust.git] / compiler / rustc_monomorphize / src / lib.rs
1 #![feature(array_windows)]
2 #![feature(control_flow_enum)]
3 #![feature(let_else)]
4 #![recursion_limit = "256"]
5 #![allow(rustc::potential_query_instability)]
6
7 #[macro_use]
8 extern crate tracing;
9 #[macro_use]
10 extern crate rustc_middle;
11
12 use rustc_hir::lang_items::LangItem;
13 use rustc_middle::traits;
14 use rustc_middle::ty::adjustment::CustomCoerceUnsized;
15 use rustc_middle::ty::query::Providers;
16 use rustc_middle::ty::{self, Ty, TyCtxt};
17
18 mod collector;
19 mod partitioning;
20 mod polymorphize;
21 mod util;
22
23 fn custom_coerce_unsize_info<'tcx>(
24     tcx: TyCtxt<'tcx>,
25     source_ty: Ty<'tcx>,
26     target_ty: Ty<'tcx>,
27 ) -> CustomCoerceUnsized {
28     let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None);
29
30     let trait_ref = ty::Binder::dummy(ty::TraitRef {
31         def_id,
32         substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
33     });
34
35     match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
36         Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
37             impl_def_id,
38             ..
39         })) => tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap(),
40         impl_source => {
41             bug!("invalid `CoerceUnsized` impl_source: {:?}", impl_source);
42         }
43     }
44 }
45
46 pub fn provide(providers: &mut Providers) {
47     partitioning::provide(providers);
48     polymorphize::provide(providers);
49 }