@@ -538,12 +538,13 @@ impl BorrowckCtxt {
538
538
539
539
move_data:: MoveExpr ( expr) => {
540
540
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)" ) ;
541
543
self . tcx . sess . span_note (
542
544
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" ,
545
546
self . loan_path_to_str( moved_lp) ,
546
- expr_ty. user_string( self . tcx) ) ) ;
547
+ expr_ty. user_string( self . tcx) , suggestion ) ) ;
547
548
}
548
549
549
550
move_data:: MovePat ( pat) => {
@@ -557,12 +558,28 @@ impl BorrowckCtxt {
557
558
}
558
559
559
560
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)") ;
560
565
self . tcx . sess . span_note (
561
566
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,
566
583
}
567
584
}
568
585
}
0 commit comments