@@ -288,6 +288,37 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
288288 block. unit ( )
289289 }
290290
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+
291322 // these are the cases that are more naturally handled by some other mode
292323 ExprKind :: Unary { .. } |
293324 ExprKind :: Binary { .. } |
@@ -300,18 +331,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
300331 ExprKind :: Unsize { .. } |
301332 ExprKind :: Repeat { .. } |
302333 ExprKind :: Borrow { .. } |
303- ExprKind :: VarRef { .. } |
304- ExprKind :: SelfRef |
305- ExprKind :: StaticRef { .. } |
306334 ExprKind :: Array { .. } |
307335 ExprKind :: Tuple { .. } |
308336 ExprKind :: Adt { .. } |
309337 ExprKind :: Closure { .. } |
310- ExprKind :: Index { .. } |
311- ExprKind :: Deref { .. } |
312338 ExprKind :: Literal { .. } |
313- ExprKind :: Yield { .. } |
314- ExprKind :: Field { .. } => {
339+ ExprKind :: Yield { .. } => {
315340 debug_assert ! ( match Category :: of( & expr. kind) . unwrap( ) {
316341 Category :: Rvalue ( RvalueFunc :: Into ) => false ,
317342 _ => true ,
0 commit comments