rustc_const_eval/
lib.rs

1// tidy-alphabetical-start
2#![allow(rustc::diagnostic_outside_of_impl)]
3#![feature(array_try_map)]
4#![feature(assert_matches)]
5#![feature(box_patterns)]
6#![feature(decl_macro)]
7#![feature(if_let_guard)]
8#![feature(never_type)]
9#![feature(slice_ptr_get)]
10#![feature(trait_alias)]
11#![feature(try_blocks)]
12#![feature(unqualified_local_imports)]
13#![feature(yeet_expr)]
14#![warn(unqualified_local_imports)]
15// tidy-alphabetical-end
16
17pub mod check_consts;
18pub mod const_eval;
19mod errors;
20pub mod interpret;
21pub mod util;
22
23use std::sync::atomic::AtomicBool;
24
25use rustc_middle::ty;
26use rustc_middle::util::Providers;
27
28pub use self::errors::ReportErrorExt;
29
30rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
31
32pub fn provide(providers: &mut Providers) {
33    const_eval::provide(providers);
34    providers.tag_for_variant = const_eval::tag_for_variant_provider;
35    providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
36    providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
37    providers.eval_static_initializer = const_eval::eval_static_initializer_provider;
38    providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
39    providers.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| {
40        const_eval::eval_to_valtree(tcx, typing_env, value)
41    };
42    providers.hooks.try_destructure_mir_constant_for_user_output =
43        const_eval::try_destructure_mir_constant_for_user_output;
44    providers.valtree_to_const_val =
45        |tcx, cv| const_eval::valtree_to_const_value(tcx, ty::TypingEnv::fully_monomorphized(), cv);
46    providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
47        util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
48    };
49    providers.hooks.validate_scalar_in_layout =
50        |tcx, scalar, layout| util::validate_scalar_in_layout(tcx, scalar, layout);
51}
52
53/// `rustc_driver::main` installs a handler that will set this to `true` if
54/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
55/// This static lives here because it is only read by the interpreter.
56pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);