rustc_monomorphize/
lib.rs1#![feature(file_buffered)]
3#![feature(if_let_guard)]
4#![feature(impl_trait_in_assoc_type)]
5#![feature(once_cell_get_mut)]
6use rustc_hir::lang_items::LangItem;
9use rustc_middle::query::TyCtxtAt;
10use rustc_middle::ty::adjustment::CustomCoerceUnsized;
11use rustc_middle::ty::{self, Ty};
12use rustc_middle::util::Providers;
13use rustc_middle::{bug, traits};
14use rustc_span::ErrorGuaranteed;
15
16mod collector;
17mod errors;
18mod graph_checks;
19mod mono_checks;
20mod partitioning;
21mod util;
22
23#[allow(non_upper_case_globals)]
#[doc(hidden)]
#[doc =
r" Auto-generated constants for type-checked references to Fluent messages."]
pub(crate) mod fluent_generated {
#[doc =
"Constant referring to Fluent message `monomorphize_abi_error_disabled_vector_type` from `monomorphize`"]
pub const monomorphize_abi_error_disabled_vector_type:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_abi_error_disabled_vector_type"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_abi_error_disabled_vector_type.label` from `monomorphize`"]
pub const monomorphize_label: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
#[doc =
"Constant referring to Fluent message `monomorphize_abi_error_disabled_vector_type.help` from `monomorphize`"]
pub const monomorphize_help: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
#[doc =
"Constant referring to Fluent message `monomorphize_abi_error_unsupported_unsized_parameter` from `monomorphize`"]
pub const monomorphize_abi_error_unsupported_unsized_parameter:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_abi_error_unsupported_unsized_parameter"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_abi_error_unsupported_vector_type` from `monomorphize`"]
pub const monomorphize_abi_error_unsupported_vector_type:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_abi_error_unsupported_vector_type"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_abi_required_target_feature` from `monomorphize`"]
pub const monomorphize_abi_required_target_feature:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_abi_required_target_feature"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_couldnt_dump_mono_stats` from `monomorphize`"]
pub const monomorphize_couldnt_dump_mono_stats: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_couldnt_dump_mono_stats"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_encountered_error_while_instantiating` from `monomorphize`"]
pub const monomorphize_encountered_error_while_instantiating:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_encountered_error_while_instantiating"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_encountered_error_while_instantiating_global_asm` from `monomorphize`"]
pub const monomorphize_encountered_error_while_instantiating_global_asm:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_encountered_error_while_instantiating_global_asm"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_large_assignments` from `monomorphize`"]
pub const monomorphize_large_assignments: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_large_assignments"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_large_assignments.note` from `monomorphize`"]
pub const monomorphize_note: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
#[doc =
"Constant referring to Fluent message `monomorphize_no_optimized_mir` from `monomorphize`"]
pub const monomorphize_no_optimized_mir: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_no_optimized_mir"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_recursion_limit` from `monomorphize`"]
pub const monomorphize_recursion_limit: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_recursion_limit"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_start_not_found` from `monomorphize`"]
pub const monomorphize_start_not_found: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_start_not_found"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_static_initializer_cyclic` from `monomorphize`"]
pub const monomorphize_static_initializer_cyclic:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_static_initializer_cyclic"),
None);
#[doc =
"Constant referring to Fluent message `monomorphize_symbol_already_defined` from `monomorphize`"]
pub const monomorphize_symbol_already_defined: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("monomorphize_symbol_already_defined"),
None);
#[doc =
r" Constants expected to exist by the diagnostic derive macros to use as default Fluent"]
#[doc = r" identifiers for different subdiagnostic kinds."]
pub mod _subdiag {
#[doc = r" Default for `#[help]`"]
pub const help: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
#[doc = r" Default for `#[note]`"]
pub const note: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
#[doc = r" Default for `#[warn]`"]
pub const warn: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("warn"));
#[doc = r" Default for `#[label]`"]
pub const label: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
#[doc = r" Default for `#[suggestion]`"]
pub const suggestion: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
}
}rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
24
25fn custom_coerce_unsize_info<'tcx>(
26 tcx: TyCtxtAt<'tcx>,
27 source_ty: Ty<'tcx>,
28 target_ty: Ty<'tcx>,
29) -> Result<CustomCoerceUnsized, ErrorGuaranteed> {
30 let trait_ref = ty::TraitRef::new(
31 tcx.tcx,
32 tcx.require_lang_item(LangItem::CoerceUnsized, tcx.span),
33 [source_ty, target_ty],
34 );
35
36 match tcx
37 .codegen_select_candidate(ty::TypingEnv::fully_monomorphized().as_query_input(trait_ref))
38 {
39 Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
40 impl_def_id,
41 ..
42 })) => Ok(tcx.coerce_unsized_info(impl_def_id)?.custom_kind.unwrap()),
43 impl_source => {
44 ::rustc_middle::util::bug::bug_fmt(format_args!("invalid `CoerceUnsized` from {1} to {2}: impl_source: {0:?}",
impl_source, source_ty, target_ty));bug!(
45 "invalid `CoerceUnsized` from {source_ty} to {target_ty}: impl_source: {:?}",
46 impl_source
47 );
48 }
49 }
50}
51
52pub fn provide(providers: &mut Providers) {
53 partitioning::provide(providers);
54 mono_checks::provide(&mut providers.queries);
55}