@@ -288,6 +288,37 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
288
288
block. unit ( )
289
289
}
290
290
291
+ // Avoid creating a temporary
292
+ ExprKind :: VarRef { .. } |
293
+ ExprKind :: SelfRef |
294
+ ExprKind :: StaticRef { .. } => {
295
+ debug_assert ! ( Category :: of( & expr. kind) == Some ( Category :: Place ) ) ;
296
+
297
+ let place = unpack ! ( block = this. as_place( block, expr) ) ;
298
+ let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
299
+ this. cfg . push_assign ( block, source_info, destination, rvalue) ;
300
+ block. unit ( )
301
+ }
302
+ ExprKind :: Index { .. } |
303
+ ExprKind :: Deref { .. } |
304
+ ExprKind :: Field { .. } => {
305
+ debug_assert ! ( Category :: of( & expr. kind) == Some ( Category :: Place ) ) ;
306
+
307
+ // Create a "fake" temporary variable so that we check that the
308
+ // value is Sized. Usually, this is caught in type checking, but
309
+ // in the case of box expr there is no such check.
310
+ if let Place :: Projection ( ..) = destination {
311
+ this. local_decls . push ( LocalDecl :: new_temp ( expr. ty , expr. span ) ) ;
312
+ }
313
+
314
+ debug_assert ! ( Category :: of( & expr. kind) == Some ( Category :: Place ) ) ;
315
+
316
+ let place = unpack ! ( block = this. as_place( block, expr) ) ;
317
+ let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
318
+ this. cfg . push_assign ( block, source_info, destination, rvalue) ;
319
+ block. unit ( )
320
+ }
321
+
291
322
// these are the cases that are more naturally handled by some other mode
292
323
ExprKind :: Unary { .. } |
293
324
ExprKind :: Binary { .. } |
@@ -300,18 +331,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
300
331
ExprKind :: Unsize { .. } |
301
332
ExprKind :: Repeat { .. } |
302
333
ExprKind :: Borrow { .. } |
303
- ExprKind :: VarRef { .. } |
304
- ExprKind :: SelfRef |
305
- ExprKind :: StaticRef { .. } |
306
334
ExprKind :: Array { .. } |
307
335
ExprKind :: Tuple { .. } |
308
336
ExprKind :: Adt { .. } |
309
337
ExprKind :: Closure { .. } |
310
- ExprKind :: Index { .. } |
311
- ExprKind :: Deref { .. } |
312
338
ExprKind :: Literal { .. } |
313
- ExprKind :: Yield { .. } |
314
- ExprKind :: Field { .. } => {
339
+ ExprKind :: Yield { .. } => {
315
340
debug_assert ! ( match Category :: of( & expr. kind) . unwrap( ) {
316
341
Category :: Rvalue ( RvalueFunc :: Into ) => false ,
317
342
_ => true ,
0 commit comments