Skip to content

Commit be6d693

Browse files
committed
Fix Visitor::NestedFilter in Clippy
1 parent 1a6312e commit be6d693

Some content is hidden

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

50 files changed

+126
-419
lines changed

src/tools/clippy/clippy_lints/src/assign_ops.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use clippy_utils::{eq_expr_value, trait_ref_of_method};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir as hir;
9-
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
9+
use rustc_hir::intravisit::{walk_expr, Visitor};
1010
use rustc_lint::{LateContext, LateLintPass};
11-
use rustc_middle::hir::map::Map;
1211
use rustc_session::{declare_lint_pass, declare_tool_lint};
1312

1413
declare_clippy_lint! {
@@ -220,16 +219,11 @@ struct ExprVisitor<'a, 'tcx> {
220219
}
221220

222221
impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
223-
type Map = Map<'tcx>;
224-
225222
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
226223
if eq_expr_value(self.cx, self.assignee, expr) {
227224
self.counter += 1;
228225
}
229226

230227
walk_expr(self, expr);
231228
}
232-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
233-
NestedVisitorMap::None
234-
}
235229
}

src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use clippy_utils::ty::implements_trait;
55
use clippy_utils::{differing_macro_contexts, get_parent_expr};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
8+
use rustc_hir::intravisit::{walk_expr, Visitor};
99
use rustc_hir::{BlockCheckMode, Expr, ExprKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
11-
use rustc_middle::hir::map::Map;
1211
use rustc_middle::lint::in_external_macro;
1312
use rustc_session::{declare_lint_pass, declare_tool_lint};
1413
use rustc_span::sym;
@@ -55,8 +54,6 @@ struct ExVisitor<'a, 'tcx> {
5554
}
5655

5756
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
58-
type Map = Map<'tcx>;
59-
6057
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
6158
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
6259
// do not lint if the closure is called using an iterator (see #1141)
@@ -82,9 +79,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
8279
}
8380
walk_expr(self, expr);
8481
}
85-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
86-
NestedVisitorMap::None
87-
}
8882
}
8983

9084
const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";

src/tools/clippy/clippy_lints/src/booleans.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
55
use if_chain::if_chain;
66
use rustc_ast::ast::LitKind;
77
use rustc_errors::Applicability;
8-
use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor};
8+
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
99
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp};
1010
use rustc_lint::{LateContext, LateLintPass};
11-
use rustc_middle::hir::map::Map;
1211
use rustc_session::{declare_lint_pass, declare_tool_lint};
1312
use rustc_span::source_map::Span;
1413
use rustc_span::sym;
@@ -452,8 +451,6 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
452451
}
453452

454453
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
455-
type Map = Map<'tcx>;
456-
457454
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
458455
if !e.span.from_expansion() {
459456
match &e.kind {
@@ -470,9 +467,6 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
470467
}
471468
walk_expr(self, e);
472469
}
473-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
474-
NestedVisitorMap::None
475-
}
476470
}
477471

478472
fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
@@ -485,8 +479,6 @@ struct NotSimplificationVisitor<'a, 'tcx> {
485479
}
486480

487481
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
488-
type Map = Map<'tcx>;
489-
490482
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
491483
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
492484
if let Some(suggestion) = simplify_not(self.cx, inner) {
@@ -504,7 +496,4 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
504496

505497
walk_expr(self, expr);
506498
}
507-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
508-
NestedVisitorMap::None
509-
}
510499
}

src/tools/clippy/clippy_lints/src/cognitive_complexity.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::is_type_diagnostic_item;
66
use clippy_utils::LimitStack;
77
use rustc_ast::ast::Attribute;
8-
use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor};
8+
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
99
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
11-
use rustc_middle::hir::map::Map;
1211
use rustc_session::{declare_tool_lint, impl_lint_pass};
1312
use rustc_span::source_map::Span;
1413
use rustc_span::{sym, BytePos};
@@ -149,8 +148,6 @@ struct CcHelper {
149148
}
150149

151150
impl<'tcx> Visitor<'tcx> for CcHelper {
152-
type Map = Map<'tcx>;
153-
154151
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
155152
walk_expr(self, e);
156153
match e.kind {
@@ -167,7 +164,4 @@ impl<'tcx> Visitor<'tcx> for CcHelper {
167164
_ => {},
168165
}
169166
}
170-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
171-
NestedVisitorMap::None
172-
}
173167
}

src/tools/clippy/clippy_lints/src/copies.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use clippy_utils::{
77
use if_chain::if_chain;
88
use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::{Applicability, DiagnosticBuilder};
10-
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
10+
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_hir::{Block, Expr, ExprKind, HirId};
1212
use rustc_lint::{LateContext, LateLintPass, LintContext};
13-
use rustc_middle::hir::map::Map;
13+
use rustc_middle::hir::nested_filter;
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
1515
use rustc_span::{source_map::Span, symbol::Symbol, BytePos};
1616
use std::borrow::Cow;
@@ -561,10 +561,10 @@ impl<'a, 'tcx> UsedValueFinderVisitor<'a, 'tcx> {
561561
}
562562

563563
impl<'a, 'tcx> Visitor<'tcx> for UsedValueFinderVisitor<'a, 'tcx> {
564-
type Map = Map<'tcx>;
564+
type NestedFilter = nested_filter::All;
565565

566-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
567-
NestedVisitorMap::All(self.cx.tcx.hir())
566+
fn nested_visit_map(&mut self) -> Self::Map {
567+
self.cx.tcx.hir()
568568
}
569569

570570
fn visit_local(&mut self, l: &'tcx rustc_hir::Local<'tcx>) {

src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use if_chain::if_chain;
55
use rustc_ast::ast::{LitFloatType, LitIntType, LitKind};
66
use rustc_errors::Applicability;
77
use rustc_hir::{
8-
intravisit::{walk_expr, walk_stmt, NestedVisitorMap, Visitor},
8+
intravisit::{walk_expr, walk_stmt, Visitor},
99
Body, Expr, ExprKind, HirId, Lit, Stmt, StmtKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::{
13-
hir::map::Map,
1413
lint::in_external_macro,
1514
ty::{self, FloatTy, IntTy, PolyFnSig, Ty},
1615
};
@@ -117,8 +116,6 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
117116
}
118117

119118
impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
120-
type Map = Map<'tcx>;
121-
122119
#[allow(clippy::too_many_lines)]
123120
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
124121
match &expr.kind {
@@ -209,10 +206,6 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
209206
walk_stmt(self, stmt);
210207
self.ty_bounds.pop();
211208
}
212-
213-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
214-
NestedVisitorMap::None
215-
}
216209
}
217210

218211
fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {

src/tools/clippy/clippy_lints/src/derive.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use clippy_utils::paths;
33
use clippy_utils::ty::{implements_trait, is_copy};
44
use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path};
55
use if_chain::if_chain;
6-
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
6+
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
77
use rustc_hir::{
88
BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, TraitRef, UnsafeSource, Unsafety,
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
11-
use rustc_middle::hir::map::Map;
11+
use rustc_middle::hir::nested_filter;
1212
use rustc_middle::ty::{self, Ty};
1313
use rustc_session::{declare_lint_pass, declare_tool_lint};
1414
use rustc_span::source_map::Span;
@@ -382,7 +382,7 @@ struct UnsafeVisitor<'a, 'tcx> {
382382
}
383383

384384
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
385-
type Map = Map<'tcx>;
385+
type NestedFilter = nested_filter::All;
386386

387387
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) {
388388
if self.has_unsafe {
@@ -414,7 +414,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
414414
walk_expr(self, expr);
415415
}
416416

417-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
418-
NestedVisitorMap::All(self.cx.tcx.hir())
417+
fn nested_visit_map(&mut self) -> Self::Map {
418+
self.cx.tcx.hir()
419419
}
420420
}

src/tools/clippy/clippy_lints/src/doc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc_data_structures::sync::Lrc;
1313
use rustc_errors::emitter::EmitterWriter;
1414
use rustc_errors::{Applicability, Handler, SuggestionStyle};
1515
use rustc_hir as hir;
16-
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
16+
use rustc_hir::intravisit::{self, Visitor};
1717
use rustc_hir::{AnonConst, Expr};
1818
use rustc_lint::{LateContext, LateLintPass};
19-
use rustc_middle::hir::map::Map;
19+
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::lint::in_external_macro;
2121
use rustc_middle::ty;
2222
use rustc_parse::maybe_new_parser_from_source_str;
@@ -799,7 +799,7 @@ struct FindPanicUnwrap<'a, 'tcx> {
799799
}
800800

801801
impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
802-
type Map = Map<'tcx>;
802+
type NestedFilter = nested_filter::OnlyBodies;
803803

804804
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
805805
if self.panic_span.is_some() {
@@ -834,7 +834,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
834834
// Panics in const blocks will cause compilation to fail.
835835
fn visit_anon_const(&mut self, _: &'tcx AnonConst) {}
836836

837-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
838-
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
837+
fn nested_visit_map(&mut self) -> Self::Map {
838+
self.cx.tcx.hir()
839839
}
840840
}

src/tools/clippy/clippy_lints/src/entry.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::fmt::Write;
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
hir_id::HirIdSet,
13-
intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor},
13+
intravisit::{walk_expr, Visitor},
1414
Block, Expr, ExprKind, Guard, HirId, Pat, Stmt, StmtKind, UnOp,
1515
};
1616
use rustc_lint::{LateContext, LateLintPass};
@@ -370,11 +370,6 @@ impl<'tcx> InsertSearcher<'_, 'tcx> {
370370
}
371371
}
372372
impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
373-
type Map = ErasedMap<'tcx>;
374-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
375-
NestedVisitorMap::None
376-
}
377-
378373
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
379374
match stmt.kind {
380375
StmtKind::Semi(e) => {

src/tools/clippy/clippy_lints/src/eval_order_dependence.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
22
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
33
use if_chain::if_chain;
4-
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
4+
use rustc_hir::intravisit::{walk_expr, Visitor};
55
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::hir::map::Map;
87
use rustc_middle::ty;
98
use rustc_session::{declare_lint_pass, declare_tool_lint};
109

@@ -133,8 +132,6 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
133132
}
134133

135134
impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
136-
type Map = Map<'tcx>;
137-
138135
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
139136
match e.kind {
140137
ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e),
@@ -167,9 +164,6 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
167164
fn visit_block(&mut self, _: &'tcx Block<'_>) {
168165
// don't continue over blocks, LateLintPass already does that
169166
}
170-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
171-
NestedVisitorMap::None
172-
}
173167
}
174168

175169
/// Walks up the AST from the given write expression (`vis.write_expr`) looking
@@ -299,8 +293,6 @@ struct ReadVisitor<'a, 'tcx> {
299293
}
300294

301295
impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
302-
type Map = Map<'tcx>;
303-
304296
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
305297
if expr.hir_id == self.last_expr.hir_id {
306298
return;
@@ -343,9 +335,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
343335

344336
walk_expr(self, expr);
345337
}
346-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
347-
NestedVisitorMap::None
348-
}
349338
}
350339

351340
/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`.

src/tools/clippy/clippy_lints/src/fallible_impl_from.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use clippy_utils::ty::is_type_diagnostic_item;
55
use if_chain::if_chain;
66
use rustc_hir as hir;
77
use rustc_lint::{LateContext, LateLintPass};
8-
use rustc_middle::hir::map::Map;
98
use rustc_middle::ty;
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110
use rustc_span::{sym, Span};
@@ -68,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
6867
}
6968

7069
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef]) {
71-
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
70+
use rustc_hir::intravisit::{self, Visitor};
7271
use rustc_hir::{Expr, ImplItemKind};
7372

7473
struct FindPanicUnwrap<'a, 'tcx> {
@@ -78,8 +77,6 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
7877
}
7978

8079
impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
81-
type Map = Map<'tcx>;
82-
8380
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
8481
if let Some(macro_call) = root_macro_call_first_node(self.lcx, expr) {
8582
if is_panic(self.lcx, macro_call.def_id) {
@@ -100,10 +97,6 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
10097
// and check sub-expressions
10198
intravisit::walk_expr(self, expr);
10299
}
103-
104-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
105-
NestedVisitorMap::None
106-
}
107100
}
108101

109102
for impl_item in impl_items {

src/tools/clippy/clippy_lints/src/functions/must_use.rs

-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_hir::def_id::{DefIdSet, LocalDefId};
44
use rustc_hir::{self as hir, def::Res, intravisit, QPath};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::{
7-
hir::map::Map,
87
lint::in_external_macro,
98
ty::{self, Ty},
109
};
@@ -211,8 +210,6 @@ struct StaticMutVisitor<'a, 'tcx> {
211210
}
212211

213212
impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
214-
type Map = Map<'tcx>;
215-
216213
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
217214
use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall};
218215

@@ -244,10 +241,6 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
244241
_ => {},
245242
}
246243
}
247-
248-
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
249-
intravisit::NestedVisitorMap::None
250-
}
251244
}
252245

253246
fn is_mutated_static(e: &hir::Expr<'_>) -> bool {

0 commit comments

Comments
 (0)