1
Fork 0

Move methods from Map to TyCtxt, part 2.

Continuing the work started in #136466.

Every method gains a `hir_` prefix, though for the ones that already
have a `par_` or `try_par_` prefix I added the `hir_` after that.
This commit is contained in:
Nicholas Nethercote 2025-02-17 14:17:57 +11:00
parent ce36a966c7
commit fd7b4bf4e1
108 changed files with 314 additions and 346 deletions

View file

@ -465,11 +465,10 @@ fn construct_fn<'tcx>(
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);
// Figure out what primary body this item has.
let body = tcx.hir().body_owned_by(fn_def);
let body = tcx.hir_body_owned_by(fn_def);
let span_with_body = tcx.hir().span_with_body(fn_id);
let return_ty_span = tcx
.hir()
.fn_decl_by_hir_id(fn_id)
.hir_fn_decl_by_hir_id(fn_id)
.unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def))
.output
.span();
@ -758,7 +757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
check_overflow |= tcx.sess.overflow_checks();
// Constants always need overflow checks.
check_overflow |= matches!(
tcx.hir().body_owner_kind(def),
tcx.hir_body_owner_kind(def),
hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_)
);

View file

@ -927,7 +927,7 @@ impl UnsafeOpKind {
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
{
true
} else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
} else if let Some(sig) = tcx.hir_fn_sig_by_hir_id(*id)
&& matches!(sig.header.safety, hir::HeaderSafety::Normal(hir::Safety::Unsafe))
{
true
@ -1145,7 +1145,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
let thir = &thir.steal();
let hir_id = tcx.local_def_id_to_hir_id(def);
let safety_context = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
let safety_context = tcx.hir_fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
match fn_sig.header.safety {
// We typeck the body as safe, but otherwise treat it as unsafe everywhere else.
// Call sites to other SafeTargetFeatures functions are checked explicitly and don't need

View file

@ -22,8 +22,7 @@ pub(crate) fn thir_body(
tcx: TyCtxt<'_>,
owner_def: LocalDefId,
) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> {
let hir = tcx.hir();
let body = hir.body_owned_by(owner_def);
let body = tcx.hir_body_owned_by(owner_def);
let mut cx = ThirBuildCx::new(tcx, owner_def);
if let Some(reported) = cx.typeck_results.tainted_by_errors {
return Err(reported);
@ -31,7 +30,7 @@ pub(crate) fn thir_body(
let expr = cx.mirror_expr(body.value);
let owner_id = tcx.local_def_id_to_hir_id(owner_def);
if let Some(fn_decl) = hir.fn_decl_by_hir_id(owner_id) {
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(owner_id) {
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
let explicit_params = cx.explicit_params(owner_id, fn_decl, &body);
cx.thir.params = closure_env_param.into_iter().chain(explicit_params).collect();
@ -77,7 +76,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
let hir = tcx.hir();
let hir_id = tcx.local_def_id_to_hir_id(def);
let body_type = if hir.body_owner_kind(def).is_fn_or_closure() {
let body_type = if tcx.hir_body_owner_kind(def).is_fn_or_closure() {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
BodyTy::Fn(typeck_results.liberated_fn_sigs()[hir_id])

View file

@ -148,7 +148,7 @@ impl<'tcx> ConstToPat<'tcx> {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Param(param_ty) = ty.kind()
{
let def_id = self.tcx.hir().enclosing_body_owner(self.id);
let def_id = self.tcx.hir_enclosing_body_owner(self.id);
let generics = self.tcx.generics_of(def_id);
let param = generics.type_param(*param_ty, self.tcx);
let span = self.tcx.def_span(param.def_id);