Add reference to 'ThirBuildCx' for PatCtxt

This commit is contained in:
human9000
2026-03-16 17:48:41 +05:00
parent 8a57f3d844
commit 0626f33aad
5 changed files with 20 additions and 14 deletions
@@ -83,6 +83,7 @@ fn mirror_stmts(
}
Some(_) | None => local.span,
};
let initializer = local.init.map(|init| self.mirror_expr(init));
let stmt = Stmt {
kind: StmtKind::Let {
remainder_scope,
@@ -91,7 +92,7 @@ fn mirror_stmts(
data: region::ScopeData::Node,
},
pattern,
initializer: local.init.map(|init| self.mirror_expr(init)),
initializer,
else_block,
hir_id: local.hir_id,
span,
+1 -1
View File
@@ -876,7 +876,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
};
let indices = self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
let mut expr = None::<ExprKind<'tcx>>;
let mut expr = None::<ExprKind<'_>>;
for &(container, variant, field) in indices.iter() {
let next = mk_call(&mut self.thir, container, variant, field);
+7 -6
View File
@@ -13,14 +13,14 @@
use rustc_middle::ty::{self, TyCtxt};
/// Query implementation for [`TyCtxt::thir_body`].
pub(crate) fn thir_body(
tcx: TyCtxt<'_>,
pub(crate) fn thir_body<'tcx>(
tcx: TyCtxt<'tcx>,
owner_def: LocalDefId,
) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> {
) -> Result<(&'tcx Steal<Thir<'tcx>>, ExprId), ErrorGuaranteed> {
debug_assert!(!tcx.is_type_const(owner_def.to_def_id()), "thir_body queried for type_const");
let body = tcx.hir_body_owned_by(owner_def);
let mut cx = ThirBuildCx::new(tcx, owner_def);
let mut cx: ThirBuildCx<'tcx> = ThirBuildCx::new(tcx, owner_def);
if let Some(reported) = cx.typeck_results.tainted_by_errors {
return Err(reported);
}
@@ -50,7 +50,7 @@ pub(crate) fn thir_body(
}
/// Context for lowering HIR to THIR for a single function body (or other kind of body).
struct ThirBuildCx<'tcx> {
pub(crate) struct ThirBuildCx<'tcx> {
tcx: TyCtxt<'tcx>,
/// The THIR data that this context is building.
thir: Thir<'tcx>,
@@ -118,6 +118,7 @@ fn pattern_from_hir_with_annotation(
let_stmt_type: Option<&hir::Ty<'tcx>>,
) -> Box<Pat<'tcx>> {
crate::thir::pattern::pat_from_hir(
self,
self.tcx,
self.typing_env,
self.typeck_results,
@@ -201,7 +202,7 @@ fn explicit_params(
fn_sig.inputs()[index]
};
let pat = self.pattern_from_hir(param.pat);
let pat: Box<Pat<'tcx>> = self.pattern_from_hir(param.pat);
Param { pat: Some(pat), ty, ty_span, self_kind, hir_id: Some(param.hir_id) }
})
}
@@ -25,7 +25,7 @@
PointerPattern, TypeNotPartialEq, TypeNotStructural, UnionPattern, UnsizedPattern,
};
impl<'tcx> PatCtxt<'tcx> {
impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
/// Converts a constant to a pattern (if possible).
/// This means aggregate values (like structs and enums) are converted
/// to a pattern that matches the value (as if you'd compared via structural equality).
@@ -61,7 +61,7 @@ struct ConstToPat<'tcx> {
}
impl<'tcx> ConstToPat<'tcx> {
fn new(pat_ctxt: &PatCtxt<'tcx>, id: hir::HirId, span: Span, c: ty::Const<'tcx>) -> Self {
fn new(pat_ctxt: &PatCtxt<'tcx, '_>, id: hir::HirId, span: Span, c: ty::Const<'tcx>) -> Self {
trace!(?pat_ctxt.typeck_results.hir_owner);
ConstToPat { tcx: pat_ctxt.tcx, typing_env: pat_ctxt.typing_env, span, id, c }
}
@@ -30,9 +30,11 @@
pub(crate) use self::check_match::check_match;
use self::migration::PatMigration;
use crate::errors::*;
use crate::thir::cx::ThirBuildCx;
/// Context for lowering HIR patterns to THIR patterns.
struct PatCtxt<'tcx> {
struct PatCtxt<'tcx, 'ptcx> {
upper: &'ptcx mut ThirBuildCx<'tcx>,
tcx: TyCtxt<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
typeck_results: &'tcx ty::TypeckResults<'tcx>,
@@ -41,8 +43,9 @@ struct PatCtxt<'tcx> {
rust_2024_migration: Option<PatMigration<'tcx>>,
}
#[instrument(level = "debug", skip(tcx, typing_env, typeck_results), ret)]
pub(super) fn pat_from_hir<'tcx>(
#[instrument(level = "debug", skip(upper, tcx, typing_env, typeck_results), ret)]
pub(super) fn pat_from_hir<'tcx, 'ptcx>(
upper: &'ptcx mut ThirBuildCx<'tcx>,
tcx: TyCtxt<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
typeck_results: &'tcx ty::TypeckResults<'tcx>,
@@ -51,6 +54,7 @@ pub(super) fn pat_from_hir<'tcx>(
let_stmt_type: Option<&hir::Ty<'tcx>>,
) -> Box<Pat<'tcx>> {
let mut pcx = PatCtxt {
upper,
tcx,
typing_env,
typeck_results,
@@ -87,7 +91,7 @@ pub(super) fn pat_from_hir<'tcx>(
thir_pat
}
impl<'tcx> PatCtxt<'tcx> {
impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
fn lower_pattern(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
let adjustments: &[PatAdjustment<'tcx>] =
self.typeck_results.pat_adjustments().get(pat.hir_id).map_or(&[], |v| &**v);