rustc_const_eval/
lib.rs

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