1
Fork 0

Turn const_caller_location from a query to a hook

This commit is contained in:
Oli Scherer 2023-10-30 09:58:54 +00:00
parent 045f158d7b
commit 77174d3f29
5 changed files with 14 additions and 12 deletions

View file

@ -49,7 +49,7 @@ 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.const_caller_location = util::caller_location::const_caller_location_provider;
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)

View file

@ -1,8 +1,9 @@
use rustc_hir::LangItem;
use rustc_middle::mir;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
use rustc_span::symbol::Symbol;
use rustc_type_ir::Mutability;
use crate::const_eval::{mk_eval_cx, CanAccessStatics, CompileTimeEvalContext};
@ -49,11 +50,13 @@ fn alloc_caller_location<'mir, 'tcx>(
}
pub(crate) fn const_caller_location_provider(
tcx: TyCtxt<'_>,
(file, line, col): (Symbol, u32, u32),
tcx: TyCtxtAt<'_>,
file: Symbol,
line: u32,
col: u32,
) -> mir::ConstValue<'_> {
trace!("const_caller_location: {}:{}:{}", file, line, col);
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), CanAccessStatics::No);
let mut ecx = mk_eval_cx(tcx.tcx, tcx.span, ty::ParamEnv::reveal_all(), CanAccessStatics::No);
let loc_place = alloc_caller_location(&mut ecx, file, line, col);
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {