Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 590b39e

Browse files
committedFeb 16, 2025·
Overhaul the intravisit::Map trait.
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
1 parent 1e498bc commit 590b39e

File tree

59 files changed

+208
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+208
-210
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
348348
expr: Option<&'hir hir::Expr<'hir>>,
349349
pat: Option<&'hir hir::Pat<'hir>>,
350350
parent_pat: Option<&'hir hir::Pat<'hir>>,
351-
hir: rustc_middle::hir::map::Map<'hir>,
351+
tcx: TyCtxt<'hir>,
352352
}
353353
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
354354
type NestedFilter = OnlyBodies;
355355

356-
fn nested_visit_map(&mut self) -> Self::Map {
357-
self.hir
356+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
357+
self.tcx
358358
}
359359

360360
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
@@ -396,7 +396,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
396396
expr: None,
397397
pat: None,
398398
parent_pat: None,
399-
hir,
399+
tcx: self.infcx.tcx,
400400
};
401401
finder.visit_expr(expr);
402402
if let Some(span) = span
@@ -2455,7 +2455,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24552455
let body_expr = tcx.hir_body(body_id).value;
24562456

24572457
struct ClosureFinder<'hir> {
2458-
hir: rustc_middle::hir::map::Map<'hir>,
2458+
tcx: TyCtxt<'hir>,
24592459
borrow_span: Span,
24602460
res: Option<(&'hir hir::Expr<'hir>, &'hir hir::Closure<'hir>)>,
24612461
/// The path expression with the `borrow_span` span
@@ -2464,8 +2464,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24642464
impl<'hir> Visitor<'hir> for ClosureFinder<'hir> {
24652465
type NestedFilter = OnlyBodies;
24662466

2467-
fn nested_visit_map(&mut self) -> Self::Map {
2468-
self.hir
2467+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
2468+
self.tcx
24692469
}
24702470

24712471
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
@@ -2491,7 +2491,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24912491

24922492
// Find the closure that most tightly wraps `capture_kind_span`
24932493
let mut finder =
2494-
ClosureFinder { hir, borrow_span: capture_kind_span, res: None, error_path: None };
2494+
ClosureFinder { tcx, borrow_span: capture_kind_span, res: None, error_path: None };
24952495
finder.visit_expr(body_expr);
24962496
let Some((closure_expr, closure)) = finder.res else { return };
24972497

‎compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
256256

257257
impl<'hir> rustc_hir::intravisit::Visitor<'hir> for FindLetExpr<'hir> {
258258
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
259-
fn nested_visit_map(&mut self) -> Self::Map {
260-
self.tcx.hir()
259+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
260+
self.tcx
261261
}
262262
fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) {
263263
if let hir::ExprKind::If(cond, _conseq, _alt)

0 commit comments

Comments
 (0)
Please sign in to comment.