thread tighter span for closures around
Track the span corresponding to the `|...|` part of the closure.
This commit is contained in:
parent
23ccaddaa7
commit
ecd10f04ce
29 changed files with 87 additions and 53 deletions
|
@ -194,10 +194,14 @@ pub trait AstBuilder {
|
|||
cond: P<ast::Expr>, then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr>;
|
||||
fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr>;
|
||||
|
||||
fn lambda_fn_decl(&self, span: Span,
|
||||
fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> P<ast::Expr>;
|
||||
fn lambda_fn_decl(&self,
|
||||
span: Span,
|
||||
fn_decl: P<ast::FnDecl>,
|
||||
blk: P<ast::Block>,
|
||||
fn_decl_span: Span)
|
||||
-> P<ast::Expr>;
|
||||
|
||||
fn lambda(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Block>) -> P<ast::Expr>;
|
||||
fn lambda(&self, span: Span, ids: Vec<ast::Ident>, blk: P<ast::Block>) -> P<ast::Expr>;
|
||||
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr>;
|
||||
fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> P<ast::Expr>;
|
||||
|
||||
|
@ -894,17 +898,34 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
self.expr(span, ast::ExprKind::Loop(block, None))
|
||||
}
|
||||
|
||||
fn lambda_fn_decl(&self, span: Span,
|
||||
fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> P<ast::Expr> {
|
||||
self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk))
|
||||
fn lambda_fn_decl(&self,
|
||||
span: Span,
|
||||
fn_decl: P<ast::FnDecl>,
|
||||
blk: P<ast::Block>,
|
||||
fn_decl_span: Span) // span of the `|...|` part
|
||||
-> P<ast::Expr> {
|
||||
self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref,
|
||||
fn_decl,
|
||||
blk,
|
||||
fn_decl_span))
|
||||
}
|
||||
fn lambda(&self, span: Span, ids: Vec<ast::Ident>, blk: P<ast::Block>) -> P<ast::Expr> {
|
||||
|
||||
fn lambda(&self,
|
||||
span: Span,
|
||||
ids: Vec<ast::Ident>,
|
||||
blk: P<ast::Block>)
|
||||
-> P<ast::Expr> {
|
||||
let fn_decl = self.fn_decl(
|
||||
ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(),
|
||||
self.ty_infer(span));
|
||||
|
||||
self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk))
|
||||
// FIXME -- We are using `span` as the span of the `|...|`
|
||||
// part of the lambda, but it probably (maybe?) corresponds to
|
||||
// the entire lambda body. Probably we should extend the API
|
||||
// here, but that's not entirely clear.
|
||||
self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk, span))
|
||||
}
|
||||
|
||||
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr> {
|
||||
self.lambda(span, Vec::new(), blk)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue