Skip to content

Commit e275abf

Browse files
authored
Rollup merge of rust-lang#98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](rust-lang#97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2 parents 5a6fe3f + 1c3f62c commit e275abf

31 files changed

+71
-62
lines changed

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::ty::implements_trait;
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::{walk_expr, Visitor};
9-
use rustc_hir::{BlockCheckMode, Expr, ExprKind};
9+
use rustc_hir::{BlockCheckMode, Closure, Expr, ExprKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -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 { body, .. } = expr.kind {
54+
if let ExprKind::Closure(&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);

clippy_lints/src/bytecount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::visitors::is_local_used;
55
use clippy_utils::{path_to_local_id, paths, peel_blocks, peel_ref_operators, strip_pat_refs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BinOpKind, Expr, ExprKind, PatKind};
8+
use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::{self, UintTy};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -51,7 +51,7 @@ 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, .. } = filter_arg.kind;
54+
if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind;
5555
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;

clippy_lints/src/eta_reduction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::{higher, is_adjusted, path_to_local, path_to_local_id};
77
use if_chain::if_chain;
88
use rustc_errors::Applicability;
99
use rustc_hir::def_id::DefId;
10-
use rustc_hir::{Expr, ExprKind, Param, PatKind, Unsafety};
10+
use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
1313
use rustc_middle::ty::binding::BindingMode;
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
7878
return;
7979
}
8080
let body = match expr.kind {
81-
ExprKind::Closure { body, .. } => cx.tcx.hir().body(body),
81+
ExprKind::Closure(&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
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
33
use clippy_utils::{higher, match_def_path, path_def_id, paths};
4-
use rustc_hir::{BorrowKind, Expr, ExprKind};
4+
use rustc_hir::{BorrowKind, Closure, Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::symbol::{sym, Symbol};
@@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
159159
}
160160
}
161161
if method.ident.name == sym!(flat_map) && args.len() == 2 {
162-
if let ExprKind::Closure { body, .. } = args[1].kind {
162+
if let ExprKind::Closure(&Closure { body, .. }) = args[1].kind {
163163
let body = cx.tcx.hir().body(body);
164164
return is_infinite(cx, &body.value);
165165
}

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{walk_expr, Visitor};
12-
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath};
12+
use rustc_hir::{BinOpKind, BorrowKind, Closure, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath};
1313
use rustc_lint::LateContext;
1414
use rustc_middle::middle::region;
1515
use rustc_middle::ty::{self, Ty};
@@ -369,7 +369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
369369
self.visit_expr(expr);
370370
}
371371
},
372-
ExprKind::Closure { body, .. } => {
372+
ExprKind::Closure(&Closure { body, .. }) => {
373373
let body = self.cx.tcx.hir().body(body);
374374
self.visit_expr(&body.value);
375375
},

clippy_lints/src/loops/while_let_on_iterator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
use if_chain::if_chain;
99
use rustc_errors::Applicability;
1010
use rustc_hir::intravisit::{walk_expr, Visitor};
11-
use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp};
11+
use rustc_hir::{Closure, def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp};
1212
use rustc_lint::LateContext;
1313
use rustc_middle::ty::adjustment::Adjust;
1414
use rustc_span::{symbol::sym, Symbol};
@@ -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 { body: id, .. } = e.kind {
223+
} else if let ExprKind::Closure(&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 { body: id, .. } = e.kind {
263+
} else if let ExprKind::Closure(&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 { body: id, .. } = e.kind {
310+
} else if let ExprKind::Closure(&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
@@ -6,7 +6,7 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::intravisit::FnKind;
88
use rustc_hir::{
9-
AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
9+
AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
1010
IsAsync, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
@@ -177,7 +177,7 @@ 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, .. }, ..} = args[0];
180+
if let Expr{kind: ExprKind::Closure(&Closure { body, .. }), ..} = args[0];
181181
let closure_body = cx.tcx.hir().body(body);
182182
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
183183
then {

clippy_lints/src/manual_ok_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::{is_lang_ctor, path_to_local_id};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::LangItem::{ResultErr, ResultOk};
8-
use rustc_hir::{Expr, ExprKind, PatKind};
8+
use rustc_hir::{Closure, Expr, ExprKind, PatKind};
99
use rustc_lint::LintContext;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::lint::in_external_macro;
@@ -88,7 +88,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8888
}
8989
}
9090
if_chain! {
91-
if let ExprKind::Closure { body, .. } = map_expr.kind;
91+
if let ExprKind::Closure(&Closure { body, .. }) = map_expr.kind;
9292
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;

clippy_lints/src/manual_retain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn check_to_owned(
148148

149149
fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::Expr<'_>, filter_expr: &hir::Expr<'_>) {
150150
if let hir::ExprKind::MethodCall(_, [_, closure], _) = filter_expr.kind
151-
&& let hir::ExprKind::Closure{ body, ..} = closure.kind
151+
&& let hir::ExprKind::Closure(&hir::Closure { body, ..}) = closure.kind
152152
&& let filter_body = cx.tcx.hir().body(body)
153153
&& let [filter_params] = filter_body.params
154154
&& let Some(sugg) = match filter_params.pat.kind {

clippy_lints/src/map_clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
6767
if method.ident.name == sym::map;
6868
let ty = cx.typeck_results().expr_ty(&args[0]);
6969
if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator);
70-
if let hir::ExprKind::Closure { body, .. } = args[1].kind;
70+
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = args[1].kind;
7171
then {
7272
let closure_body = cx.tcx.hir().body(body);
7373
let closure_expr = peel_blocks(&closure_body.value);

0 commit comments

Comments
 (0)