rustc_const_eval/
lib.rs

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