Skip to content

Commit bd071bf

Browse files
authored
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant. Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`. r? ``@Aaron1011``
2 parents 196f3c0 + 7b84a97 commit bd071bf

36 files changed

+112
-98
lines changed

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> {
5151

5252
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5353
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
54-
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
54+
if let ExprKind::Closure { body, .. } = expr.kind {
5555
// do not lint if the closure is called using an iterator (see #1141)
5656
if_chain! {
5757
if let Some(parent) = get_parent_expr(self.cx, expr);
@@ -64,7 +64,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
6464
}
6565
}
6666

67-
let body = self.cx.tcx.hir().body(eid);
67+
let body = self.cx.tcx.hir().body(body);
6868
let ex = &body.value;
6969
if let ExprKind::Block(block, _) = ex.kind {
7070
if !body.value.span.from_expansion() && !block.stmts.is_empty() {

clippy_lints/src/bytecount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5151
if count.ident.name == sym::count;
5252
if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind;
5353
if filter.ident.name == sym!(filter);
54-
if let ExprKind::Closure(_, _, body_id, _, _) = filter_arg.kind;
55-
let body = cx.tcx.hir().body(body_id);
54+
if let ExprKind::Closure { body, .. } = filter_arg.kind;
55+
let body = cx.tcx.hir().body(body);
5656
if let [param] = body.params;
5757
if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind;
5858
if let ExprKind::Binary(ref op, l, r) = body.value.kind;

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn is_linted_explicit_deref_position(parent: Option<Node<'_>>, child_id: HirId,
498498
| ExprKind::Loop(..)
499499
| ExprKind::Match(..)
500500
| ExprKind::Let(..)
501-
| ExprKind::Closure(..)
501+
| ExprKind::Closure{..}
502502
| ExprKind::Block(..)
503503
| ExprKind::Assign(..)
504504
| ExprKind::AssignOp(..)

clippy_lints/src/eta_reduction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
7878
return;
7979
}
8080
let body = match expr.kind {
81-
ExprKind::Closure(_, _, id, _, _) => cx.tcx.hir().body(id),
81+
ExprKind::Closure { body, .. } => cx.tcx.hir().body(body),
8282
_ => return,
8383
};
8484
if body.value.span.from_expansion() {

clippy_lints/src/infinite_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
158158
}
159159
}
160160
if method.ident.name == sym!(flat_map) && args.len() == 2 {
161-
if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind {
162-
let body = cx.tcx.hir().body(body_id);
161+
if let ExprKind::Closure { body, .. } = args[1].kind {
162+
let body = cx.tcx.hir().body(body);
163163
return is_infinite(cx, &body.value);
164164
}
165165
}

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
369369
self.visit_expr(expr);
370370
}
371371
},
372-
ExprKind::Closure(_, _, body_id, ..) => {
373-
let body = self.cx.tcx.hir().body(body_id);
372+
ExprKind::Closure { body, .. } => {
373+
let body = self.cx.tcx.hir().body(body);
374374
self.visit_expr(&body.value);
375375
},
376376
_ => walk_expr(self, expr),

clippy_lints/src/loops/never_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
182182
.fold(NeverLoopResult::Otherwise, combine_both),
183183
ExprKind::Struct(_, _, None)
184184
| ExprKind::Yield(_, _)
185-
| ExprKind::Closure(_, _, _, _, _)
185+
| ExprKind::Closure { .. }
186186
| ExprKind::Path(_)
187187
| ExprKind::ConstBlock(_)
188188
| ExprKind::Lit(_)

clippy_lints/src/loops/while_let_on_iterator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc
220220
if let Some(e) = e {
221221
self.visit_expr(e);
222222
}
223-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
223+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
224224
if is_res_used(self.cx, self.iter_expr.path, id) {
225225
self.uses_iter = true;
226226
}
@@ -260,7 +260,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
260260
if let Some(e) = e {
261261
self.visit_expr(e);
262262
}
263-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
263+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
264264
self.used_iter = is_res_used(self.cx, self.iter_expr.path, id);
265265
} else {
266266
walk_expr(self, e);
@@ -307,7 +307,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
307307
if let Some(e) = e {
308308
self.visit_expr(e);
309309
}
310-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
310+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
311311
self.used_after = is_res_used(self.cx, self.iter_expr.path, id);
312312
} else {
313313
walk_expr(self, e);

clippy_lints/src/manual_async_fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
177177
if let Some(block_expr) = block.expr;
178178
if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR);
179179
if args.len() == 1;
180-
if let Expr{kind: ExprKind::Closure(_, _, body_id, ..), ..} = args[0];
181-
let closure_body = cx.tcx.hir().body(body_id);
180+
if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0];
181+
let closure_body = cx.tcx.hir().body(body);
182182
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
183183
then {
184184
return Some(closure_body);

clippy_lints/src/manual_ok_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8888
}
8989
}
9090
if_chain! {
91-
if let ExprKind::Closure(_, _, body_id, ..) = map_expr.kind;
92-
let body = cx.tcx.hir().body(body_id);
91+
if let ExprKind::Closure { body, .. } = map_expr.kind;
92+
let body = cx.tcx.hir().body(body);
9393
if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
9494
if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;
9595
if is_lang_ctor(cx, ok_path, ResultOk);

0 commit comments

Comments
 (0)