summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/expr.rs
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-06-02 20:15:05 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-12 16:25:16 +0400
commit40ae7b5b8e09da657b62bc849b8bcdf99a1cb210 (patch)
treef2a08c2651b0cb786a37697ee7806b272c01bb1d /compiler/rustc_ast_lowering/src/expr.rs
parentfbdb07f4e7f4666085aec4b1ed2fd05817dc42cf (diff)
downloadrust-40ae7b5b8e09da657b62bc849b8bcdf99a1cb210.tar.gz
rust-40ae7b5b8e09da657b62bc849b8bcdf99a1cb210.zip
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
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/expr.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index 9e02e7ed3b9..7a35660b0af 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -155,6 +155,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
                     self.lower_expr_await(span, expr)
                 }
                 ExprKind::Closure(
+                    ref binder,
                     capture_clause,
                     asyncness,
                     movability,
@@ -164,6 +165,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
                 ) => {
                     if let Async::Yes { closure_id, .. } = asyncness {
                         self.lower_expr_async_closure(
+                            binder,
                             capture_clause,
                             e.id,
                             closure_id,
@@ -173,6 +175,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
                         )
                     } else {
                         self.lower_expr_closure(
+                            binder,
                             capture_clause,
                             e.id,
                             movability,
@@ -831,6 +834,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
     fn lower_expr_closure(
         &mut self,
+        binder: &ClosureBinder,
         capture_clause: CaptureBy,
         closure_id: NodeId,
         movability: Movability,
@@ -838,6 +842,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
         body: &Expr,
         fn_decl_span: Span,
     ) -> hir::ExprKind<'hir> {
+        // FIXME(waffle): lower binder
+        if let &ClosureBinder::For { span, .. } = binder {
+            self.sess
+                .struct_span_err(span, "`for<...>` binders for closures are not yet supported")
+                .help("consider removing `for<...>`")
+                .emit();
+        }
+
         let (body, generator_option) = self.with_new_scopes(move |this| {
             let prev = this.current_item;
             this.current_item = Some(fn_decl_span);
@@ -908,6 +920,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
     fn lower_expr_async_closure(
         &mut self,
+        binder: &ClosureBinder,
         capture_clause: CaptureBy,
         closure_id: NodeId,
         inner_closure_id: NodeId,
@@ -915,6 +928,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
         body: &Expr,
         fn_decl_span: Span,
     ) -> hir::ExprKind<'hir> {
+        // FIXME(waffle): lower binder
+        if let &ClosureBinder::For { span, .. } = binder {
+            self.sess
+                .struct_span_err(
+                    span,
+                    "`for<...>` binders for async closures are not yet supported",
+                )
+                .help("consider removing `for<...>`")
+                .emit();
+        }
+
         let outer_decl =
             FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };