1
1
//! See docs in `build/expr/mod.rs`.
2
2
3
- use rustc_data_structures:: fx:: FxHashMap ;
4
3
use rustc_index:: vec:: Idx ;
5
4
6
5
use crate :: build:: expr:: category:: { Category , RvalueFunc } ;
@@ -9,11 +8,16 @@ use crate::hair::*;
9
8
use rustc:: middle:: region;
10
9
use rustc:: mir:: interpret:: PanicInfo ;
11
10
use rustc:: mir:: * ;
12
- use rustc:: ty:: { self , CanonicalUserTypeAnnotation , Ty , UpvarSubsts } ;
11
+ use rustc:: ty:: { self , Ty , UpvarSubsts } ;
13
12
use syntax_pos:: Span ;
14
13
15
14
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
16
- /// See comment on `as_local_operand`
15
+ /// Returns an rvalue suitable for use until the end of the current
16
+ /// scope expression.
17
+ ///
18
+ /// The operand returned from this function will *not be valid* after
19
+ /// an ExprKind::Scope is passed, so please do *not* return it from
20
+ /// functions to avoid bad miscompiles.
17
21
pub fn as_local_rvalue < M > ( & mut self , block : BasicBlock , expr : M ) -> BlockAnd < Rvalue < ' tcx > >
18
22
where
19
23
M : Mirror < ' tcx , Output = Expr < ' tcx > > ,
@@ -23,7 +27,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
23
27
}
24
28
25
29
/// Compile `expr`, yielding an rvalue.
26
- pub fn as_rvalue < M > (
30
+ fn as_rvalue < M > (
27
31
& mut self ,
28
32
block : BasicBlock ,
29
33
scope : Option < region:: Scope > ,
@@ -66,16 +70,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
66
70
let value_operand = unpack ! ( block = this. as_operand( block, scope, value) ) ;
67
71
block. and ( Rvalue :: Repeat ( value_operand, count) )
68
72
}
69
- ExprKind :: Borrow {
70
- borrow_kind,
71
- arg,
72
- } => {
73
- let arg_place = match borrow_kind {
74
- BorrowKind :: Shared => unpack ! ( block = this. as_read_only_place( block, arg) ) ,
75
- _ => unpack ! ( block = this. as_place( block, arg) ) ,
76
- } ;
77
- block. and ( Rvalue :: Ref ( this. hir . tcx ( ) . lifetimes . re_erased , borrow_kind, arg_place) )
78
- }
79
73
ExprKind :: Binary { op, lhs, rhs } => {
80
74
let lhs = unpack ! ( block = this. as_operand( block, scope, lhs) ) ;
81
75
let rhs = unpack ! ( block = this. as_operand( block, scope, rhs) ) ;
@@ -256,77 +250,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
256
250
} ;
257
251
block. and ( Rvalue :: Aggregate ( result, operands) )
258
252
}
259
- ExprKind :: Adt {
260
- adt_def,
261
- variant_index,
262
- substs,
263
- user_ty,
264
- fields,
265
- base,
266
- } => {
267
- // see (*) above
268
- let is_union = adt_def. is_union ( ) ;
269
- let active_field_index = if is_union {
270
- Some ( fields[ 0 ] . name . index ( ) )
271
- } else {
272
- None
273
- } ;
274
-
275
- // first process the set of fields that were provided
276
- // (evaluating them in order given by user)
277
- let fields_map: FxHashMap < _ , _ > = fields
278
- . into_iter ( )
279
- . map ( |f| {
280
- (
281
- f. name ,
282
- unpack ! ( block = this. as_operand( block, scope, f. expr) ) ,
283
- )
284
- } ) . collect ( ) ;
285
-
286
- let field_names = this. hir . all_fields ( adt_def, variant_index) ;
287
-
288
- let fields = if let Some ( FruInfo { base, field_types } ) = base {
289
- let base = unpack ! ( block = this. as_place( block, base) ) ;
290
-
291
- // MIR does not natively support FRU, so for each
292
- // base-supplied field, generate an operand that
293
- // reads it from the base.
294
- field_names
295
- . into_iter ( )
296
- . zip ( field_types. into_iter ( ) )
297
- . map ( |( n, ty) | match fields_map. get ( & n) {
298
- Some ( v) => v. clone ( ) ,
299
- None => this. consume_by_copy_or_move ( this. hir . tcx ( ) . mk_place_field (
300
- base. clone ( ) ,
301
- n,
302
- ty,
303
- ) ) ,
304
- } )
305
- . collect ( )
306
- } else {
307
- field_names
308
- . iter ( )
309
- . filter_map ( |n| fields_map. get ( n) . cloned ( ) )
310
- . collect ( )
311
- } ;
312
-
313
- let inferred_ty = expr. ty ;
314
- let user_ty = user_ty. map ( |ty| {
315
- this. canonical_user_type_annotations . push ( CanonicalUserTypeAnnotation {
316
- span : source_info. span ,
317
- user_ty : ty,
318
- inferred_ty,
319
- } )
320
- } ) ;
321
- let adt = box AggregateKind :: Adt (
322
- adt_def,
323
- variant_index,
324
- substs,
325
- user_ty,
326
- active_field_index,
327
- ) ;
328
- block. and ( Rvalue :: Aggregate ( adt, fields) )
329
- }
330
253
ExprKind :: Assign { .. } | ExprKind :: AssignOp { .. } => {
331
254
block = unpack ! ( this. stmt_expr( block, expr, None ) ) ;
332
255
block. and ( this. unit_rvalue ( ) )
@@ -351,6 +274,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
351
274
| ExprKind :: Match { .. }
352
275
| ExprKind :: NeverToAny { .. }
353
276
| ExprKind :: Use { .. }
277
+ | ExprKind :: Borrow { .. }
278
+ | ExprKind :: Adt { .. }
354
279
| ExprKind :: Loop { .. }
355
280
| ExprKind :: LogicalOp { .. }
356
281
| ExprKind :: Call { .. }
0 commit comments