From 40ae7b5b8e09da657b62bc849b8bcdf99a1cb210 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 2 Jun 2022 20:15:05 +0400 Subject: [PATCH 01/12] Parse closure binders This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature --- compiler/rustc_ast/src/ast.rs | 27 +++++++- compiler/rustc_ast/src/mut_visit.rs | 18 ++++- compiler/rustc_ast/src/visit.rs | 25 +++++-- compiler/rustc_ast_lowering/src/expr.rs | 24 +++++++ .../rustc_ast_passes/src/ast_validation.rs | 4 ++ compiler/rustc_ast_passes/src/feature_gate.rs | 5 ++ .../rustc_ast_pretty/src/pprust/state/expr.rs | 11 +++ .../src/assert/context.rs | 2 +- compiler/rustc_expand/src/build.rs | 1 + compiler/rustc_feature/src/active.rs | 2 + compiler/rustc_lint/src/early.rs | 2 +- compiler/rustc_parse/src/parser/expr.rs | 48 ++++++------- compiler/rustc_resolve/src/def_collector.rs | 2 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + src/test/ui-fulldeps/pprust-expr-roundtrip.rs | 1 + .../binder/async-closure-with-binder.rs | 7 ++ .../binder/async-closure-with-binder.stderr | 8 +++ .../ui/closures/binder/implicit-return.rs | 6 ++ .../ui/closures/binder/implicit-return.stderr | 10 +++ ...on-for-introducing-lifetime-into-binder.rs | 7 ++ ...or-introducing-lifetime-into-binder.stderr | 33 +++++++++ .../feature-gate-closure_lifetime_binder.rs | 12 ++++ ...eature-gate-closure_lifetime_binder.stderr | 67 +++++++++++++++++++ 24 files changed, 287 insertions(+), 38 deletions(-) create mode 100644 src/test/ui/closures/binder/async-closure-with-binder.rs create mode 100644 src/test/ui/closures/binder/async-closure-with-binder.stderr create mode 100644 src/test/ui/closures/binder/implicit-return.rs create mode 100644 src/test/ui/closures/binder/implicit-return.stderr create mode 100644 src/test/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.rs create mode 100644 src/test/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.stderr create mode 100644 src/test/ui/feature-gates/feature-gate-closure_lifetime_binder.rs create mode 100644 src/test/ui/feature-gates/feature-gate-closure_lifetime_binder.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f705d00442227..ac2328a582418 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1390,7 +1390,7 @@ pub enum ExprKind { /// A closure (e.g., `move |a, b, c| a + b + c`). /// /// The final span is the span of the argument block `|...|`. - Closure(CaptureBy, Async, Movability, P, P, Span), + Closure(ClosureBinder, CaptureBy, Async, Movability, P, P, Span), /// A block (`'label: { ... }`). Block(P, Option