@@ -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 } => {
@@ -150,7 +162,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
150
162
// first process the set of fields
151
163
let fields: Vec < _ > =
152
164
fields. into_iter ( )
153
- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
165
+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
154
166
. collect ( ) ;
155
167
156
168
block. and ( Rvalue :: Aggregate ( AggregateKind :: Array , fields) )
@@ -159,15 +171,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
159
171
// first process the set of fields
160
172
let fields: Vec < _ > =
161
173
fields. into_iter ( )
162
- . map ( |f| unpack ! ( block = this. as_operand( block, f) ) )
174
+ . map ( |f| unpack ! ( block = this. as_operand( block, scope , f) ) )
163
175
. collect ( ) ;
164
176
165
177
block. and ( Rvalue :: Aggregate ( AggregateKind :: Tuple , fields) )
166
178
}
167
179
ExprKind :: Closure { closure_id, substs, upvars } => { // see (*) above
168
180
let upvars =
169
181
upvars. into_iter ( )
170
- . map ( |upvar| unpack ! ( block = this. as_operand( block, upvar) ) )
182
+ . map ( |upvar| unpack ! ( block = this. as_operand( block, scope , upvar) ) )
171
183
. collect ( ) ;
172
184
block. and ( Rvalue :: Aggregate ( AggregateKind :: Closure ( closure_id, substs) , upvars) )
173
185
}
@@ -179,10 +191,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
179
191
180
192
// first process the set of fields that were provided
181
193
// (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 ( ) ;
186
197
187
198
let field_names = this. hir . all_fields ( adt_def, variant_index) ;
188
199
@@ -235,7 +246,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
235
246
Some ( Category :: Rvalue ( RvalueFunc :: AsRvalue ) ) => false ,
236
247
_ => true ,
237
248
} ) ;
238
- let operand = unpack ! ( block = this. as_operand( block, expr) ) ;
249
+ let operand = unpack ! ( block = this. as_operand( block, scope , expr) ) ;
239
250
block. and ( Rvalue :: Use ( operand) )
240
251
}
241
252
}
0 commit comments