@@ -347,7 +347,20 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
347
347
loc
348
348
} ;
349
349
350
+ let is_copy = !self_ty. moves_by_default ( tcx, tcx. param_env ( def_id) , span) ;
351
+
350
352
match self_ty. sty {
353
+ _ if is_copy => {
354
+ // `return *self;`
355
+ let statement = Statement {
356
+ source_info : source_info,
357
+ kind : StatementKind :: Assign (
358
+ Lvalue :: Local ( RETURN_POINTER ) ,
359
+ Rvalue :: Use ( Operand :: Consume ( rcvr) )
360
+ )
361
+ } ;
362
+ block ( & mut blocks, statement, TerminatorKind :: Return ) ;
363
+ }
351
364
ty:: TyArray ( ty, len) => {
352
365
let mut returns = Vec :: new ( ) ;
353
366
for i in 0 ..len {
@@ -402,15 +415,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
402
415
block ( & mut blocks, statement, TerminatorKind :: Return ) ;
403
416
}
404
417
_ => {
405
- // `return *self;`
406
- let statement = Statement {
407
- source_info : source_info,
408
- kind : StatementKind :: Assign (
409
- Lvalue :: Local ( RETURN_POINTER ) ,
410
- Rvalue :: Use ( Operand :: Consume ( rcvr) )
411
- )
412
- } ;
413
- block ( & mut blocks, statement, TerminatorKind :: Return ) ;
418
+ bug ! ( "builtin shim for `{:?}` which is not `Copy` and is not an aggregate" , self_ty) ;
414
419
}
415
420
} ;
416
421
0 commit comments