@@ -538,12 +538,13 @@ impl BorrowckCtxt {
538538
539539 move_data:: MoveExpr ( expr) => {
540540 let expr_ty = ty:: expr_ty_adjusted ( self . tcx , expr) ;
541+ let suggestion = move_suggestion ( self . tcx , expr_ty,
542+ "moved by default (use `copy` to override)" ) ;
541543 self . tcx . sess . span_note (
542544 expr. span ,
543- fmt ! ( "`%s` moved here because it has type `%s`, \
544- which is moved by default (use `copy` to override)",
545+ fmt ! ( "`%s` moved here because it has type `%s`, which is %s" ,
545546 self . loan_path_to_str( moved_lp) ,
546- expr_ty. user_string( self . tcx) ) ) ;
547+ expr_ty. user_string( self . tcx) , suggestion ) ) ;
547548 }
548549
549550 move_data:: MovePat ( pat) => {
@@ -557,12 +558,28 @@ impl BorrowckCtxt {
557558 }
558559
559560 move_data:: Captured ( expr) => {
561+ let expr_ty = ty:: expr_ty_adjusted ( self . tcx , expr) ;
562+ let suggestion = move_suggestion ( self . tcx , expr_ty,
563+ "moved by default (make a copy and \
564+ capture that instead to override)") ;
560565 self . tcx . sess . span_note (
561566 expr. span ,
562- fmt ! ( "`%s` moved into closure environment here \
563- because its type is moved by default \
564- (make a copy and capture that instead to override)",
565- self . loan_path_to_str( moved_lp) ) ) ;
567+ fmt ! ( "`%s` moved into closure environment here because it \
568+ has type `%s`, which is %s",
569+ self . loan_path_to_str( moved_lp) ,
570+ expr_ty. user_string( self . tcx) , suggestion) ) ;
571+ }
572+ }
573+
574+ fn move_suggestion ( tcx : ty:: ctxt , ty : ty:: t , default_msg : & ' static str )
575+ -> & ' static str {
576+ match ty:: get ( ty) . sty {
577+ ty:: ty_closure( ref cty) if cty. sigil == ast:: BorrowedSigil =>
578+ "a non-copyable stack closure (capture it in a new closure, \
579+ e.g. `|x| f(x)`, to override)",
580+ _ if !ty:: type_is_copyable ( tcx, ty) =>
581+ "non-copyable (perhaps you meant to use clone()?)" ,
582+ _ => default_msg,
566583 }
567584 }
568585 }
0 commit comments