1#![feature(array_try_map)]
3#![feature(decl_macro)]
4#![feature(deref_patterns)]
5#![feature(never_type)]
6#![feature(slice_ptr_get)]
7#![feature(trait_alias)]
8#![feature(unqualified_local_imports)]
9#![feature(yeet_expr)]
10#![warn(unqualified_local_imports)]
11pub mod check_consts;
14pub mod const_eval;
15mod diagnostics;
16pub mod interpret;
17pub mod util;
18
19use std::sync::atomic::AtomicBool;
20
21use rustc_middle::util::Providers;
22use rustc_middle::{bug, ty};
23
24fn assert_typing_mode(typing_mode: ty::TypingMode<'_>) {
29 if truecfg!(debug_assertions) {
30 match typing_mode.assert_not_erased() {
31 ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => {}
32 ty::TypingMode::Coherence
35 | ty::TypingMode::Typeck { .. }
36 | ty::TypingMode::Reflection
37 | ty::TypingMode::PostTypeckUntilBorrowck { .. }
38 | ty::TypingMode::PostBorrowck { .. } => ::rustc_middle::util::bug::bug_fmt(format_args!("Const eval should always happens in PostAnalysis or Codegen mode. See the comment on `assert_typing_mode` for more details."))bug!(
39 "Const eval should always happens in PostAnalysis or Codegen mode. See the comment on `assert_typing_mode` for more details."
40 ),
41 }
42 }
43}
44
45pub fn provide(providers: &mut Providers) {
46 const_eval::provide(&mut providers.queries);
47 providers.queries.tag_for_variant = const_eval::tag_for_variant_provider;
48 providers.queries.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
49 providers.queries.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
50 providers.queries.eval_static_initializer = const_eval::eval_static_initializer_provider;
51 providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
52 providers.queries.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| {
53 const_eval::eval_to_valtree(tcx, typing_env, value)
54 };
55 providers.hooks.try_destructure_mir_constant_for_user_output =
56 const_eval::try_destructure_mir_constant_for_user_output;
57 providers.queries.valtree_to_const_val =
58 |tcx, cv| const_eval::valtree_to_const_value(tcx, ty::TypingEnv::fully_monomorphized(), cv);
59 providers.queries.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
60 util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
61 };
62 providers.hooks.validate_scalar_in_layout =
63 |tcx, scalar, layout| util::validate_scalar_in_layout(tcx, scalar, layout);
64}
65
66pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);