@@ -21,22 +21,34 @@ use build::expr::category::{Category, RvalueFunc};
2121use hair:: * ;
2222use rustc_const_math:: { ConstInt , ConstIsize } ;
2323use rustc:: middle:: const_val:: ConstVal ;
24+ use rustc:: middle:: region:: CodeExtent ;
2425use rustc:: ty;
2526use rustc:: mir:: * ;
2627use syntax:: ast;
2728use syntax_pos:: Span ;
2829
2930impl < ' a , ' gcx , ' tcx > Builder < ' a , ' gcx , ' tcx > {
31+ /// See comment on `as_local_operand`
32+ pub fn as_local_rvalue < M > ( & mut self , block : BasicBlock , expr : M )
33+ -> BlockAnd < Rvalue < ' tcx > >
34+ where M : Mirror < ' tcx , Output = Expr < ' tcx > >
35+ {
36+ let topmost_scope = self . topmost_scope ( ) ; // FIXME(#6393)
37+ self . as_rvalue ( block, Some ( topmost_scope) , expr)
38+ }
39+
3040 /// Compile `expr`, yielding an rvalue.
31- pub fn as_rvalue < M > ( & mut self , block : BasicBlock , expr : M ) -> BlockAnd < Rvalue < ' tcx > >
41+ pub fn as_rvalue < M > ( & mut self , block : BasicBlock , scope : Option < CodeExtent > , expr : M )
42+ -> BlockAnd < Rvalue < ' tcx > >
3243 where M : Mirror < ' tcx , Output = Expr < ' tcx > >
3344 {
3445 let expr = self . hir . mirror ( expr) ;
35- self . expr_as_rvalue ( block, expr)
46+ self . expr_as_rvalue ( block, scope , expr)
3647 }
3748
3849 fn expr_as_rvalue ( & mut self ,
3950 mut block : BasicBlock ,
51+ scope : Option < CodeExtent > ,
4052 expr : Expr < ' tcx > )
4153 -> BlockAnd < Rvalue < ' tcx > > {
4254 debug ! ( "expr_as_rvalue(block={:?}, expr={:?})" , block, expr) ;
@@ -47,24 +59,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4759
4860 match expr. kind {
4961 ExprKind :: Scope { extent, value } => {
50- this. in_scope ( extent, block, |this| this. as_rvalue ( block, value) )
62+ this. in_scope ( extent, block, |this| this. as_rvalue ( block, scope , value) )
5163 }
5264 ExprKind :: Repeat { value, count } => {
53- let value_operand = unpack ! ( block = this. as_operand( block, value) ) ;
65+ let value_operand = unpack ! ( block = this. as_operand( block, scope , value) ) ;
5466 block. and ( Rvalue :: Repeat ( value_operand, count) )
5567 }
5668 ExprKind :: Borrow { region, borrow_kind, arg } => {
5769 let arg_lvalue = unpack ! ( block = this. as_lvalue( block, arg) ) ;
5870 block. and ( Rvalue :: Ref ( region, borrow_kind, arg_lvalue) )
5971 }
6072 ExprKind :: Binary { op, lhs, rhs } => {
61- let lhs = unpack ! ( block = this. as_operand( block, lhs) ) ;
62- let rhs = unpack ! ( block = this. as_operand( block, rhs) ) ;
73+ let lhs = unpack ! ( block = this. as_operand( block, scope , lhs) ) ;
74+ let rhs = unpack ! ( block = this. as_operand( block, scope , rhs) ) ;
6375 this. build_binary_op ( block, op, expr_span, expr. ty ,
6476 lhs, rhs)
6577 }
6678 ExprKind :: Unary { op, arg } => {
67- let arg = unpack ! ( block = this. as_operand( block, arg) ) ;
79+ let arg = unpack ! ( block = this. as_operand( block, scope , arg) ) ;
6880 // Check for -MIN on signed integers
6981 if this. hir . check_overflow ( ) && op == UnOp :: Neg && expr. ty . is_signed ( ) {
7082 let bool_ty = this. hir . bool_ty ( ) ;
@@ -97,27 +109,27 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
97109 ExprKind :: Cast { source } => {
98110 let source = this. hir . mirror ( source) ;
99111
100- let source = unpack ! ( block = this. as_operand( block, source) ) ;
112+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
101113 block. and ( Rvalue :: Cast ( CastKind :: Misc , source, expr. ty ) )
102114 }
103115 ExprKind :: Use { source } => {
104- let source = unpack ! ( block = this. as_operand( block, source) ) ;
116+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
105117 block. and ( Rvalue :: Use ( source) )
106118 }
107119 ExprKind :: ReifyFnPointer { source } => {
108- let source = unpack ! ( block = this. as_operand( block, source) ) ;
120+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
109121 block. and ( Rvalue :: Cast ( CastKind :: ReifyFnPointer , source, expr. ty ) )
110122 }
111123 ExprKind :: UnsafeFnPointer { source } => {
112- let source = unpack ! ( block = this. as_operand( block, source) ) ;
124+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
113125 block. and ( Rvalue :: Cast ( CastKind :: UnsafeFnPointer , source, expr. ty ) )
114126 }
115127 ExprKind :: ClosureFnPointer { source } => {
116- let source = unpack ! ( block = this. as_operand( block, source) ) ;
128+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
117129 block. and ( Rvalue :: Cast ( CastKind :: ClosureFnPointer , source, expr. ty ) )
118130 }
119131 ExprKind :: Unsize { source } => {
120- let source = unpack ! ( block = this. as_operand( block, source) ) ;
132+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
121133 block. and ( Rvalue :: Cast ( CastKind :: Unsize , source, expr. ty ) )
122134 }
123135 ExprKind :: Array { fields } => {
@@ -151,7 +163,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
151163 let el_ty = expr. ty . sequence_element_type ( this. hir . tcx ( ) ) ;
152164 let fields: Vec < _ > =
153165 fields. into_iter ( )
154- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
166+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
155167 . collect ( ) ;
156168
157169 block. and ( Rvalue :: Aggregate ( AggregateKind :: Array ( el_ty) , fields) )
@@ -160,15 +172,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
160172 // first process the set of fields
161173 let fields: Vec < _ > =
162174 fields. into_iter ( )
163- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
175+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
164176 . collect ( ) ;
165177
166178 block. and ( Rvalue :: Aggregate ( AggregateKind :: Tuple , fields) )
167179 }
168180 ExprKind :: Closure { closure_id, substs, upvars } => { // see (*) above
169181 let upvars =
170182 upvars. into_iter ( )
171- . map ( |upvar| unpack ! ( block = this. as_operand( block, upvar) ) )
183+ . map ( |upvar| unpack ! ( block = this. as_operand( block, scope , upvar) ) )
172184 . collect ( ) ;
173185 block. and ( Rvalue :: Aggregate ( AggregateKind :: Closure ( closure_id, substs) , upvars) )
174186 }
@@ -180,10 +192,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
180192
181193 // first process the set of fields that were provided
182194 // (evaluating them in order given by user)
183- let fields_map: FxHashMap < _ , _ > =
184- fields. into_iter ( )
185- . map ( |f| ( f. name , unpack ! ( block = this. as_operand( block, f. expr) ) ) )
186- . collect ( ) ;
195+ let fields_map: FxHashMap < _ , _ > = fields. into_iter ( )
196+ . map ( |f| ( f. name , unpack ! ( block = this. as_operand( block, scope, f. expr) ) ) )
197+ . collect ( ) ;
187198
188199 let field_names = this. hir . all_fields ( adt_def, variant_index) ;
189200
@@ -236,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
236247 Some ( Category :: Rvalue ( RvalueFunc :: AsRvalue ) ) => false ,
237248 _ => true ,
238249 } ) ;
239- let operand = unpack ! ( block = this. as_operand( block, expr) ) ;
250+ let operand = unpack ! ( block = this. as_operand( block, scope , expr) ) ;
240251 block. and ( Rvalue :: Use ( operand) )
241252 }
242253 }
0 commit comments