@@ -68,35 +68,35 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
68
68
}
69
69
}
70
70
71
- /// Adjust the span from the block, to the last expression of the
72
- /// block. This is a better span when returning a mutable reference
73
- /// with too short a lifetime. The error message will use the span
74
- /// from the assignment to the return place, which should only point
75
- /// at the returned value, not the entire function body.
76
- ///
77
- /// fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 {
78
- /// x
79
- /// // ^ error message points at this expression.
80
- /// }
81
- fn adjust_span < ' tcx > ( expr : & mut Expr < ' tcx > ) -> Span {
82
- if let ExprKind :: Block { body } = expr. kind {
83
- if let Some ( ref last_expr) = body. expr {
84
- expr. span = last_expr. span ;
85
- }
86
- }
87
-
88
- expr. span
89
- }
90
-
91
71
fn apply_adjustment < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
92
72
hir_expr : & ' tcx hir:: Expr ,
93
73
mut expr : Expr < ' tcx > ,
94
74
adjustment : & Adjustment < ' tcx > )
95
75
-> Expr < ' tcx > {
96
76
let Expr { temp_lifetime, mut span, .. } = expr;
77
+
78
+ // Adjust the span from the block, to the last expression of the
79
+ // block. This is a better span when returning a mutable reference
80
+ // with too short a lifetime. The error message will use the span
81
+ // from the assignment to the return place, which should only point
82
+ // at the returned value, not the entire function body.
83
+ //
84
+ // fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 {
85
+ // x
86
+ // // ^ error message points at this expression.
87
+ // }
88
+ let mut adjust_span = |expr : & mut Expr < ' tcx > | {
89
+ if let ExprKind :: Block { body } = expr. kind {
90
+ if let Some ( ref last_expr) = body. expr {
91
+ span = last_expr. span ;
92
+ expr. span = span;
93
+ }
94
+ }
95
+ } ;
96
+
97
97
let kind = match adjustment. kind {
98
98
Adjust :: Pointer ( PointerCast :: Unsize ) => {
99
- span = adjust_span ( & mut expr) ;
99
+ adjust_span ( & mut expr) ;
100
100
ExprKind :: Pointer { cast : PointerCast :: Unsize , source : expr. to_ref ( ) }
101
101
}
102
102
Adjust :: Pointer ( cast) => {
@@ -106,7 +106,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
106
106
ExprKind :: NeverToAny { source : expr. to_ref ( ) }
107
107
}
108
108
Adjust :: Deref ( None ) => {
109
- span = adjust_span ( & mut expr) ;
109
+ adjust_span ( & mut expr) ;
110
110
ExprKind :: Deref { arg : expr. to_ref ( ) }
111
111
}
112
112
Adjust :: Deref ( Some ( deref) ) => {
0 commit comments