Skip to content

Commit 77174d3

Browse files
committed
Turn const_caller_location from a query to a hook
1 parent 045f158 commit 77174d3

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

compiler/rustc_const_eval/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn provide(providers: &mut Providers) {
4949
const_eval::provide(providers);
5050
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
5151
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
52-
providers.const_caller_location = util::caller_location::const_caller_location_provider;
52+
providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
5353
providers.eval_to_valtree = |tcx, param_env_and_value| {
5454
let (param_env, raw) = param_env_and_value.into_parts();
5555
const_eval::eval_to_valtree(tcx, param_env, raw)

compiler/rustc_const_eval/src/util/caller_location.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_hir::LangItem;
22
use rustc_middle::mir;
3+
use rustc_middle::query::TyCtxtAt;
4+
use rustc_middle::ty;
35
use rustc_middle::ty::layout::LayoutOf;
4-
use rustc_middle::ty::{self, TyCtxt};
5-
use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
6+
use rustc_span::symbol::Symbol;
67
use rustc_type_ir::Mutability;
78

89
use crate::const_eval::{mk_eval_cx, CanAccessStatics, CompileTimeEvalContext};
@@ -49,11 +50,13 @@ fn alloc_caller_location<'mir, 'tcx>(
4950
}
5051

5152
pub(crate) fn const_caller_location_provider(
52-
tcx: TyCtxt<'_>,
53-
(file, line, col): (Symbol, u32, u32),
53+
tcx: TyCtxtAt<'_>,
54+
file: Symbol,
55+
line: u32,
56+
col: u32,
5457
) -> mir::ConstValue<'_> {
5558
trace!("const_caller_location: {}:{}:{}", file, line, col);
56-
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), CanAccessStatics::No);
59+
let mut ecx = mk_eval_cx(tcx.tcx, tcx.span, ty::ParamEnv::reveal_all(), CanAccessStatics::No);
5760

5861
let loc_place = alloc_caller_location(&mut ecx, file, line, col);
5962
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {

compiler/rustc_middle/src/hooks/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ declare_hooks! {
6767
/// Tries to destructure an `mir::Const` ADT or array into its variant index
6868
/// and its field values. This should only be used for pretty printing.
6969
hook try_destructure_mir_constant_for_diagnostics(val: mir::ConstValue<'tcx>, ty: Ty<'tcx>) -> Option<mir::DestructuredConstant<'tcx>>;
70+
71+
/// Getting a &core::panic::Location referring to a span.
72+
hook const_caller_location(file: rustc_span::Symbol, line: u32, col: u32) -> mir::ConstValue<'tcx>;
7073
}

compiler/rustc_middle/src/mir/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@ impl<'tcx> TyCtxt<'tcx> {
590590
pub fn span_as_caller_location(self, span: Span) -> ConstValue<'tcx> {
591591
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
592592
let caller = self.sess.source_map().lookup_char_pos(topmost.lo());
593-
self.const_caller_location((
593+
self.const_caller_location(
594594
rustc_span::symbol::Symbol::intern(
595595
&caller.file.name.for_codegen(&self.sess).to_string_lossy(),
596596
),
597597
caller.line as u32,
598598
caller.col_display as u32 + 1,
599-
))
599+
)
600600
}
601601
}

compiler/rustc_middle/src/query/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,6 @@ rustc_queries! {
11011101
desc { "destructuring type level constant"}
11021102
}
11031103

1104-
query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> mir::ConstValue<'tcx> {
1105-
desc { "getting a &core::panic::Location referring to a span" }
1106-
}
1107-
11081104
// FIXME get rid of this with valtrees
11091105
query lit_to_const(
11101106
key: LitToConstInput<'tcx>

0 commit comments

Comments
 (0)