rustc_monomorphize/
lib.rs1#![cfg_attr(bootstrap, feature(array_windows))]
3#![feature(file_buffered)]
4#![feature(if_let_guard)]
5#![feature(impl_trait_in_assoc_type)]
6#![feature(once_cell_get_mut)]
7use rustc_hir::lang_items::LangItem;
10use rustc_middle::query::TyCtxtAt;
11use rustc_middle::ty::adjustment::CustomCoerceUnsized;
12use rustc_middle::ty::{self, Ty};
13use rustc_middle::util::Providers;
14use rustc_middle::{bug, traits};
15use rustc_span::ErrorGuaranteed;
16
17mod collector;
18mod errors;
19mod graph_checks;
20mod mono_checks;
21mod partitioning;
22mod util;
23
24#[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" }
25
26fn custom_coerce_unsize_info<'tcx>(
27 tcx: TyCtxtAt<'tcx>,
28 source_ty: Ty<'tcx>,
29 target_ty: Ty<'tcx>,
30) -> Result<CustomCoerceUnsized, ErrorGuaranteed> {
31 let trait_ref = ty::TraitRef::new(
32 tcx.tcx,
33 tcx.require_lang_item(LangItem::CoerceUnsized, tcx.span),
34 [source_ty, target_ty],
35 );
36
37 match tcx
38 .codegen_select_candidate(ty::TypingEnv::fully_monomorphized().as_query_input(trait_ref))
39 {
40 Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
41 impl_def_id,
42 ..
43 })) => Ok(tcx.coerce_unsized_info(impl_def_id)?.custom_kind.unwrap()),
44 impl_source => {
45 ::rustc_middle::util::bug::bug_fmt(format_args!("invalid `CoerceUnsized` from {1} to {2}: impl_source: {0:?}",
impl_source, source_ty, target_ty));bug!(
46 "invalid `CoerceUnsized` from {source_ty} to {target_ty}: impl_source: {:?}",
47 impl_source
48 );
49 }
50 }
51}
52
53pub fn provide(providers: &mut Providers) {
54 partitioning::provide(providers);
55 mono_checks::provide(&mut providers.queries);
56}