Skip to content

Commit 91481e3

Browse files
committed
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 8cf9eea commit 91481e3

24 files changed

+61
-64
lines changed

clippy_lints/src/derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
437437
walk_expr(self, expr)
438438
}
439439

440-
fn nested_visit_map(&mut self) -> Self::Map {
441-
self.cx.tcx.hir()
440+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
441+
self.cx.tcx
442442
}
443443
}
444444

clippy_lints/src/doc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,8 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> {
10791079
// Panics in const blocks will cause compilation to fail.
10801080
fn visit_anon_const(&mut self, _: &'tcx AnonConst) {}
10811081

1082-
fn nested_visit_map(&mut self) -> Self::Map {
1083-
self.cx.tcx.hir()
1082+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
1083+
self.cx.tcx
10841084
}
10851085
}
10861086

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
241241
}
242242
}
243243

244-
fn nested_visit_map(&mut self) -> Self::Map {
245-
self.cx.tcx.hir()
244+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
245+
self.cx.tcx
246246
}
247247
}
248248

clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl<'tcx> Visitor<'tcx> for SelfFinder<'_, 'tcx> {
134134
type Result = ControlFlow<()>;
135135
type NestedFilter = OnlyBodies;
136136

137-
fn nested_visit_map(&mut self) -> Self::Map {
138-
self.cx.tcx.hir()
137+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
138+
self.cx.tcx
139139
}
140140

141141
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) -> Self::Result {

clippy_lints/src/implicit_hasher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'_, '_, 'tcx> {
363363
walk_expr(self, e);
364364
}
365365

366-
fn nested_visit_map(&mut self) -> Self::Map {
367-
self.cx.tcx.hir()
366+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
367+
self.cx.tcx
368368
}
369369
}

clippy_lints/src/index_refutable_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ struct SliceIndexLintingVisitor<'a, 'tcx> {
223223
impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
224224
type NestedFilter = nested_filter::OnlyBodies;
225225

226-
fn nested_visit_map(&mut self) -> Self::Map {
227-
self.cx.tcx.hir()
226+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
227+
self.cx.tcx
228228
}
229229

230230
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {

clippy_lints/src/lifetimes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use rustc_hir::{
1919
WherePredicateKind, lang_items,
2020
};
2121
use rustc_lint::{LateContext, LateLintPass, LintContext};
22-
use rustc_middle::hir::map::Map;
2322
use rustc_middle::hir::nested_filter as middle_nested_filter;
23+
use rustc_middle::ty::TyCtxt;
2424
use rustc_session::impl_lint_pass;
2525
use rustc_span::Span;
2626
use rustc_span::def_id::LocalDefId;
@@ -582,7 +582,7 @@ impl<'tcx, F> Visitor<'tcx> for LifetimeChecker<'_, 'tcx, F>
582582
where
583583
F: NestedFilter<'tcx>,
584584
{
585-
type Map = Map<'tcx>;
585+
type MaybeTyCtxt = TyCtxt<'tcx>;
586586
type NestedFilter = F;
587587

588588
// for lifetimes as parameters of generics
@@ -628,8 +628,8 @@ where
628628
self.lifetime_elision_impossible = false;
629629
}
630630

631-
fn nested_visit_map(&mut self) -> Self::Map {
632-
self.cx.tcx.hir()
631+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
632+
self.cx.tcx
633633
}
634634
}
635635

clippy_lints/src/loops/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ impl<'tcx> Visitor<'tcx> for InitializeVisitor<'_, 'tcx> {
240240
}
241241
}
242242

243-
fn nested_visit_map(&mut self) -> Self::Map {
244-
self.cx.tcx.hir()
243+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
244+
self.cx.tcx
245245
}
246246
}
247247

clippy_lints/src/loops/while_let_on_iterator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
245245
impl<'tcx> Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> {
246246
type NestedFilter = OnlyBodies;
247247
type Result = ControlFlow<()>;
248-
fn nested_visit_map(&mut self) -> Self::Map {
249-
self.cx.tcx.hir()
248+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
249+
self.cx.tcx
250250
}
251251

252252
fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
@@ -288,8 +288,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
288288
}
289289
impl<'tcx> Visitor<'tcx> for NestedLoopVisitor<'_, '_, 'tcx> {
290290
type NestedFilter = OnlyBodies;
291-
fn nested_visit_map(&mut self) -> Self::Map {
292-
self.cx.tcx.hir()
291+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
292+
self.cx.tcx
293293
}
294294

295295
fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {

clippy_lints/src/methods/needless_collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ impl<'tcx> Visitor<'tcx> for UsedCountVisitor<'_, 'tcx> {
456456
}
457457
}
458458

459-
fn nested_visit_map(&mut self) -> Self::Map {
460-
self.cx.tcx.hir()
459+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
460+
self.cx.tcx
461461
}
462462
}
463463

0 commit comments

Comments
 (0)