Rollup merge of #136464 - nnethercote:rm-TyCtxtAt-for-hooks, r=oli-obk
Remove hook calling via `TyCtxtAt`. All hooks receive a `TyCtxtAt` argument. Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook. However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.) This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries. r? `@oli-obk`
This commit is contained in:
commit
5bd0f32378
8 changed files with 21 additions and 38 deletions
|
@ -1,7 +1,7 @@
|
|||
// Not in interpret to make sure we do not use private implementation details
|
||||
|
||||
use rustc_abi::VariantIdx;
|
||||
use rustc_middle::query::{Key, TyCtxtAt};
|
||||
use rustc_middle::query::Key;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::{bug, mir};
|
||||
|
@ -35,16 +35,17 @@ pub(crate) type ValTreeCreationResult<'tcx> = Result<ty::ValTree<'tcx>, ValTreeC
|
|||
|
||||
#[instrument(skip(tcx), level = "debug")]
|
||||
pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
|
||||
tcx: TyCtxtAt<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
val: mir::ConstValue<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Option<mir::DestructuredConstant<'tcx>> {
|
||||
let typing_env = ty::TypingEnv::fully_monomorphized();
|
||||
let (ecx, op) = mk_eval_cx_for_const_val(tcx, typing_env, val, ty)?;
|
||||
// FIXME: use a proper span here?
|
||||
let (ecx, op) = mk_eval_cx_for_const_val(tcx.at(rustc_span::DUMMY_SP), typing_env, val, ty)?;
|
||||
|
||||
// We go to `usize` as we cannot allocate anything bigger anyway.
|
||||
let (field_count, variant, down) = match ty.kind() {
|
||||
ty::Array(_, len) => (len.try_to_target_usize(tcx.tcx)? as usize, None, op),
|
||||
ty::Array(_, len) => (len.try_to_target_usize(tcx)? as usize, None, op),
|
||||
ty::Adt(def, _) if def.variants().is_empty() => {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use rustc_hir::LangItem;
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_middle::{bug, mir};
|
||||
use rustc_span::Symbol;
|
||||
use tracing::trace;
|
||||
|
@ -48,15 +47,15 @@ fn alloc_caller_location<'tcx>(
|
|||
}
|
||||
|
||||
pub(crate) fn const_caller_location_provider(
|
||||
tcx: TyCtxtAt<'_>,
|
||||
tcx: TyCtxt<'_>,
|
||||
file: Symbol,
|
||||
line: u32,
|
||||
col: u32,
|
||||
) -> mir::ConstValue<'_> {
|
||||
trace!("const_caller_location: {}:{}:{}", file, line, col);
|
||||
let mut ecx = mk_eval_cx_to_read_const_val(
|
||||
tcx.tcx,
|
||||
tcx.span,
|
||||
tcx,
|
||||
rustc_span::DUMMY_SP, // FIXME: use a proper span here?
|
||||
ty::TypingEnv::fully_monomorphized(),
|
||||
CanAccessMutGlobal::No,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue