11//! See docs in `build/expr/mod.rs`.
22
3- use rustc_data_structures:: fx:: FxHashMap ;
43use rustc_index:: vec:: Idx ;
54
65use crate :: build:: expr:: category:: { Category , RvalueFunc } ;
@@ -9,11 +8,16 @@ use crate::hair::*;
98use rustc:: middle:: region;
109use rustc:: mir:: interpret:: PanicInfo ;
1110use rustc:: mir:: * ;
12- use rustc:: ty:: { self , CanonicalUserTypeAnnotation , Ty , UpvarSubsts } ;
11+ use rustc:: ty:: { self , Ty , UpvarSubsts } ;
1312use syntax_pos:: Span ;
1413
1514impl < ' 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.
1721 pub fn as_local_rvalue < M > ( & mut self , block : BasicBlock , expr : M ) -> BlockAnd < Rvalue < ' tcx > >
1822 where
1923 M : Mirror < ' tcx , Output = Expr < ' tcx > > ,
@@ -23,7 +27,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2327 }
2428
2529 /// Compile `expr`, yielding an rvalue.
26- pub fn as_rvalue < M > (
30+ fn as_rvalue < M > (
2731 & mut self ,
2832 block : BasicBlock ,
2933 scope : Option < region:: Scope > ,
@@ -66,16 +70,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6670 let value_operand = unpack ! ( block = this. as_operand( block, scope, value) ) ;
6771 block. and ( Rvalue :: Repeat ( value_operand, count) )
6872 }
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- }
7973 ExprKind :: Binary { op, lhs, rhs } => {
8074 let lhs = unpack ! ( block = this. as_operand( block, scope, lhs) ) ;
8175 let rhs = unpack ! ( block = this. as_operand( block, scope, rhs) ) ;
@@ -256,77 +250,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
256250 } ;
257251 block. and ( Rvalue :: Aggregate ( result, operands) )
258252 }
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- }
330253 ExprKind :: Assign { .. } | ExprKind :: AssignOp { .. } => {
331254 block = unpack ! ( this. stmt_expr( block, expr, None ) ) ;
332255 block. and ( this. unit_rvalue ( ) )
@@ -351,6 +274,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
351274 | ExprKind :: Match { .. }
352275 | ExprKind :: NeverToAny { .. }
353276 | ExprKind :: Use { .. }
277+ | ExprKind :: Borrow { .. }
278+ | ExprKind :: Adt { .. }
354279 | ExprKind :: Loop { .. }
355280 | ExprKind :: LogicalOp { .. }
356281 | ExprKind :: Call { .. }
0 commit comments