Skip to content

Commit 274a5bd

Browse files
committed
Simplify things (follow review comments)
1 parent ea40256 commit 274a5bd

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

clippy_lints/src/redundant_closure_call.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,12 @@ declare_clippy_lint! {
4343
declare_lint_pass!(RedundantClosureCall => [REDUNDANT_CLOSURE_CALL]);
4444

4545
// Used to find `return` statements or equivalents e.g., `?`
46-
struct ReturnVisitor {
47-
found_return: bool,
48-
}
49-
50-
impl ReturnVisitor {
51-
#[must_use]
52-
fn new() -> Self {
53-
Self { found_return: false }
54-
}
55-
}
46+
struct ReturnVisitor;
5647

5748
impl<'tcx> Visitor<'tcx> for ReturnVisitor {
5849
type Result = ControlFlow<()>;
5950
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> ControlFlow<()> {
6051
if let ExprKind::Ret(_) | ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) = ex.kind {
61-
self.found_return = true;
6252
return ControlFlow::Break(());
6353
}
6454
hir_visit::walk_expr(self, ex)
@@ -103,9 +93,8 @@ fn find_innermost_closure<'tcx>(
10393
while let ExprKind::Closure(closure) = expr.kind
10494
&& let body = cx.tcx.hir().body(closure.body)
10595
&& {
106-
let mut visitor = ReturnVisitor::new();
107-
visitor.visit_expr(body.value);
108-
!visitor.found_return
96+
let mut visitor = ReturnVisitor;
97+
!visitor.visit_expr(body.value).is_break()
10998
}
11099
&& steps > 0
111100
{

clippy_lints/src/unconditional_recursion.rs

-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ struct CheckCalls<'a, 'tcx> {
277277
cx: &'a LateContext<'tcx>,
278278
map: Map<'tcx>,
279279
implemented_ty_id: DefId,
280-
found_default_call: bool,
281280
method_span: Span,
282281
}
283282

@@ -302,7 +301,6 @@ where
302301
&& let Some(trait_def_id) = self.cx.tcx.trait_of_item(method_def_id)
303302
&& self.cx.tcx.is_diagnostic_item(sym::Default, trait_def_id)
304303
{
305-
self.found_default_call = true;
306304
span_error(self.cx, self.method_span, expr);
307305
return ControlFlow::Break(());
308306
}
@@ -384,7 +382,6 @@ impl UnconditionalRecursion {
384382
cx,
385383
map: cx.tcx.hir(),
386384
implemented_ty_id,
387-
found_default_call: false,
388385
method_span,
389386
};
390387
walk_body(&mut c, body);

clippy_lints/src/unused_peekable.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,22 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable {
7171
return;
7272
}
7373

74+
let mut found_peek_call = false;
75+
7476
for stmt in &block.stmts[idx..] {
75-
vis.visit_stmt(stmt);
77+
if vis.visit_stmt(stmt).is_break() {
78+
found_peek_call = true;
79+
break;
80+
}
7681
}
7782

78-
if let Some(expr) = block.expr {
79-
vis.visit_expr(expr);
83+
if !found_peek_call && let Some(expr) = block.expr {
84+
if vis.visit_expr(expr).is_break() {
85+
found_peek_call = true
86+
}
8087
}
8188

82-
if !vis.found_peek_call {
89+
if !found_peek_call {
8390
span_lint_hir_and_then(
8491
cx,
8592
UNUSED_PEEKABLE,
@@ -99,16 +106,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable {
99106
struct PeekableVisitor<'a, 'tcx> {
100107
cx: &'a LateContext<'tcx>,
101108
expected_hir_id: HirId,
102-
found_peek_call: bool,
103109
}
104110

105111
impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
106112
fn new(cx: &'a LateContext<'tcx>, expected_hir_id: HirId) -> Self {
107-
Self {
108-
cx,
109-
expected_hir_id,
110-
found_peek_call: false,
111-
}
113+
Self { cx, expected_hir_id }
112114
}
113115
}
114116

@@ -139,7 +141,6 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
139141
}
140142

141143
if args.iter().any(|arg| arg_is_mut_peekable(self.cx, arg)) {
142-
self.found_peek_call = true;
143144
return ControlFlow::Break(());
144145
}
145146

@@ -161,15 +162,13 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
161162
if matches!(method_name, "peek" | "peek_mut" | "next_if" | "next_if_eq")
162163
&& arg_is_mut_peekable(self.cx, self_arg)
163164
{
164-
self.found_peek_call = true;
165165
return ControlFlow::Break(());
166166
}
167167

168168
// foo.some_method() excluding Iterator methods
169169
if remaining_args.iter().any(|arg| arg_is_mut_peekable(self.cx, arg))
170170
&& !is_trait_method(self.cx, expr, sym::Iterator)
171171
{
172-
self.found_peek_call = true;
173172
return ControlFlow::Break(());
174173
}
175174

@@ -184,14 +183,12 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
184183
},
185184
ExprKind::AddrOf(_, Mutability::Not, _) => return ControlFlow::Continue(()),
186185
_ => {
187-
self.found_peek_call = true;
188186
return ControlFlow::Break(());
189187
},
190188
}
191189
},
192190
Node::LetStmt(LetStmt { init: Some(init), .. }) => {
193191
if arg_is_mut_peekable(self.cx, init) {
194-
self.found_peek_call = true;
195192
return ControlFlow::Break(());
196193
}
197194

@@ -200,7 +197,6 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
200197
Node::Stmt(stmt) => {
201198
match stmt.kind {
202199
StmtKind::Let(_) | StmtKind::Item(_) => {
203-
self.found_peek_call = true;
204200
return ControlFlow::Break(());
205201
},
206202
StmtKind::Expr(_) | StmtKind::Semi(_) => {},

0 commit comments

Comments
 (0)