@@ -21,22 +21,34 @@ use build::expr::category::{Category, RvalueFunc};
21
21
use hair:: * ;
22
22
use rustc_const_math:: { ConstInt , ConstIsize } ;
23
23
use rustc:: middle:: const_val:: ConstVal ;
24
+ use rustc:: middle:: region:: CodeExtent ;
24
25
use rustc:: ty;
25
26
use rustc:: mir:: * ;
26
27
use syntax:: ast;
27
28
use syntax_pos:: Span ;
28
29
29
30
impl < ' 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
+
30
40
/// 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 > >
32
43
where M : Mirror < ' tcx , Output = Expr < ' tcx > >
33
44
{
34
45
let expr = self . hir . mirror ( expr) ;
35
- self . expr_as_rvalue ( block, expr)
46
+ self . expr_as_rvalue ( block, scope , expr)
36
47
}
37
48
38
49
fn expr_as_rvalue ( & mut self ,
39
50
mut block : BasicBlock ,
51
+ scope : Option < CodeExtent > ,
40
52
expr : Expr < ' tcx > )
41
53
-> BlockAnd < Rvalue < ' tcx > > {
42
54
debug ! ( "expr_as_rvalue(block={:?}, expr={:?})" , block, expr) ;
@@ -47,24 +59,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
47
59
48
60
match expr. kind {
49
61
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) )
51
63
}
52
64
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) ) ;
54
66
block. and ( Rvalue :: Repeat ( value_operand, count) )
55
67
}
56
68
ExprKind :: Borrow { region, borrow_kind, arg } => {
57
69
let arg_lvalue = unpack ! ( block = this. as_lvalue( block, arg) ) ;
58
70
block. and ( Rvalue :: Ref ( region, borrow_kind, arg_lvalue) )
59
71
}
60
72
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) ) ;
63
75
this. build_binary_op ( block, op, expr_span, expr. ty ,
64
76
lhs, rhs)
65
77
}
66
78
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) ) ;
68
80
// Check for -MIN on signed integers
69
81
if this. hir . check_overflow ( ) && op == UnOp :: Neg && expr. ty . is_signed ( ) {
70
82
let bool_ty = this. hir . bool_ty ( ) ;
@@ -97,27 +109,27 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
97
109
ExprKind :: Cast { source } => {
98
110
let source = this. hir . mirror ( source) ;
99
111
100
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
112
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
101
113
block. and ( Rvalue :: Cast ( CastKind :: Misc , source, expr. ty ) )
102
114
}
103
115
ExprKind :: Use { source } => {
104
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
116
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
105
117
block. and ( Rvalue :: Use ( source) )
106
118
}
107
119
ExprKind :: ReifyFnPointer { source } => {
108
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
120
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
109
121
block. and ( Rvalue :: Cast ( CastKind :: ReifyFnPointer , source, expr. ty ) )
110
122
}
111
123
ExprKind :: UnsafeFnPointer { source } => {
112
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
124
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
113
125
block. and ( Rvalue :: Cast ( CastKind :: UnsafeFnPointer , source, expr. ty ) )
114
126
}
115
127
ExprKind :: ClosureFnPointer { source } => {
116
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
128
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
117
129
block. and ( Rvalue :: Cast ( CastKind :: ClosureFnPointer , source, expr. ty ) )
118
130
}
119
131
ExprKind :: Unsize { source } => {
120
- let source = unpack ! ( block = this. as_operand( block, source) ) ;
132
+ let source = unpack ! ( block = this. as_operand( block, scope , source) ) ;
121
133
block. and ( Rvalue :: Cast ( CastKind :: Unsize , source, expr. ty ) )
122
134
}
123
135
ExprKind :: Array { fields } => {
@@ -151,7 +163,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
151
163
let el_ty = expr. ty . sequence_element_type ( this. hir . tcx ( ) ) ;
152
164
let fields: Vec < _ > =
153
165
fields. into_iter ( )
154
- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
166
+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
155
167
. collect ( ) ;
156
168
157
169
block. and ( Rvalue :: Aggregate ( AggregateKind :: Array ( el_ty) , fields) )
@@ -160,15 +172,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
160
172
// first process the set of fields
161
173
let fields: Vec < _ > =
162
174
fields. into_iter ( )
163
- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
175
+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
164
176
. collect ( ) ;
165
177
166
178
block. and ( Rvalue :: Aggregate ( AggregateKind :: Tuple , fields) )
167
179
}
168
180
ExprKind :: Closure { closure_id, substs, upvars } => { // see (*) above
169
181
let upvars =
170
182
upvars. into_iter ( )
171
- . map ( |upvar| unpack ! ( block = this. as_operand( block, upvar) ) )
183
+ . map ( |upvar| unpack ! ( block = this. as_operand( block, scope , upvar) ) )
172
184
. collect ( ) ;
173
185
block. and ( Rvalue :: Aggregate ( AggregateKind :: Closure ( closure_id, substs) , upvars) )
174
186
}
@@ -180,10 +192,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
180
192
181
193
// first process the set of fields that were provided
182
194
// (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 ( ) ;
187
198
188
199
let field_names = this. hir . all_fields ( adt_def, variant_index) ;
189
200
@@ -236,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
236
247
Some ( Category :: Rvalue ( RvalueFunc :: AsRvalue ) ) => false ,
237
248
_ => true ,
238
249
} ) ;
239
- let operand = unpack ! ( block = this. as_operand( block, expr) ) ;
250
+ let operand = unpack ! ( block = this. as_operand( block, scope , expr) ) ;
240
251
block. and ( Rvalue :: Use ( operand) )
241
252
}
242
253
}
0 commit comments