@@ -347,7 +347,20 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
347347 loc
348348 } ;
349349
350+ let is_copy = !self_ty. moves_by_default ( tcx, tcx. param_env ( def_id) , span) ;
351+
350352 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+ }
351364 ty:: TyArray ( ty, len) => {
352365 let mut returns = Vec :: new ( ) ;
353366 for i in 0 ..len {
@@ -402,15 +415,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
402415 block ( & mut blocks, statement, TerminatorKind :: Return ) ;
403416 }
404417 _ => {
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) ;
414419 }
415420 } ;
416421
0 commit comments