1
Fork 0
rust/compiler/rustc_monomorphize/src/lib.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.4 KiB
Rust
Raw Normal View History

// tidy-alphabetical-start
#![feature(array_windows)]
2024-09-05 00:34:04 +03:00
#![feature(if_let_guard)]
#![feature(let_chains)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_hir::lang_items::LangItem;
use rustc_middle::query::TyCtxtAt;
2020-03-29 16:41:09 +02:00
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
use rustc_middle::ty::{self, Ty};
use rustc_middle::util::Providers;
2020-03-29 16:41:09 +02:00
use rustc_middle::{bug, traits};
2024-01-23 15:23:22 +00:00
use rustc_span::ErrorGuaranteed;
mod collector;
mod errors;
mod partitioning;
mod polymorphize;
mod util;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2021-01-07 00:41:55 -05:00
fn custom_coerce_unsize_info<'tcx>(
tcx: TyCtxtAt<'tcx>,
source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>,
2024-01-23 15:23:22 +00:00
) -> Result<CustomCoerceUnsized, ErrorGuaranteed> {
2024-05-10 14:59:56 -04:00
let trait_ref = ty::TraitRef::new(
tcx.tcx,
2024-05-10 14:59:56 -04:00
tcx.require_lang_item(LangItem::CoerceUnsized, Some(tcx.span)),
[source_ty, target_ty],
);
2022-09-09 13:36:27 +02:00
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
impl_def_id,
..
2024-01-23 15:23:22 +00:00
})) => Ok(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);
}
}
}
pub fn provide(providers: &mut Providers) {
partitioning::provide(providers);
polymorphize::provide(providers);
}