Skip to main content

rustc_const_eval/
lib.rs

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