2021-01-02 14:42:15 +01:00
|
|
|
#![feature(array_windows)]
|
|
|
|
#![feature(bool_to_option)]
|
|
|
|
#![feature(crate_visibility_modifier)]
|
|
|
|
#![feature(control_flow_enum)]
|
2021-10-16 03:45:14 +02:00
|
|
|
#![feature(let_else)]
|
2021-09-01 21:05:35 +02:00
|
|
|
#![recursion_limit = "256"]
|
2021-01-02 14:42:15 +01:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_middle;
|
|
|
|
|
|
|
|
use rustc_hir::lang_items::LangItem;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::traits;
|
|
|
|
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
2021-01-02 14:42:15 +01:00
|
|
|
use rustc_middle::ty::query::Providers;
|
2021-03-26 17:40:15 -04:00
|
|
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2021-01-02 14:42:15 +01:00
|
|
|
mod collector;
|
|
|
|
mod partitioning;
|
|
|
|
mod polymorphize;
|
|
|
|
mod util;
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2021-01-07 00:41:55 -05:00
|
|
|
fn custom_coerce_unsize_info<'tcx>(
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2019-06-12 00:11:55 +03:00
|
|
|
source_ty: Ty<'tcx>,
|
|
|
|
target_ty: Ty<'tcx>,
|
|
|
|
) -> CustomCoerceUnsized {
|
2020-08-18 11:47:27 +01:00
|
|
|
let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None);
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2021-01-07 00:41:55 -05:00
|
|
|
let trait_ref = ty::Binder::dummy(ty::TraitRef {
|
2020-03-06 19:28:44 +01:00
|
|
|
def_id,
|
2019-12-22 17:42:04 -05:00
|
|
|
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
|
2017-10-25 16:14:51 +02:00
|
|
|
});
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
|
2020-09-24 19:22:36 +02:00
|
|
|
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
|
2020-06-02 15:54:24 +00:00
|
|
|
impl_def_id,
|
|
|
|
..
|
|
|
|
})) => tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap(),
|
2020-05-11 15:25:33 +00:00
|
|
|
impl_source => {
|
|
|
|
bug!("invalid `CoerceUnsized` impl_source: {:?}", impl_source);
|
2017-10-25 16:14:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 14:42:15 +01:00
|
|
|
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
|
|
partitioning::provide(providers);
|
|
|
|
polymorphize::provide(providers);
|
|
|
|
}
|