@@ -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 } => {
@@ -150,7 +162,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
150162 // first process the set of fields
151163 let fields: Vec < _ > =
152164 fields. into_iter ( )
153- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
165+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
154166 . collect ( ) ;
155167
156168 block. and ( Rvalue :: Aggregate ( AggregateKind :: Array , fields) )
@@ -159,15 +171,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
159171 // first process the set of fields
160172 let fields: Vec < _ > =
161173 fields. into_iter ( )
162- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
174+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
163175 . collect ( ) ;
164176
165177 block. and ( Rvalue :: Aggregate ( AggregateKind :: Tuple , fields) )
166178 }
167179 ExprKind :: Closure { closure_id, substs, upvars } => { // see (*) above
168180 let upvars =
169181 upvars. into_iter ( )
170- . map ( |upvar| unpack ! ( block = this. as_operand( block, upvar) ) )
182+ . map ( |upvar| unpack ! ( block = this. as_operand( block, scope , upvar) ) )
171183 . collect ( ) ;
172184 block. and ( Rvalue :: Aggregate ( AggregateKind :: Closure ( closure_id, substs) , upvars) )
173185 }
@@ -179,10 +191,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
179191
180192 // first process the set of fields that were provided
181193 // (evaluating them in order given by user)
182- let fields_map: FxHashMap < _ , _ > =
183- fields. into_iter ( )
184- . map ( |f| ( f. name , unpack ! ( block = this. as_operand( block, f. expr) ) ) )
185- . collect ( ) ;
194+ let fields_map: FxHashMap < _ , _ > = fields. into_iter ( )
195+ . map ( |f| ( f. name , unpack ! ( block = this. as_operand( block, scope, f. expr) ) ) )
196+ . collect ( ) ;
186197
187198 let field_names = this. hir . all_fields ( adt_def, variant_index) ;
188199
@@ -235,7 +246,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
235246 Some ( Category :: Rvalue ( RvalueFunc :: AsRvalue ) ) => false ,
236247 _ => true ,
237248 } ) ;
238- let operand = unpack ! ( block = this. as_operand( block, expr) ) ;
249+ let operand = unpack ! ( block = this. as_operand( block, scope , expr) ) ;
239250 block. and ( Rvalue :: Use ( operand) )
240251 }
241252 }
0 commit comments