@@ -353,17 +353,24 @@ fn trans_trait_callee<'a>(bcx: &'a Block<'a>,
353
353
// converting to an rvalue.
354
354
let self_datum = unpack_datum ! (
355
355
bcx, expr:: trans( bcx, self_expr) ) ;
356
- let self_datum = unpack_datum ! (
357
- bcx, self_datum. to_rvalue_datum( bcx, "trait_callee" ) ) ;
358
356
359
- // Convert to by-ref since `trans_trait_callee_from_llval` wants it
360
- // that way.
361
- let self_datum = unpack_datum ! (
362
- bcx, self_datum. to_ref_datum( bcx) ) ;
357
+ let llval = if ty:: type_needs_drop ( bcx. tcx ( ) , self_datum. ty ) {
358
+ let self_datum = unpack_datum ! (
359
+ bcx, self_datum. to_rvalue_datum( bcx, "trait_callee" ) ) ;
360
+
361
+ // Convert to by-ref since `trans_trait_callee_from_llval` wants it
362
+ // that way.
363
+ let self_datum = unpack_datum ! (
364
+ bcx, self_datum. to_ref_datum( bcx) ) ;
363
365
364
- // Arrange cleanup in case something should go wrong before the
365
- // actual call occurs.
366
- let llval = self_datum. add_clean ( bcx. fcx , arg_cleanup_scope) ;
366
+ // Arrange cleanup in case something should go wrong before the
367
+ // actual call occurs.
368
+ self_datum. add_clean ( bcx. fcx , arg_cleanup_scope)
369
+ } else {
370
+ // We don't have to do anything about cleanups for &Trait and &mut Trait.
371
+ assert ! ( self_datum. kind. is_by_ref( ) ) ;
372
+ self_datum. val
373
+ } ;
367
374
368
375
let callee_ty = node_id_type ( bcx, callee_id) ;
369
376
trans_trait_callee_from_llval ( bcx, callee_ty, n_method, llval)
0 commit comments