2021-01-02 13:42:15 +00:00
|
|
|
#![feature(array_windows)]
|
2021-09-01 19:05:35 +00:00
|
|
|
#![recursion_limit = "256"]
|
2022-02-23 13:06:22 +00:00
|
|
|
#![allow(rustc::potential_query_instability)]
|
2022-08-18 21:51:47 +00:00
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
2021-01-02 13:42:15 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_middle;
|
|
|
|
|
2022-10-13 09:13:02 +00:00
|
|
|
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
2023-04-16 12:33:00 +00:00
|
|
|
use rustc_fluent_macro::fluent_messages;
|
2021-01-02 13:42:15 +00:00
|
|
|
use rustc_hir::lang_items::LangItem;
|
2023-05-15 04:24:45 +00:00
|
|
|
use rustc_middle::query::Providers;
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::traits;
|
|
|
|
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
2023-05-15 04:24:45 +00:00
|
|
|
use rustc_middle::ty::query::TyCtxtAt;
|
2022-11-17 14:39:19 +00:00
|
|
|
use rustc_middle::ty::{self, Ty};
|
2017-10-25 14:14:51 +00:00
|
|
|
|
2021-01-02 13:42:15 +00:00
|
|
|
mod collector;
|
2022-08-18 21:51:47 +00:00
|
|
|
mod errors;
|
2021-01-02 13:42:15 +00:00
|
|
|
mod partitioning;
|
|
|
|
mod polymorphize;
|
|
|
|
mod util;
|
2017-10-25 14:14:51 +00:00
|
|
|
|
2023-03-02 23:18:38 +00:00
|
|
|
fluent_messages! { "../messages.ftl" }
|
2022-10-13 09:13:02 +00:00
|
|
|
|
2021-01-07 05:41:55 +00:00
|
|
|
fn custom_coerce_unsize_info<'tcx>(
|
2022-11-17 14:39:19 +00:00
|
|
|
tcx: TyCtxtAt<'tcx>,
|
2019-06-11 21:11:55 +00:00
|
|
|
source_ty: Ty<'tcx>,
|
|
|
|
target_ty: Ty<'tcx>,
|
|
|
|
) -> CustomCoerceUnsized {
|
2023-04-25 16:07:48 +00:00
|
|
|
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
2023-04-26 10:55:11 +00:00
|
|
|
tcx.tcx,
|
2023-04-25 16:07:48 +00:00
|
|
|
LangItem::CoerceUnsized,
|
2023-04-26 10:55:11 +00:00
|
|
|
tcx.span,
|
2023-04-25 16:07:48 +00:00
|
|
|
[source_ty, target_ty],
|
|
|
|
));
|
2017-10-25 14:14:51 +00:00
|
|
|
|
2022-09-09 11:36:27 +00:00
|
|
|
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
|
2020-09-24 17:22:36 +00: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 14:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 13:42:15 +00:00
|
|
|
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
|
|
partitioning::provide(providers);
|
|
|
|
polymorphize::provide(providers);
|
|
|
|
}
|