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

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ impl<'tcx> Visitor<'tcx> for UnwrapVisitor<'_, 'tcx> {
143143
walk_path(self, path);
144144
}
145145

146-
fn nested_visit_map(&mut self) -> Self::Map {
147-
self.cx.tcx.hir()
146+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
147+
self.cx.tcx
148148
}
149149
}
150150

@@ -174,7 +174,7 @@ impl<'tcx> Visitor<'tcx> for ReferenceVisitor<'_, 'tcx> {
174174
rustc_hir::intravisit::walk_expr(self, expr)
175175
}
176176

177-
fn nested_visit_map(&mut self) -> Self::Map {
178-
self.cx.tcx.hir()
177+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
178+
self.cx.tcx
179179
}
180180
}

clippy_lints/src/methods/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ struct CloneOrCopyVisitor<'cx, 'tcx> {
8989
impl<'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'_, 'tcx> {
9090
type NestedFilter = nested_filter::OnlyBodies;
9191

92-
fn nested_visit_map(&mut self) -> Self::Map {
93-
self.cx.tcx.hir()
92+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
93+
self.cx.tcx
9494
}
9595

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

clippy_lints/src/mutable_debug_assertion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'tcx> Visitor<'tcx> for MutArgVisitor<'_, 'tcx> {
119119
walk_expr(self, expr);
120120
}
121121

122-
fn nested_visit_map(&mut self) -> Self::Map {
123-
self.cx.tcx.hir()
122+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
123+
self.cx.tcx
124124
}
125125
}

clippy_lints/src/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[
583583
}
584584
impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> {
585585
type NestedFilter = nested_filter::OnlyBodies;
586-
fn nested_visit_map(&mut self) -> Self::Map {
587-
self.cx.tcx.hir()
586+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
587+
self.cx.tcx
588588
}
589589

590590
fn visit_anon_const(&mut self, _: &'tcx AnonConst) {}

clippy_lints/src/redundant_closure_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
241241
hir_visit::walk_expr(self, expr);
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
let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 };

clippy_lints/src/unconditional_recursion.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_hir::intravisit::{FnKind, Visitor, walk_body, walk_expr};
99
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind};
1010
use rustc_hir_analysis::lower_ty;
1111
use rustc_lint::{LateContext, LateLintPass};
12-
use rustc_middle::hir::map::Map;
1312
use rustc_middle::hir::nested_filter;
1413
use rustc_middle::ty::{self, AssocKind, Ty, TyCtxt};
1514
use rustc_session::impl_lint_pass;
@@ -275,7 +274,6 @@ fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>,
275274

276275
struct CheckCalls<'a, 'tcx> {
277276
cx: &'a LateContext<'tcx>,
278-
map: Map<'tcx>,
279277
implemented_ty_id: DefId,
280278
method_span: Span,
281279
}
@@ -287,8 +285,8 @@ where
287285
type NestedFilter = nested_filter::OnlyBodies;
288286
type Result = ControlFlow<()>;
289287

290-
fn nested_visit_map(&mut self) -> Self::Map {
291-
self.map
288+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
289+
self.cx.tcx
292290
}
293291

294292
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) -> ControlFlow<()> {
@@ -380,7 +378,6 @@ impl UnconditionalRecursion {
380378
{
381379
let mut c = CheckCalls {
382380
cx,
383-
map: cx.tcx.hir(),
384381
implemented_ty_id,
385382
method_span,
386383
};

clippy_lints/src/unused_async.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ impl<'tcx> Visitor<'tcx> for AsyncFnVisitor<'_, 'tcx> {
101101
}
102102
}
103103

104-
fn nested_visit_map(&mut self) -> Self::Map {
105-
self.cx.tcx.hir()
104+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
105+
self.cx.tcx
106106
}
107107
}
108108

clippy_lints/src/unused_peekable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
112112
type NestedFilter = OnlyBodies;
113113
type Result = ControlFlow<()>;
114114

115-
fn nested_visit_map(&mut self) -> Self::Map {
116-
self.cx.tcx.hir()
115+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
116+
self.cx.tcx
117117
}
118118

119119
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> {

clippy_lints/src/unwrap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ impl<'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'_, 'tcx> {
374374
}
375375
}
376376

377-
fn nested_visit_map(&mut self) -> Self::Map {
378-
self.cx.tcx.hir()
377+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
378+
self.cx.tcx
379379
}
380380
}
381381

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'tcx> Visitor<'tcx> for LintCollector<'_, 'tcx> {
277277
}
278278
}
279279

280-
fn nested_visit_map(&mut self) -> Self::Map {
280+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
281281
self.cx.tcx.hir()
282282
}
283283
}

clippy_lints/src/zombie_processes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> {
249249
walk_expr(self, ex)
250250
}
251251

252-
fn nested_visit_map(&mut self) -> Self::Map {
253-
self.cx.tcx.hir()
252+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
253+
self.cx.tcx
254254
}
255255
}
256256

clippy_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ impl<'tcx> Visitor<'tcx> for ContainsName<'_, 'tcx> {
13701370
}
13711371
}
13721372

1373-
fn nested_visit_map(&mut self) -> Self::Map {
1374-
self.cx.tcx.hir()
1373+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
1374+
self.cx.tcx
13751375
}
13761376
}
13771377

clippy_utils/src/usage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl<'tcx> Visitor<'tcx> for BindingUsageFinder<'_, 'tcx> {
133133
ControlFlow::Continue(())
134134
}
135135

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

clippy_utils/src/visitors.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ pub fn for_each_expr<'tcx, B, C: Continue>(
154154
type NestedFilter = nested_filter::OnlyBodies;
155155
type Result = ControlFlow<B>;
156156

157-
fn nested_visit_map(&mut self) -> Self::Map {
158-
self.tcx.hir()
157+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
158+
self.tcx
159159
}
160160

161161
fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) -> Self::Result {
@@ -412,8 +412,8 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
412412
type NestedFilter = nested_filter::OnlyBodies;
413413
type Result = ControlFlow<()>;
414414

415-
fn nested_visit_map(&mut self) -> Self::Map {
416-
self.cx.tcx.hir()
415+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
416+
self.cx.tcx
417417
}
418418
fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
419419
match e.kind {
@@ -477,8 +477,8 @@ pub fn contains_unsafe_block<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>)
477477
impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> {
478478
type Result = ControlFlow<()>;
479479
type NestedFilter = nested_filter::OnlyBodies;
480-
fn nested_visit_map(&mut self) -> Self::Map {
481-
self.cx.tcx.hir()
480+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
481+
self.cx.tcx
482482
}
483483

484484
fn visit_block(&mut self, b: &'tcx Block<'_>) -> Self::Result {
@@ -544,8 +544,8 @@ pub fn for_each_local_use_after_expr<'tcx, B>(
544544
}
545545
impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B>, B> Visitor<'tcx> for V<'_, 'tcx, F, B> {
546546
type NestedFilter = nested_filter::OnlyBodies;
547-
fn nested_visit_map(&mut self) -> Self::Map {
548-
self.cx.tcx.hir()
547+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
548+
self.cx.tcx
549549
}
550550

551551
fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {
@@ -729,8 +729,8 @@ pub fn for_each_local_assignment<'tcx, B>(
729729
}
730730
impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B>, B> Visitor<'tcx> for V<'_, 'tcx, F, B> {
731731
type NestedFilter = nested_filter::OnlyBodies;
732-
fn nested_visit_map(&mut self) -> Self::Map {
733-
self.cx.tcx.hir()
732+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
733+
self.cx.tcx
734734
}
735735

736736
fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {

0 commit comments

Comments
 (0)