diff --git a/src/expr.rs b/src/expr.rs index 43fff1efa..e2ea38fb6 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2004,8 +2004,8 @@ impl ExprClosureBuilder { FnDeclBuilder::with_callback(self) } - pub fn build_fn_decl(self, fn_decl: P) -> ExprClosureBlockBuilder { - ExprClosureBlockBuilder { + pub fn build_fn_decl(self, fn_decl: P) -> ExprClosureExprBuilder { + ExprClosureExprBuilder { builder: self.builder, capture_by: self.capture_by, fn_decl: fn_decl, @@ -2015,45 +2015,42 @@ impl ExprClosureBuilder { } impl Invoke> for ExprClosureBuilder { - type Result = ExprClosureBlockBuilder; + type Result = ExprClosureExprBuilder; - fn invoke(self, fn_decl: P) -> ExprClosureBlockBuilder { + fn invoke(self, fn_decl: P) -> ExprClosureExprBuilder { self.build_fn_decl(fn_decl) } } ////////////////////////////////////////////////////////////////////////////// -pub struct ExprClosureBlockBuilder { +pub struct ExprClosureExprBuilder { builder: ExprBuilder, capture_by: ast::CaptureBy, fn_decl: P, span: Span, } -impl ExprClosureBlockBuilder +impl ExprClosureExprBuilder where F: Invoke>, { - pub fn expr(self) -> ExprBuilder> { - self.block().expr() - } - - pub fn block(self) -> BlockBuilder { - BlockBuilder::with_callback(self) + pub fn expr(self) -> ExprBuilder { + let span = self.span; + ExprBuilder::with_callback(self).span(span) } - pub fn build_block(self, block: P) -> F::Result { - self.builder.build_expr_kind(ast::ExprKind::Closure(self.capture_by, self.fn_decl, block, self.span)) + pub fn build_expr(self, expr: P) -> F::Result { + self.builder.build_expr_kind(ast::ExprKind::Closure(self.capture_by, self.fn_decl, expr, self.span)) } } -impl Invoke> for ExprClosureBlockBuilder +impl Invoke> for ExprClosureExprBuilder where F: Invoke>, { type Result = F::Result; - fn invoke(self, block: P) -> F::Result { - self.build_block(block) + fn invoke(self, expr: P) -> F::Result { + self.build_expr(expr) } } diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 34fca62ec..814a0dc20 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -575,7 +575,7 @@ fn test_trivial_closure() { ast::ExprKind::Closure( ast::CaptureBy::Value, builder.fn_decl().default_return(), - builder.block().expr().usize(1), + builder.expr().usize(1), DUMMY_SP, ) ) @@ -597,7 +597,7 @@ fn test_closure_by_ref() { ast::ExprKind::Closure( ast::CaptureBy::Ref, builder.fn_decl().default_return(), - builder.block().expr().usize(2), + builder.expr().usize(2), DUMMY_SP, ) ) @@ -611,7 +611,7 @@ fn test_closure_block() { let expr = builder.expr().closure() .by_ref() .fn_decl().default_return() - .block().expr().usize(3); + .expr().usize(3); assert_eq!( expr, @@ -619,7 +619,7 @@ fn test_closure_block() { ast::ExprKind::Closure( ast::CaptureBy::Ref, builder.fn_decl().default_return(), - builder.block().expr().usize(3), + builder.expr().usize(3), DUMMY_SP, ) )