rust/compiler/rustc_const_eval/src/lib.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
2.1 KiB
Rust
Raw Normal View History

2015-08-18 17:59:21 -04:00
/*!
2020-02-21 11:03:21 -03:00
Rust MIR: a lowered representation of Rust.
2015-08-18 17:59:21 -04:00
*/
2023-11-13 07:39:17 -05:00
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
2023-11-13 07:39:17 -05:00
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![feature(assert_matches)]
2016-02-11 18:05:28 +02:00
#![feature(box_patterns)]
#![feature(decl_macro)]
#![feature(let_chains)]
#![feature(slice_ptr_get)]
#![feature(never_type)]
#![feature(trait_alias)]
#![feature(try_blocks)]
2022-05-29 01:19:52 -07:00
#![feature(yeet_expr)]
2022-12-21 16:32:16 +00:00
#![feature(if_let_guard)]
2015-08-18 17:59:21 -04:00
#[macro_use]
2020-08-13 23:05:01 -07:00
extern crate tracing;
#[macro_use]
2020-03-29 16:41:09 +02:00
extern crate rustc_middle;
2015-08-18 17:59:21 -04:00
pub mod const_eval;
2022-06-28 21:26:05 -07:00
mod errors;
2017-12-14 11:36:28 +01:00
pub mod interpret;
pub mod transform;
pub mod util;
pub use errors::ReportErrorExt;
use rustc_middle::{ty, util::Providers};
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn provide(providers: &mut Providers) {
const_eval::provide(providers);
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
providers.eval_static_initializer_raw = |tcx, def_id| {
assert!(tcx.is_static(def_id.to_def_id()));
let instance = ty::Instance::mono(tcx, def_id.to_def_id());
let gid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None };
let param_env = ty::ParamEnv::reveal_all();
Ok(tcx.eval_to_allocation_raw(param_env.and(gid))?.alloc_id)
};
providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
providers.eval_to_valtree = |tcx, param_env_and_value| {
let (param_env, raw) = param_env_and_value.into_parts();
const_eval::eval_to_valtree(tcx, param_env, raw)
};
2023-10-31 17:38:41 +00:00
providers.hooks.try_destructure_mir_constant_for_user_output =
const_eval::try_destructure_mir_constant_for_user_output;
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
};
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
};
}