@@ -14,7 +14,18 @@ use hair::*;
1414use rustc:: mir:: * ;
1515
1616impl < ' 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+ {
1829 let this = self ;
1930 let expr_span = expr. span ;
2031 let source_info = this. source_info ( expr. span ) ;
@@ -29,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2940 } => {
3041 let value = this. hir . mirror ( value) ;
3142 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 )
3344 } )
3445 }
3546 ExprKind :: Assign { lhs, rhs } => {
@@ -192,7 +203,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
192203 let expr_ty = expr. ty ;
193204 let temp = this. temp ( expr. ty . clone ( ) , expr_span) ;
194205 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) ) ;
196215 block. unit ( )
197216 }
198217 }
0 commit comments