diff options
| author | Saleem Jaffer <saleem@acko.com> | 2019-04-18 00:10:45 +0530 |
|---|---|---|
| committer | Saleem Jaffer <saleem@acko.com> | 2019-04-18 00:10:45 +0530 |
| commit | a2f8269d0c2cdf05aa86d6ef478073f6f634d838 (patch) | |
| tree | 2fd6ef49e6fdc8c622ce84bd826a8eed577a2898 | |
| parent | 999ee0190fbcabf13253d6f95bb7ab73709c9240 (diff) | |
making adjust_span a closure
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index bd17080e8c2..7ffdad08453 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -68,35 +68,35 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { } } -/// Adjust the span from the block, to the last expression of the -/// block. This is a better span when returning a mutable reference -/// with too short a lifetime. The error message will use the span -/// from the assignment to the return place, which should only point -/// at the returned value, not the entire function body. -/// -/// fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 { -/// x -/// // ^ error message points at this expression. -/// } -fn adjust_span<'tcx>(expr: &mut Expr<'tcx>) -> Span { - if let ExprKind::Block { body } = expr.kind { - if let Some(ref last_expr) = body.expr { - expr.span = last_expr.span; - } - } - - expr.span -} - fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir_expr: &'tcx hir::Expr, mut expr: Expr<'tcx>, adjustment: &Adjustment<'tcx>) -> Expr<'tcx> { let Expr { temp_lifetime, mut span, .. } = expr; + + // Adjust the span from the block, to the last expression of the + // block. This is a better span when returning a mutable reference + // with too short a lifetime. The error message will use the span + // from the assignment to the return place, which should only point + // at the returned value, not the entire function body. + // + // fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 { + // x + // // ^ error message points at this expression. + // } + let mut adjust_span = |expr: &mut Expr<'tcx>| { + if let ExprKind::Block { body } = expr.kind { + if let Some(ref last_expr) = body.expr { + span = last_expr.span; + expr.span = span; + } + } + }; + let kind = match adjustment.kind { Adjust::Pointer(PointerCast::Unsize) => { - span = adjust_span(&mut expr); + adjust_span(&mut expr); ExprKind::Pointer { cast: PointerCast::Unsize, source: expr.to_ref() } } Adjust::Pointer(cast) => { @@ -106,7 +106,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, ExprKind::NeverToAny { source: expr.to_ref() } } Adjust::Deref(None) => { - span = adjust_span(&mut expr); + adjust_span(&mut expr); ExprKind::Deref { arg: expr.to_ref() } } Adjust::Deref(Some(deref)) => { |
