@@ -14,7 +14,18 @@ use hair::*;
14
14
use rustc:: mir:: * ;
15
15
16
16
impl < ' a , ' gcx , ' tcx > Builder < ' a , ' gcx , ' tcx > {
17
- pub fn stmt_expr ( & mut self , mut block : BasicBlock , expr : Expr < ' tcx > ) -> BlockAnd < ( ) > {
17
+ /// Builds a block of MIR statements to evaluate the HAIR `expr`.
18
+ /// If the original expression was an AST statement,
19
+ /// (e.g. `some().code(&here());`) then `opt_stmt_span` is the
20
+ /// span of that statement (including its semicolon, if any).
21
+ /// Diagnostics use this span (which may be larger than that of
22
+ /// `expr`) to identify when statement temporaries are dropped.
23
+ pub fn stmt_expr ( & mut self ,
24
+ mut block : BasicBlock ,
25
+ expr : Expr < ' tcx > ,
26
+ opt_stmt_span : Option < StatementSpan > )
27
+ -> BlockAnd < ( ) >
28
+ {
18
29
let this = self ;
19
30
let expr_span = expr. span ;
20
31
let source_info = this. source_info ( expr. span ) ;
@@ -29,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
29
40
} => {
30
41
let value = this. hir . mirror ( value) ;
31
42
this. in_scope ( ( region_scope, source_info) , lint_level, block, |this| {
32
- this. stmt_expr ( block, value)
43
+ this. stmt_expr ( block, value, opt_stmt_span )
33
44
} )
34
45
}
35
46
ExprKind :: Assign { lhs, rhs } => {
@@ -192,7 +203,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
192
203
let expr_ty = expr. ty ;
193
204
let temp = this. temp ( expr. ty . clone ( ) , expr_span) ;
194
205
unpack ! ( block = this. into( & temp, block, expr) ) ;
195
- unpack ! ( block = this. build_drop( block, expr_span, temp, expr_ty) ) ;
206
+
207
+ // Attribute drops of the statement's temps to the
208
+ // semicolon at the statement's end.
209
+ let drop_point = this. hir . tcx ( ) . sess . source_map ( ) . end_point ( match opt_stmt_span {
210
+ None => expr_span,
211
+ Some ( StatementSpan ( span) ) => span,
212
+ } ) ;
213
+
214
+ unpack ! ( block = this. build_drop( block, drop_point, temp, expr_ty) ) ;
196
215
block. unit ( )
197
216
}
198
217
}
0 commit comments