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