Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Update to rustc 1.15.0-nightly (ba872f270 2016-11-17)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Nov 18, 2016
1 parent 876600a commit ae8771e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
31 changes: 14 additions & 17 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,8 +2004,8 @@ impl<F> ExprClosureBuilder<F> {
FnDeclBuilder::with_callback(self)
}

pub fn build_fn_decl(self, fn_decl: P<ast::FnDecl>) -> ExprClosureBlockBuilder<F> {
ExprClosureBlockBuilder {
pub fn build_fn_decl(self, fn_decl: P<ast::FnDecl>) -> ExprClosureExprBuilder<F> {
ExprClosureExprBuilder {
builder: self.builder,
capture_by: self.capture_by,
fn_decl: fn_decl,
Expand All @@ -2015,45 +2015,42 @@ impl<F> ExprClosureBuilder<F> {
}

impl<F> Invoke<P<ast::FnDecl>> for ExprClosureBuilder<F> {
type Result = ExprClosureBlockBuilder<F>;
type Result = ExprClosureExprBuilder<F>;

fn invoke(self, fn_decl: P<ast::FnDecl>) -> ExprClosureBlockBuilder<F> {
fn invoke(self, fn_decl: P<ast::FnDecl>) -> ExprClosureExprBuilder<F> {
self.build_fn_decl(fn_decl)
}
}

//////////////////////////////////////////////////////////////////////////////

pub struct ExprClosureBlockBuilder<F> {
pub struct ExprClosureExprBuilder<F> {
builder: ExprBuilder<F>,
capture_by: ast::CaptureBy,
fn_decl: P<ast::FnDecl>,
span: Span,
}

impl<F> ExprClosureBlockBuilder<F>
impl<F> ExprClosureExprBuilder<F>
where F: Invoke<P<ast::Expr>>,
{
pub fn expr(self) -> ExprBuilder<BlockBuilder<Self>> {
self.block().expr()
}

pub fn block(self) -> BlockBuilder<Self> {
BlockBuilder::with_callback(self)
pub fn expr(self) -> ExprBuilder<Self> {
let span = self.span;
ExprBuilder::with_callback(self).span(span)
}

pub fn build_block(self, block: P<ast::Block>) -> 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<ast::Expr>) -> F::Result {
self.builder.build_expr_kind(ast::ExprKind::Closure(self.capture_by, self.fn_decl, expr, self.span))
}
}

impl<F> Invoke<P<ast::Block>> for ExprClosureBlockBuilder<F>
impl<F> Invoke<P<ast::Expr>> for ExprClosureExprBuilder<F>
where F: Invoke<P<ast::Expr>>,
{
type Result = F::Result;

fn invoke(self, block: P<ast::Block>) -> F::Result {
self.build_block(block)
fn invoke(self, expr: P<ast::Expr>) -> F::Result {
self.build_expr(expr)
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Expand All @@ -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,
)
)
Expand All @@ -611,15 +611,15 @@ 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,
builder.expr().build_expr_kind(
ast::ExprKind::Closure(
ast::CaptureBy::Ref,
builder.fn_decl().default_return(),
builder.block().expr().usize(3),
builder.expr().usize(3),
DUMMY_SP,
)
)
Expand Down

0 comments on commit ae8771e

Please sign in to comment.