rustc_const_eval/
lib.rs

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